forked from gwik/ffmpeg-rb
/
test_ffmpeg_frame.rb
256 lines (212 loc) · 10.8 KB
/
test_ffmpeg_frame.rb
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
require 'ffmpeg/test_case'
class TestFFMPEGFrame < FFMPEG::TestCase
def setup
super
@frame = FFMPEG::Frame.new 40, 30, FFMPEG::PixelFormat::YUV420P
@frame.defaults
@data_size = @frame.data_size
end
def test_class_from
format_context = FFMPEG::FormatContext.new @thumbs_up
codec_context = format_context.video_stream.codec_context
frame = FFMPEG::Frame.from codec_context
assert_equal 176, frame.width
assert_equal 144, frame.height
assert_equal FFMPEG::PixelFormat::YUV420P, frame.pixel_format
end
def test_clear
@frame.fill
@frame.data = ["\x55" * @data_size, nil, nil, nil]
@frame.clear
assert_equal "\0" * @data_size, @frame.data[0]
end
def test_data
@frame.fill
data = @frame.data
assert_equal 4, data.length
assert_equal @data_size, data[0].length
refute_nil data[1]
refute_nil data[2]
assert_equal nil, data[3]
data[0].replace "\xff"
refute_equal "\xff", @frame.data[0]
end
def test_data_equals
@frame.fill
@frame.data = ["\x55" * @data_size, nil, nil, nil]
assert_equal "\x55" * @data_size, @frame.data[0]
end
def test_data_equals2
@frame.fill
data = util_fill_frame @frame
@frame.data = data
data = @frame.data
expected = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
"\x20\x21\x22\x23\x24\x25\x26\x27\x01\x02\x03\x04\x05\x06\x07\x08",
"\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18",
"\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28",
"\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11",
"\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21",
"\x22\x23\x24\x25\x26\x27\x28\x29\x03\x04\x05\x06\x07\x08\x09\x0a",
"\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a",
"\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a",
"\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13",
"\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23",
"\x24\x25\x26\x27\x28\x29\x2a\x2b\x05\x06\x07\x08\x09\x0a\x0b\x0c",
"\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c",
"\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c",
"\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15",
"\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25",
"\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x07\x08\x09\x0a\x0b\x0c\x0d\x0e",
"\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e",
"\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e",
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17",
"\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27",
"\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10",
"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
"\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30",
"\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
"\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29",
"\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x0b\x0c\x0d\x0e\x0f\x10\x11\x12",
"\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22",
"\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32",
"\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b",
"\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b",
"\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x0d\x0e\x0f\x10\x11\x12\x13\x14",
"\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24",
"\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34",
"\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
"\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d",
"\x2e\x2f\x30\x31\x32\x33\x34\x35\x0f\x10\x11\x12\x13\x14\x15\x16",
"\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26",
"\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36",
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
"\x30\x31\x32\x33\x34\x35\x36\x37\x11\x12\x13\x14\x15\x16\x17\x18",
"\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28",
"\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38",
"\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21",
"\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31",
"\x32\x33\x34\x35\x36\x37\x38\x39\x13\x14\x15\x16\x17\x18\x19\x1a",
"\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a",
"\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a",
"\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23",
"\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33",
"\x34\x35\x36\x37\x38\x39\x3a\x3b\x15\x16\x17\x18\x19\x1a\x1b\x1c",
"\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c",
"\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c",
"\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25",
"\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35",
"\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x17\x18\x19\x1a\x1b\x1c\x1d\x1e",
"\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e",
"\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e",
"\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27",
"\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37",
"\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
"\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30",
"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40",
"\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29",
"\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39",
"\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x1b\x1c\x1d\x1e\x1f\x20\x21\x22",
"\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32",
"\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42",
"\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b",
"\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b",
"\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x1d\x1e\x1f\x20\x21\x22\x23\x24",
"\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34",
"\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44",
"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
"\x80\x80\x80\x80\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81",
"\x81\x81\x81\x81\x81\x81\x81\x81\x82\x82\x82\x82\x82\x82\x82\x82",
"\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x82\x83\x83\x83\x83",
"\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83\x83",
"\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84\x84",
"\x84\x84\x84\x84\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85\x85",
"\x85\x85\x85\x85\x85\x85\x85\x85\x86\x86\x86\x86\x86\x86\x86\x86",
"\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x86\x87\x87\x87\x87",
"\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87\x87",
"\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88\x88",
"\x88\x88\x88\x88\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89\x89",
"\x89\x89\x89\x89\x89\x89\x89\x89\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a",
"\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8a\x8b\x8b\x8b\x8b",
"\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b\x8b",
"\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c\x8c",
"\x8c\x8c\x8c\x8c\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d",
"\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e",
"\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x8e\x40\x41\x42\x43",
"\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
"\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
"\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
"\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
"\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
"\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
"\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
"\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
"\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
"\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
"\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47",
"\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x40\x41\x42\x43",
"\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
"\x50\x51\x52\x53\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b",
"\x4c\x4d\x4e\x4f\x50\x51\x52\x53",
].join ''
# for rebuilding above if it's wrong
#data = data.first
#until data.empty? do
# bytes = data.slice! 0, 16
# p bytes.unpack('C*').map { |byte|
# "x#{"%02x" % byte}"
# }.join('')
#end
#flunk
assert_equal expected, data[0]
end
def test_data_size
assert_equal 1800, @data_size
end
def test_defaults
@frame.defaults
# this test sucks, the underlying C call does these things now
assert_equal FFMPEG::NOPTS_VALUE, @frame.pts
assert_equal true, @frame.key_frame
end
def test_fill
assert_equal [nil, nil, nil, nil], @frame.data
@frame.fill
data = @frame.data
assert_equal @data_size, data.first.length
end
def test_key_frame
assert_equal true, @frame.key_frame
end
def test_key_frame_eh
assert @frame.key_frame?
end
def test_linesize
@frame.fill
assert_equal [40, 20, 20, 0], @frame.linesize
end
def test_picture_type
@frame.picture_type = FFMPEG::PixelFormat::RGBA
assert_equal FFMPEG::PixelFormat::RGBA, @frame.picture_type
end
def test_pts
@frame.pts = 2
assert_equal 2, @frame.pts
end
def test_quality
@frame.quality = 2
assert_equal 2, @frame.quality
end
def test_type
assert_equal nil, @frame.type
@frame.picture_type = FFMPEG::Frame::I_TYPE
assert_equal :I_TYPE, @frame.type
end
end