-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg_encode.h
66 lines (50 loc) · 1.11 KB
/
ffmpeg_encode.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdint.h>
#include <libavutil\pixfmt.h>
// presets:
//
// ultrafast
// superfast
// veryfast
// faster
// fast
// medium – default preset
// slow
// slower
// veryslow
class FfmpegEncoder
{
public:
struct Params
{
uint32_t width;
uint32_t height;
double fps;
uint32_t bitrate;
const char *preset;
uint32_t crf; //0–51
enum AVPixelFormat src_format;
enum AVPixelFormat dst_format;
};
FfmpegEncoder() = default;
FfmpegEncoder(const char *filename, const Params ¶ms);
~FfmpegEncoder();
bool Open(const char *filename, const Params ¶ms);
void Close();
bool Write(const unsigned char *data);
bool IsOpen() const;
private:
bool FlushPackets();
private:
bool mIsOpen = false;
struct Context
{
struct AVFormatContext *format_context = nullptr;
struct AVStream *stream = nullptr;
struct AVCodecContext *codec_context = nullptr;
struct AVFrame *frame = nullptr;
struct SwsContext *sws_context = nullptr;
struct AVCodec *codec = nullptr;
uint32_t frame_index = 0;
};
Context mContext = {};
};