forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

ffmpeg_parity.rs458 lines, 8.0 KiBHistoryRawDownload
1//! Byte-exact parity with ffmpeg's MPEG-4 Part 2 / H.263 decoder on streams ffmpeg encodes at test
2//! time (`ffmpeg -c:v mpeg4`, `libxvid`, `h263`). Skipped without ffmpeg unless `EC_REQUIRE_FIXTURES`
3//! is set; the libxvid cases (GMC, N-VOPs, XviD IDCT) also skip when the encoder is not built in.
4
5mod common;
6
7use common::*;
8
9macro_rules! parity {
10 ($name:ident, $size:expr, $frames:expr, [$($arg:expr),* $(,)?]) => {
11 #[test]
12 fn $name() {
13 if !gate() {
14 return;
15 }
16 let n = parity_es(stringify!($name), $size, $frames, &[$($arg),*], "m4v").unwrap();
17 assert!(n >= $frames - 2, "decoded only {n} of {} pictures", $frames);
18 }
19 };
20}
21
22// Simple profile: I/P, H.263 quantisation.
23parity!(
24 simple_q2,
25 "176x144",
26 30,
27 ["-c:v", "mpeg4", "-qscale:v", "2", "-g", "12"]
28);
29parity!(
30 simple_q8,
31 "176x144",
32 30,
33 ["-c:v", "mpeg4", "-qscale:v", "8", "-g", "30"]
34);
35parity!(
36 simple_q31,
37 "176x144",
38 30,
39 ["-c:v", "mpeg4", "-qscale:v", "31", "-g", "30"]
40);
41parity!(
42 mv4,
43 "176x144",
44 30,
45 ["-c:v", "mpeg4", "-qscale:v", "4", "-flags", "+mv4"]
46);
47parity!(
48 aic,
49 "176x144",
50 30,
51 ["-c:v", "mpeg4", "-qscale:v", "4", "-flags", "+aic"]
52);
53parity!(
54 cbr_cif,
55 "352x288",
56 60,
57 ["-c:v", "mpeg4", "-b:v", "300k", "-g", "50"]
58);
59// Advanced Simple profile tools.
60parity!(
61 bframes,
62 "176x144",
63 30,
64 ["-c:v", "mpeg4", "-qscale:v", "4", "-bf", "2", "-g", "12"]
65);
66parity!(
67 bframes_1,
68 "176x144",
69 30,
70 ["-c:v", "mpeg4", "-qscale:v", "4", "-bf", "1"]
71);
72parity!(
73 qpel,
74 "176x144",
75 30,
76 ["-c:v", "mpeg4", "-qscale:v", "4", "-flags", "+qpel"]
77);
78parity!(
79 qpel_bf_mv4,
80 "176x144",
81 30,
82 [
83 "-c:v",
84 "mpeg4",
85 "-qscale:v",
86 "4",
87 "-bf",
88 "2",
89 "-flags",
90 "+qpel+mv4"
91 ]
92);
93parity!(
94 interlaced_dct,
95 "176x144",
96 30,
97 ["-c:v", "mpeg4", "-qscale:v", "4", "-flags", "+ildct"]
98);
99parity!(
100 interlaced_me_bf,
101 "176x144",
102 30,
103 [
104 "-c:v",
105 "mpeg4",
106 "-qscale:v",
107 "4",
108 "-bf",
109 "2",
110 "-flags",
111 "+ildct+ilme"
112 ]
113);
114parity!(
115 interlaced_direct_q31,
116 "176x144",
117 30,
118 [
119 "-c:v",
120 "mpeg4",
121 "-qscale:v",
122 "31",
123 "-bf",
124 "2",
125 "-flags",
126 "+ildct+ilme"
127 ]
128);
129parity!(
130 interlaced_everything,
131 "176x144",
132 30,
133 [
134 "-c:v",
135 "mpeg4",
136 "-qscale:v",
137 "3",
138 "-bf",
139 "2",
140 "-flags",
141 "+ildct+ilme+qpel+mv4"
142 ]
143);
144parity!(
145 mpeg_quant,
146 "176x144",
147 30,
148 [
149 "-c:v",
150 "mpeg4",
151 "-qscale:v",
152 "4",
153 "-bf",
154 "2",
155 "-mpeg_quant",
156 "1"
157 ]
158);
159parity!(
160 mpeg_quant_q31_qpel,
161 "176x144",
162 30,
163 [
164 "-c:v",
165 "mpeg4",
166 "-qscale:v",
167 "31",
168 "-mpeg_quant",
169 "1",
170 "-flags",
171 "+qpel"
172 ]
173);
174parity!(
175 resync_packets,
176 "176x144",
177 30,
178 ["-c:v", "mpeg4", "-qscale:v", "4", "-bf", "2", "-ps", "400"]
179);
180parity!(
181 resync_small_packets,
182 "352x288",
183 20,
184 [
185 "-c:v",
186 "mpeg4",
187 "-qscale:v",
188 "6",
189 "-ps",
190 "100",
191 "-flags",
192 "+mv4"
193 ]
194);
195parity!(
196 all_tools,
197 "176x144",
198 30,
199 [
200 "-c:v",
201 "mpeg4",
202 "-qscale:v",
203 "5",
204 "-bf",
205 "2",
206 "-flags",
207 "+ildct+ilme+qpel+mv4+aic",
208 "-mpeg_quant",
209 "1",
210 "-ps",
211 "300"
212 ]
213);
214// Field-MV B-frames across video-packet boundaries: ffmpeg clears only last_mv[dir][0] at a resync.
215parity!(
216 interlaced_resync_bf,
217 "176x144",
218 30,
219 [
220 "-c:v",
221 "mpeg4",
222 "-qscale:v",
223 "5",
224 "-bf",
225 "2",
226 "-flags",
227 "+ildct+ilme+qpel+mv4",
228 "-ps",
229 "100"
230 ]
231);
232parity!(
233 interlaced_resync_bf_tiny_packets,
234 "352x288",
235 16,
236 [
237 "-c:v",
238 "mpeg4",
239 "-qscale:v",
240 "4",
241 "-bf",
242 "2",
243 "-flags",
244 "+ildct+ilme",
245 "-ps",
246 "60"
247 ]
248);
249// Picture sizes that are not a macroblock multiple (cropped output).
250parity!(
251 odd_size,
252 "170x130",
253 20,
254 [
255 "-c:v",
256 "mpeg4",
257 "-qscale:v",
258 "4",
259 "-bf",
260 "2",
261 "-flags",
262 "+qpel+mv4"
263 ]
264);
265parity!(
266 tiny,
267 "32x32",
268 20,
269 [
270 "-c:v",
271 "mpeg4",
272 "-qscale:v",
273 "4",
274 "-bf",
275 "2",
276 "-flags",
277 "+qpel+mv4"
278 ]
279);
280parity!(
281 wide,
282 "640x64",
283 12,
284 [
285 "-c:v",
286 "mpeg4",
287 "-qscale:v",
288 "4",
289 "-bf",
290 "2",
291 "-flags",
292 "+qpel+mv4+ildct+ilme"
293 ]
294);
295
296#[test]
297fn hd_720p_with_everything() {
298 if !gate() {
299 return;
300 }
301 let n = parity_es(
302 "hd720",
303 "1280x720",
304 8,
305 &[
306 "-c:v",
307 "mpeg4",
308 "-qscale:v",
309 "4",
310 "-bf",
311 "2",
312 "-flags",
313 "+qpel+mv4+ildct+ilme",
314 ],
315 "m4v",
316 )
317 .unwrap();
318 assert!(n >= 6);
319}
320
321// H.263 baseline (short video header).
322#[test]
323fn h263_formats() {
324 if !gate() {
325 return;
326 }
327 for (size, q, gop) in [
328 ("128x96", "4", "8"),
329 ("176x144", "4", "10"),
330 ("352x288", "4", "10"),
331 ("352x288", "12", "30"),
332 ("704x576", "6", "6"),
333 ] {
334 let tag = format!("h263_{size}_{q}");
335 let n = parity_es(
336 &tag,
337 size,
338 20,
339 &["-c:v", "h263", "-qscale:v", q, "-g", gop],
340 "h263",
341 )
342 .unwrap_or_else(|e| panic!("{tag}: {e}"));
343 assert_eq!(n, 20, "{tag}");
344 }
345}
346
347#[test]
348fn h263_with_gob_headers() {
349 if !gate() {
350 return;
351 }
352 // `-ps` makes ffmpeg's H.263 encoder start a GOB (with its header) every n macroblocks.
353 let n = parity_es(
354 "h263_gob",
355 "352x288",
356 20,
357 &["-c:v", "h263", "-qscale:v", "6", "-ps", "300"],
358 "h263",
359 )
360 .unwrap();
361 assert_eq!(n, 20);
362}
363
364// libxvid: GMC with warp points, N-VOPs, the XviD IDCT and XviD's qpel/bframe habits.
365fn libxvid(tag: &str, size: &str, frames: u32, extra: &[&str]) {
366 if !gate() {
367 return;
368 }
369 if !have_encoder("libxvid") {
370 eprintln!("skipped {tag}: ffmpeg has no libxvid encoder");
371 return;
372 }
373 let mut enc = vec!["-c:v", "libxvid"];
374 enc.extend_from_slice(extra);
375 let n = parity_es(tag, size, frames, &enc, "m4v").unwrap_or_else(|e| panic!("{tag}: {e}"));
376 assert!(n >= frames as usize - 3);
377}
378
379#[test]
380fn xvid_gmc() {
381 libxvid(
382 "xvid_gmc",
383 "176x144",
384 30,
385 &["-qscale:v", "4", "-bf", "2", "-gmc", "1", "-g", "12"],
386 );
387}
388
389#[test]
390fn xvid_gmc_qpel_mv4() {
391 libxvid(
392 "xvid_gmc_qpel",
393 "352x288",
394 40,
395 &[
396 "-qscale:v",
397 "4",
398 "-bf",
399 "2",
400 "-gmc",
401 "1",
402 "-flags",
403 "+qpel+mv4",
404 "-g",
405 "12",
406 ],
407 );
408}
409
410#[test]
411fn xvid_gmc_no_bframes_mpeg_quant() {
412 libxvid(
413 "xvid_gmc_mq",
414 "320x240",
415 40,
416 &[
417 "-qscale:v",
418 "3",
419 "-bf",
420 "0",
421 "-gmc",
422 "1",
423 "-flags",
424 "+qpel",
425 "-mpeg_quant",
426 "1",
427 ],
428 );
429}
430
431#[test]
432fn xvid_interlaced() {
433 libxvid(
434 "xvid_ilace",
435 "176x144",
436 30,
437 &["-qscale:v", "4", "-bf", "2", "-flags", "+ildct+ilme"],
438 );
439}
440
441#[test]
442fn xvid_mpeg_quant_qpel() {
443 libxvid(
444 "xvid_mq",
445 "176x144",
446 30,
447 &[
448 "-qscale:v",
449 "4",
450 "-bf",
451 "2",
452 "-flags",
453 "+qpel",
454 "-mpeg_quant",
455 "1",
456 ],
457 );
458}