61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
#ifndef FFMPEGENCODER_H
|
|
#define FFMPEGENCODER_H
|
|
|
|
extern "C" {
|
|
#include <libavformat/avformat.h>
|
|
#include <libswscale/swscale.h>
|
|
#include <libswresample/swresample.h>
|
|
}
|
|
|
|
#include "codec/encoder.h"
|
|
|
|
class FFmpegEncoder : public Encoder
|
|
{
|
|
public:
|
|
FFmpegEncoder(const EncodingParams ¶ms);
|
|
|
|
virtual bool Open() override;
|
|
virtual void Write(FramePtr frame) override;
|
|
virtual void Close() override;
|
|
|
|
private:
|
|
/**
|
|
* @brief Handle an error
|
|
*
|
|
* Immediately closes the Decoder (freeing memory resources) and sends the string provided to the warning stream.
|
|
* As this function closes the Decoder, no further Decoder functions should be performed after this is called
|
|
* (unless the Decoder is opened again first).
|
|
*/
|
|
void Error(const QString& s);
|
|
|
|
/**
|
|
* @brief Handle an FFmpeg error code
|
|
*
|
|
* Uses the FFmpeg API to retrieve a descriptive string for this error code and sends it to Error(). As such, this
|
|
* function also automatically closes the Decoder.
|
|
*
|
|
* @param error_code
|
|
*/
|
|
void FFmpegError(int error_code);
|
|
|
|
bool InitializeStream(enum AVMediaType type, AVStream** stream, AVCodecContext** codec_ctx, const QString& codec);
|
|
bool InitializeCodecContext(AVStream** stream, AVCodecContext** codec_ctx, AVCodec* codec);
|
|
bool SetupCodecContext(AVStream *stream, AVCodecContext *codec_ctx, AVCodec *codec);
|
|
|
|
void FlushEncoders();
|
|
|
|
AVFormatContext* fmt_ctx_;
|
|
|
|
AVStream* video_stream_;
|
|
AVCodecContext* video_codec_ctx_;
|
|
SwsContext* video_scale_ctx_;
|
|
olive::PixelFormat video_conversion_fmt_;
|
|
|
|
AVStream* audio_stream_;
|
|
AVCodecContext* audio_codec_ctx_;
|
|
SwrContext* audio_resample_ctx_;
|
|
|
|
};
|
|
|
|
#endif // FFMPEGENCODER_H
|