FFRecoder.h1 1.03 KB
#pragma once
#include <memory>

class AVFrame;
class AVStream;
class AVCodecContext;
class AVFormatContext;
struct AVRational;
struct SwsContext;
struct AVPacket;

class FFRecoder
{
public:
	FFRecoder();
	virtual ~FFRecoder();

	bool init(int w, int h, AVRational time_base, AVCodecContext* avctx, const char* outfile_name);
	void uninit();
	bool write_image(const uint8_t* bgr);
	bool write_yuv(const uint8_t* yuv_data);
	bool write_frame(AVFrame* frame);
	bool flush();

	// AVPacket 方式
	bool init(AVRational time_base, AVCodecContext* avctx, const char* outfile_name);
	bool write_pkt(AVPacket *pkt);

private:
	bool bgr_to_yuv420p(const uint8_t* const buf_bgr, uint8_t* const buf_420p);
	void update_pts(AVPacket* pkt);

private:
	int width_;
	int height_;
	int y_size_;
	int uv_size_;
	int pts_;
	AVCodecContext* codec_ctx_;
	AVFormatContext* fmt_ctx_;
	AVStream* out_stream_;
	AVFrame* yuv_frame_;

	SwsContext * img_convert_ctx;
	//AVFrame* pFrameOut;
	uint8_t * out_buffer;

	bool bFirstFrame;
	int64_t last_src_pts;
	int64_t last_pts;
};