forked from CedricGuillemet/Imogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpegCodec.h
145 lines (120 loc) · 3.26 KB
/
ffmpegCodec.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include "ffmpegInclude.h"
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <cstring>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <string>
namespace FFMPEGCodec
{
void RegisterAll();
using namespace std;
class Decoder
{
public:
Decoder() { Init(); }
virtual ~Decoder()
{
Close();
}
bool Open(const std::string &name);
bool Close(void);
int CurrentSubimage(void) const {
return m_subimage;
}
bool SeekSubimage(int subimage, int miplevel);
void *GetRGBData();
void ReadFrame(int pos);
bool Seek(int pos);
double Fps() const;
int64_t TimeStamp(int pos) const;
size_t mWidth, mHeight;
size_t mFrameCount;
const std::string GetFilename() const { return m_filename; }
private:
std::string m_filename;
int m_subimage;
int64_t m_nsubimages;
AVFormatContext * m_format_context;
AVCodecContext * m_codec_context;
AVCodec *m_codec;
AVFrame *m_frame;
AVFrame *m_rgb_frame;
size_t m_stride;
AVPixelFormat m_dst_pix_format;
SwsContext *m_sws_rgb_context;
AVRational m_frame_rate;
std::vector<uint8_t> m_rgb_buffer;
std::vector<int> m_video_indexes;
int m_video_stream;
int64_t m_frames;
int m_last_search_pos;
int m_last_decoded_pos;
bool m_offset_time;
bool m_codec_cap_delay;
bool m_read_frame;
int64_t m_start_time;
// init to initialize state
void Init(void) {
m_filename.clear();
m_format_context = 0;
m_codec_context = 0;
m_codec = 0;
m_frame = 0;
m_rgb_frame = 0;
m_sws_rgb_context = 0;
m_stride = 0;
m_rgb_buffer.clear();
m_video_indexes.clear();
m_video_stream = -1;
m_frames = 0;
m_last_search_pos = 0;
m_last_decoded_pos = 0;
m_offset_time = true;
m_read_frame = false;
m_codec_cap_delay = false;
m_subimage = 0;
m_start_time = 0;
mFrameCount = 0;
mWidth = 0;
mHeight = 0;
}
};
class Encoder {
public:
Encoder() {
oformat = NULL;
ofctx = NULL;
videoStream = NULL;
videoFrame = NULL;
swsCtx = NULL;
frameCounter = 0;
}
~Encoder() {
Free();
}
void Init(const std::string& filename, int width, int height, int fpsrate, int bitrate);
void AddFrame(uint8_t *data, int width, int height);
void Finish();
private:
std::string mFilename;
AVOutputFormat *oformat;
AVFormatContext *ofctx;
AVStream *videoStream;
AVFrame *videoFrame;
AVCodec *codec;
AVCodecContext *cctx;
SwsContext *swsCtx;
int frameCounter;
int fps;
void Free();
void Remux();
};
extern int(*Log)(const char *szFormat, ...);
}