forked from ammen99/wf-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame-writer.hpp
50 lines (40 loc) · 1020 Bytes
/
frame-writer.hpp
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
// Adapted from https://stackoverflow.com/questions/34511312/how-to-encode-a-video-from-several-images-generated-in-a-c-program-without-wri
// (Later) adapted from https://github.com/apc-llc/moviemaker-cpp
#ifndef FRAME_WRITER
#define FRAME_WRITER
#include <stdint.h>
#include <string>
#include <vector>
#include <map>
extern "C"
{
#include <x264.h>
#include <libswscale/swscale.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libavutil/opt.h>
}
enum InputFormat
{
INPUT_FORMAT_BGR0,
INPUT_FORMAT_RGB0
};
class FrameWriter
{
const unsigned int width, height;
SwsContext* swsCtx;
AVOutputFormat* fmt;
AVStream* stream;
AVFormatContext* fc;
AVCodecContext* c;
AVPacket pkt;
AVFrame *yuvpic;
void finish_frame();
public :
FrameWriter(const std::string& filename,
int width, int height, InputFormat format);
void add_frame(const uint8_t* pixels, int msec, bool y_invert);
~FrameWriter();
};
#endif // FRAME_WRITER