-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngineVideoManager.h
82 lines (68 loc) · 2.03 KB
/
EngineVideoManager.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "WickedEngine.h"
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/opt.h>
}
class EngineVideoManager
{
public:
EngineVideoManager();
~EngineVideoManager();
static EngineVideoManager* getInstance()
{
if (instance == nullptr)
{
instance = new EngineVideoManager();
}
return instance;
}
static void removeInstance()
{
if (instance != 0)
{
delete instance;
instance = nullptr;
}
}
void startCaptureVideo(int width = 1920,int height = 1080);
void addCaptureVideoFrame(wi::graphics::Texture& newFrame);
void stopCaptureVideo(std::string fileName);
bool isVideoInComputation();
XMINT2 getVideoSize();
private:
static EngineVideoManager* instance;
const int FRAMERATE = 25;
const AVPixelFormat FORMAT_PIXEL = AV_PIX_FMT_RGBA;
bool isComputingVideo = false;
int videoWidth = 1920;
int videoHeight = 1080;
int initializeCodec(std::string fileName);
void addStream();
void closeStream();
void openVideo();
void allocatePicture();
int writeFrame();
int encodeFrame(AVFrame* frame);
void closeEncodeContext(AVFormatContext* ifmt_ctx, AVFormatContext* ofmt_ctx);
void encodeAndWriteVideo(wi::graphics::Texture& newFrame);
void reEncodeToMp4(std::string h264File, std::string fileName);
struct OutputStream
{
AVStream* stream = nullptr;
AVCodecContext* codecContext = nullptr;
int64_t nextPoint;
AVFrame* frame = nullptr;
struct SwsContext* swsContext = nullptr;
};
AVFormatContext* formatContext = nullptr;
AVOutputFormat* outputFormat = nullptr;
AVCodec* videoCodec = nullptr;
AVDictionary* videoDictionary = nullptr;
SwsContext* swsContext = nullptr;
AVPacket packet;
OutputStream streamOut;
};