-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoProcessTest.cpp
83 lines (60 loc) · 1.9 KB
/
VideoProcessTest.cpp
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
//~ #include "stdafx.h"
#include "VideoProcess.h"
#include "DebugPrinter.hpp"
using namespace VideoProcess;
static void saveFrame(AVFrame *frame, int width, int height, int it);
static AVFrame * get_next_frame(void *opaque);
//~ #define TESTVIDEO "bluescreen.avi"
std::string TESTVIDEO = "bluescreen.avi";
int main(int argc, char* argv[])
{
Decoder decoder = Decoder(TESTVIDEO);
int width = decoder.getWidth();
int height = decoder.getHeight();
PixelFormat pix_fmt = decoder.getPixelFormat();
AVRational time_base = decoder.getTimeBase();
AVRational aspect_ratio = decoder.getAspectRatio();
dout_HERE;
Filter filter = Filter("yadif=1:-1", width, height, pix_fmt,
time_base, aspect_ratio, &get_next_frame, &decoder);
dout_HERE;
Scaler scaler = Scaler(width, height, pix_fmt, width, height, PIX_FMT_RGB24);
//Encoder encoder = Encoder("out.avi", width, height, time_base);
for (int it = 0; it < 5; it++)
{
AVFrame *read_frame = filter.getNextFilteredFrame();
if (read_frame == NULL)
break;
AVFrame *rgb_frame = scaler.scaleFrame(read_frame, 0, height);
saveFrame(rgb_frame, width, height, it);
/* Encoder test
AVFrame *read_frame = decoder.getNextFrame();
if (read_frame == NULL)
break;
encoder.appendFrame(read_frame);
*/
}
return 0;
}
void saveFrame(AVFrame *frame, int width, int height, int it)
{
FILE *file;
char filename[32];
int y;
// Open file
sprintf(filename, "frame%d.ppm", it);
file=fopen(filename, "wb");
if(file==NULL)
return;
// Write header
fprintf(file, "P6\n%d %d\n255\n", width, height);
// Write pixel data
for(y=0; y<height; y++)
fwrite(frame->data[0]+y * frame->linesize[0], 1, width*3, file);
// Close file
fclose(file);
}
AVFrame * get_next_frame(void *opaque)
{
return ((Decoder *)opaque)->getNextFrame();
}