-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathGeneratedVideoSource.cpp
More file actions
114 lines (105 loc) · 2 KB
/
Copy pathGeneratedVideoSource.cpp
File metadata and controls
114 lines (105 loc) · 2 KB
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
#include "GeneratedVideoSource.h"
GeneratedVideoSource::GeneratedVideoSource(int width, int height, FrameSink* frameSink)
{
// generate a raw video source that will convert the raw format to any other format and pass it on to the encoder
// or any other sink (might be a filter as well).
output = new RawVideoDataSource(width, height, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA, 30, frameSink);
}
GeneratedVideoSource::~GeneratedVideoSource()
{
delete output;
delete rgb;
}
uint8_t* generate_rgb(int width, int height, int pts, uint8_t *rgb);
void GeneratedVideoSource::PreparePipeline()
{
while (!output->IsPrimed() && !IsDone())
{
Step();
}
}
void GeneratedVideoSource::Step()
{
rgb = generate_rgb(output->GetWidth(), output->GetHeight(), frameNumber, rgb);
output->WriteFrame(rgb, 4 * output->GetWidth());
++frameNumber;
if (IsDone())
{
output->Close();
}
}
bool GeneratedVideoSource::IsDone()
{
return frameNumber >= 100;
}
uint8_t* generate_rgb(int width, int height, int pts, uint8_t *rgb)
{
int x, y, cur;
rgb = (uint8_t*)realloc(rgb, 4 * sizeof(uint8_t) * height * width);
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
cur = 4 * (y * width + x);
rgb[cur + 0] = 0;
rgb[cur + 1] = 0;
rgb[cur + 2] = 0;
rgb[cur + 3] = (pts % 25) * (255 / 25);
if ((pts / 25) % 2 == 0)
{
if (y < height / 2)
{
if (x < width / 2)
{
/* Black. */
}
else
{
rgb[cur + 0] = 255;
}
}
else
{
if (x < width / 2)
{
rgb[cur + 1] = 255;
}
else
{
rgb[cur + 2] = 255;
}
}
}
else
{
if (y < height / 2)
{
rgb[cur + 0] = 255;
if (x < width / 2)
{
rgb[cur + 1] = 255;
}
else
{
rgb[cur + 2] = 255;
}
}
else
{
if (x < width / 2)
{
rgb[cur + 1] = 255;
rgb[cur + 2] = 255;
}
else
{
rgb[cur + 0] = 255;
rgb[cur + 1] = 255;
rgb[cur + 2] = 255;
}
}
}
}
}
return rgb;
}