FFRecoder.h
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <memory>
#include "depend_headers.h"
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(AVStream* stream, AVCodecContext* avctx, const char* outfile_name);
bool write_pkt(AVPacket *pkt);
bool flush_pkt();
void release();
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;
int64_t first_pts;
int64_t first_dts;
int64_t frame_index{0};
AVStream* m_inStream;
};