forge
Explore
Log in

Don't you dare go Hollow

Fixture M6: mpeg2/mpeg4/prores/dnxhd/dv/mjpeg tests use ec_testkit ffmpeg and ffprobe, skip-if-missing gates removed so missing ffmpeg or encoder fails

Browse files at this commit

0110b0edd9a6794d5f334445f64cccb517d083afAhmet Kaan GümüşParent: 155ce74
Cargo.lockmodified+6 -0
@@ -431,6 +431,7 @@ dependencies = [
431431 "ec-matroska",
432432 "ec-mp4",
433433 "ec-riff",
434+ "ec-testkit",
434435 ]
435436
436437 [[package]]
@@ -455,6 +456,7 @@ dependencies = [
455456 "ec-core",
456457 "ec-mp4",
457458 "ec-riff",
459+ "ec-testkit",
458460 ]
459461
460462 [[package]]
@@ -573,6 +575,7 @@ dependencies = [
573575 "ec-image",
574576 "ec-matroska",
575577 "ec-mp4",
578+ "ec-testkit",
576579 ]
577580
578581 [[package]]
@@ -596,6 +599,7 @@ name = "ec-mpeg2"
596599 version = "0.1.0"
597600 dependencies = [
598601 "ec-core",
602+ "ec-testkit",
599603 ]
600604
601605 [[package]]
@@ -606,6 +610,7 @@ dependencies = [
606610 "ec-matroska",
607611 "ec-mp4",
608612 "ec-riff",
613+ "ec-testkit",
609614 ]
610615
611616 [[package]]
@@ -684,6 +689,7 @@ dependencies = [
684689 "bytemuck",
685690 "ec-core",
686691 "ec-mp4",
692+ "ec-testkit",
687693 "wide",
688694 ]
689695
crates/ec-dnxhd/Cargo.tomlmodified+1 -0
@@ -10,6 +10,7 @@ authors.workspace = true
1010 ec-core = { workspace = true }
1111
1212 [dev-dependencies]
13+ec-testkit.workspace = true
1314 ec-mp4 = { workspace = true }
1415 ec-matroska = { workspace = true }
1516 ec-riff = { workspace = true }
crates/ec-dnxhd/tests/common/mod.rsmodified+1 -24
@@ -2,33 +2,10 @@
22 #![allow(dead_code)]
33
44 use std::path::{Path, PathBuf};
5-use std::process::Command;
65
76 use ec_core::Demuxer;
87 use ec_core::frame::VideoFrame;
98
10-pub fn require() -> bool {
11- std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
12-}
13-
14-pub fn have_ffmpeg() -> bool {
15- Command::new("ffmpeg")
16- .arg("-version")
17- .output()
18- .map(|o| o.status.success())
19- .unwrap_or(false)
20-}
21-
22-/// True when the test may run; panics instead of skipping when fixtures are required.
23-pub fn can_run() -> bool {
24- if have_ffmpeg() {
25- return true;
26- }
27- assert!(!require(), "ffmpeg is required (EC_REQUIRE_FIXTURES set)");
28- eprintln!("skipping: no ffmpeg");
29- false
30-}
31-
329 pub fn scratch(tag: &str) -> PathBuf {
3310 let base = std::env::var_os("TMPDIR")
3411 .map(PathBuf::from)
@@ -39,7 +16,7 @@ pub fn scratch(tag: &str) -> PathBuf {
3916 }
4017
4118 pub fn ffmpeg(args: &[&str]) -> bool {
42- let out = Command::new("ffmpeg")
19+ let out = ec_testkit::ffmpeg()
4320 .args(["-v", "error", "-y", "-nostdin"])
4421 .args(args)
4522 .output();
crates/ec-dnxhd/tests/ffmpeg_parity.rsmodified+0 -15
@@ -160,9 +160,6 @@ fn compare(tag: &str, frames: &[Vec<u8>], threads: usize) -> Result<Picture, Str
160160 }
161161
162162 fn run_cases(tag: &str, cases: &[Case]) {
163- if !can_run() {
164- return;
165- }
166163 let dir = scratch(tag);
167164 let mut failures = Vec::new();
168165 for case in cases {
@@ -283,9 +280,6 @@ fn patched(frames: &[Vec<u8>], f: impl Fn(&mut [u8])) -> Vec<Vec<u8>> {
283280
284281 #[test]
285282 fn twelve_bit_streams_by_patching_the_depth_field() {
286- if !can_run() {
287- return;
288- }
289283 let dir = scratch("p12");
290284 let mut failures = Vec::new();
291285 for (tag, size, pix, prof, src) in [
@@ -311,9 +305,6 @@ fn twelve_bit_streams_by_patching_the_depth_field() {
311305
312306 #[test]
313307 fn mbaff_cid_1260_by_patching_the_header() {
314- if !can_run() {
315- return;
316- }
317308 let dir = scratch("mbaff");
318309 let mut failures = Vec::new();
319310 for (tag, src) in [("mbaff_t", T), ("mbaff_n", N)] {
@@ -358,9 +349,6 @@ fn mbaff_cid_1260_by_patching_the_header() {
358349
359350 #[test]
360351 fn video_frame_output_formats_and_interlace_flag() {
361- if !can_run() {
362- return;
363- }
364352 use ec_core::frame::{Interlace, PixelFormat};
365353 let dir = scratch("vf");
366354 let mut dec = DnxhdDecoder::new(CodecParameters::new(CodecId::Dnxhd)).unwrap();
@@ -382,9 +370,6 @@ fn video_frame_output_formats_and_interlace_flag() {
382370
383371 #[test]
384372 fn matroska_carries_dnxhd_too() {
385- if !can_run() {
386- return;
387- }
388373 let dir = scratch("mkv");
389374 let mkv = dir.join("a.mkv");
390375 let mov = dir.join("a.mov");
crates/ec-dnxhd/tests/refusals.rsmodified+8 -11
@@ -11,10 +11,7 @@ fn decoder() -> DnxhdDecoder {
1111 DnxhdDecoder::new(CodecParameters::new(CodecId::Dnxhd)).unwrap()
1212 }
1313
14-fn encode_one(tag: &str, pix: &str, enc: &[&str]) -> Option<Vec<u8>> {
15- if !can_run() {
16- return None;
17- }
14+fn encode_one(tag: &str, pix: &str, enc: &[&str]) -> Vec<u8> {
1815 let dir = scratch(tag);
1916 let out = dir.join("a.mov");
2017 let lavfi = format!("testsrc2=size=320x176:rate=25,format={pix}");
@@ -24,7 +21,7 @@ fn encode_one(tag: &str, pix: &str, enc: &[&str]) -> Option<Vec<u8>> {
2421 assert!(ffmpeg(&args));
2522 let f = mov_frames(&out).remove(0);
2623 let _ = std::fs::remove_dir_all(&dir);
27- Some(f)
24+ f
2825 }
2926
3027 fn refused(r: Result<ec_core::frame::VideoFrame, Error>, what: &str) {
@@ -38,7 +35,7 @@ fn refused(r: Result<ec_core::frame::VideoFrame, Error>, what: &str) {
3835
3936 #[test]
4037 fn alpha_rgb_and_act_variants_are_refused_by_name() {
41- let Some(sq) = encode_one("ref-sq", "yuv422p", &["-profile:v", "dnxhr_sq"]) else { return };
38+ let sq = encode_one("ref-sq", "yuv422p", &["-profile:v", "dnxhr_sq"]);
4239 assert!(decoder().decode_bytes(&sq).is_ok());
4340
4441 let mut alpha = sq.clone();
@@ -50,16 +47,16 @@ fn alpha_rgb_and_act_variants_are_refused_by_name() {
5047 refused(decoder().decode_bytes(&act), "adaptive colour transform");
5148
5249 // GBR (RGB) 4:4:4: ffmpeg writes it with the ACT flag clear.
53- let rgb = encode_one("ref-rgb", "gbrp10le", &["-profile:v", "dnxhr_444"]).unwrap();
50+ let rgb = encode_one("ref-rgb", "gbrp10le", &["-profile:v", "dnxhr_444"]);
5451 refused(decoder().decode_bytes(&rgb), "RGB");
5552 // The same encoder's YCbCr 4:4:4 is accepted.
56- let yuv = encode_one("ref-444", "yuv444p10le", &["-profile:v", "dnxhr_444"]).unwrap();
53+ let yuv = encode_one("ref-444", "yuv444p10le", &["-profile:v", "dnxhr_444"]);
5754 assert!(decoder().decode_bytes(&yuv).is_ok());
5855 }
5956
6057 #[test]
6158 fn unknown_cids_and_bad_headers_are_errors() {
62- let Some(sq) = encode_one("ref-bad", "yuv422p", &["-profile:v", "dnxhr_sq"]) else { return };
59+ let sq = encode_one("ref-bad", "yuv422p", &["-profile:v", "dnxhr_sq"]);
6360 let mut bad = sq.clone();
6461 bad[0x28..0x2c].copy_from_slice(&1239u32.to_be_bytes());
6562 assert!(matches!(decoder().decode_bytes(&bad), Err(Error::Unsupported { .. })));
@@ -76,7 +73,7 @@ fn unknown_cids_and_bad_headers_are_errors() {
7673
7774 #[test]
7875 fn damaged_frames_never_panic() {
79- let Some(hq) = encode_one("ref-dmg", "yuv422p10le", &["-profile:v", "dnxhr_hqx"]) else { return };
76+ let hq = encode_one("ref-dmg", "yuv422p10le", &["-profile:v", "dnxhr_hqx"]);
8077 let mut dec = decoder();
8178 let mut s = 0x9E37_79B9_7F4A_7C15u64;
8279 let mut next = move || {
@@ -119,7 +116,7 @@ fn damaged_frames_never_panic() {
119116 #[test]
120117 fn registry_decoder_path_returns_a_frame() {
121118 use ec_core::registry::Decoder;
122- let Some(hq) = encode_one("ref-reg", "yuv422p", &["-profile:v", "dnxhr_hq"]) else { return };
119+ let hq = encode_one("ref-reg", "yuv422p", &["-profile:v", "dnxhr_hq"]);
123120 let mut d = decoder();
124121 let pkt = ec_core::packet::Packet::new(0, ec_core::timebase::TimeBase::new(1, 25), hq);
125122 d.send_packet(&pkt).unwrap();
crates/ec-dv/Cargo.tomlmodified+1 -0
@@ -10,5 +10,6 @@ authors.workspace = true
1010 ec-core = { workspace = true }
1111
1212 [dev-dependencies]
13+ec-testkit.workspace = true
1314 ec-mp4 = { workspace = true }
1415 ec-riff = { workspace = true }
crates/ec-dv/tests/common/mod.rsmodified+1 -20
@@ -2,25 +2,6 @@
22 #![allow(dead_code)]
33
44 use std::path::{Path, PathBuf};
5-use std::process::Command;
6-
7-pub fn require() -> bool {
8- std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
9-}
10-
11-pub fn have_ffmpeg() -> bool {
12- Command::new("ffmpeg").arg("-version").output().map(|o| o.status.success()).unwrap_or(false)
13-}
14-
15-/// Skip (or fail under EC_REQUIRE_FIXTURES) when ffmpeg is missing.
16-pub fn ffmpeg_or_skip() -> bool {
17- if have_ffmpeg() {
18- return true;
19- }
20- assert!(!require(), "EC_REQUIRE_FIXTURES set but ffmpeg is not available");
21- eprintln!("skipping: no ffmpeg");
22- false
23-}
245
256 pub fn scratch(tag: &str) -> PathBuf {
267 let base = std::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir);
@@ -30,7 +11,7 @@ pub fn scratch(tag: &str) -> PathBuf {
3011 }
3112
3213 pub fn run(args: &[&str]) -> bool {
33- let out = Command::new("ffmpeg").args(["-v", "error", "-y", "-nostdin"]).args(args).output();
14+ let out = ec_testkit::ffmpeg().args(["-v", "error", "-y", "-nostdin"]).args(args).output();
3415 match out {
3516 Ok(o) => {
3617 if !o.status.success() {
crates/ec-dv/tests/containers.rsmodified+10 -29
@@ -35,9 +35,6 @@ fn native(frames: &[Vec<u8>]) -> Vec<u8> {
3535
3636 #[test]
3737 fn avi_and_mov_carry_dv() {
38- if !ffmpeg_or_skip() {
39- return;
40- }
4138 for f in [&FLAVOURS[0], &FLAVOURS[1], &FLAVOURS[3], &FLAVOURS[5]] {
4239 for ext in ["avi", "mov"] {
4340 let Some(path) = make(f, "c", ext, true, 8) else {
@@ -65,9 +62,6 @@ fn avi_and_mov_carry_dv() {
6562
6663 #[test]
6764 fn decoder_trait_output_formats() {
68- if !ffmpeg_or_skip() {
69- return;
70- }
7165 use ec_core::frame::{Frame, Interlace, PixelFormat};
7266 use ec_core::registry::CodecParameters;
7367 let cases = [(0usize, PixelFormat::I422), (1, PixelFormat::I420), (3, PixelFormat::I422), (5, PixelFormat::I422)];
@@ -110,9 +104,6 @@ fn decoder_trait_output_formats() {
110104
111105 #[test]
112106 fn field_order_matches_ffprobe_view() {
113- if !ffmpeg_or_skip() {
114- return;
115- }
116107 use ec_core::frame::Interlace;
117108 // ffmpeg's encoder: +ilme marks the stream interlaced; SD output is bottom-field-first
118109 // unless the (top-field-first) flag is requested.
@@ -125,27 +116,23 @@ fn field_order_matches_ffprobe_view() {
125116 };
126117 let a = first(&ilme);
127118 let b = first(&prog);
128- let out = std::process::Command::new("ffprobe")
119+ let out = ec_testkit::ffprobe()
129120 .args(["-v", "error", "-select_streams", "v:0", "-show_frames", "-read_intervals", "%+#1", "-show_entries", "frame=interlaced_frame,top_field_first,flags", "-of", "default=nw=1"])
130121 .arg(&ilme)
131- .output();
132- if let Ok(o) = out {
133- let txt = String::from_utf8_lossy(&o.stdout).to_string();
134- let interlaced = txt.contains("interlaced_frame=1") || txt.contains("interlaced");
135- let tff = txt.contains("top_field_first=1") || txt.contains("top_first");
136- assert_eq!(a.is_interlaced(), interlaced, "ffprobe says: {txt}");
137- if interlaced {
138- assert_eq!(a == Interlace::TopFieldFirst, tff, "ffprobe says: {txt}");
139- }
122+ .output()
123+ .unwrap();
124+ let txt = String::from_utf8_lossy(&out.stdout).to_string();
125+ let interlaced = txt.contains("interlaced_frame=1") || txt.contains("interlaced");
126+ let tff = txt.contains("top_field_first=1") || txt.contains("top_first");
127+ assert_eq!(a.is_interlaced(), interlaced, "ffprobe says: {txt}");
128+ if interlaced {
129+ assert_eq!(a == Interlace::TopFieldFirst, tff, "ffprobe says: {txt}");
140130 }
141131 assert!(!b.is_interlaced() || a.is_interlaced());
142132 }
143133
144134 #[test]
145135 fn raw_demuxer_sniff_seek_and_junk() {
146- if !ffmpeg_or_skip() {
147- return;
148- }
149136 let f = &FLAVOURS[0];
150137 let path = make(f, "s", "dv", true, 8).unwrap();
151138 let data = std::fs::read(&path).unwrap();
@@ -178,19 +165,13 @@ fn raw_demuxer_sniff_seek_and_junk() {
178165
179166 #[test]
180167 fn audio_rates_and_12bit_match_ffmpeg() {
181- if !ffmpeg_or_skip() {
182- return;
183- }
184168 let f = &FLAVOURS[1]; // PAL
185169 for ar in ["44100", "32000"] {
186170 let dir = scratch("ar");
187171 let p = dir.join(format!("a{ar}.dv"));
188172 let vsrc = "testsrc2=size=720x576:rate=25:duration=2,noise=alls=8:allf=t";
189173 let asrc = format!("sine=frequency=1000:sample_rate={ar}:duration=2");
190- if !run(&["-f", "lavfi", "-i", vsrc, "-f", "lavfi", "-i", &asrc, "-ac", "2", "-frames:v", "6", "-c:v", "dvvideo", "-pix_fmt", f.pix_fmt, "-c:a", "pcm_s16le", "-ar", ar, "-shortest", "-f", "dv", p.to_str().unwrap()]) {
191- assert!(!require(), "ffmpeg could not write {ar} Hz DV");
192- continue;
193- }
174+ assert!(run(&["-f", "lavfi", "-i", vsrc, "-f", "lavfi", "-i", &asrc, "-ac", "2", "-frames:v", "6", "-c:v", "dvvideo", "-pix_fmt", f.pix_fmt, "-c:a", "pcm_s16le", "-ar", ar, "-shortest", "-f", "dv", p.to_str().unwrap()]), "ffmpeg could not write {ar} Hz DV");
194175 compare_audio(&p, ar.parse().unwrap());
195176 // flip the audio source pack to 12-bit non-linear and compare again
196177 let mut data = std::fs::read(&p).unwrap();
crates/ec-dv/tests/ffmpeg_parity.rsmodified+0 -9
@@ -67,9 +67,6 @@ macro_rules! flavour_test {
6767 ($name:ident, $idx:expr) => {
6868 #[test]
6969 fn $name() {
70- if !ffmpeg_or_skip() {
71- return;
72- }
7370 let f = &FLAVOURS[$idx];
7471 for (ilme, noise) in [(false, 0), (true, 6), (true, 25), (false, 40)] {
7572 check_flavour(f, ilme, noise);
@@ -90,9 +87,6 @@ flavour_test!(hd_720p60, 8);
9087
9188 #[test]
9289 fn native_formats() {
93- if !ffmpeg_or_skip() {
94- return;
95- }
9690 for (i, want) in [Chroma::Yuv411, Chroma::Yuv420, Chroma::Yuv411, Chroma::Yuv422, Chroma::Yuv422].into_iter().enumerate() {
9791 let f = &FLAVOURS[i];
9892 let path = make(f, "fmt", "dv", false, 5).unwrap();
@@ -187,9 +181,6 @@ fn check_mutated(f: &Flavour, mode: u32, seed: u64) {
187181
188182 #[test]
189183 fn mutated_streams_match_ffmpeg() {
190- if !ffmpeg_or_skip() {
191- return;
192- }
193184 for f in FLAVOURS {
194185 for mode in 0..5 {
195186 for seed in [1u64, 2, 3] {
crates/ec-dv/tests/perf.rsmodified+0 -3
@@ -37,9 +37,6 @@ fn machine_is_busy() -> bool {
3737
3838 #[test]
3939 fn decode_speed() {
40- if !ffmpeg_or_skip() {
41- return;
42- }
4340 let mut bad = Vec::new();
4441 for f in FLAVOURS {
4542 let hd = f.size.starts_with("1440") || f.size.starts_with("1280") || f.size.starts_with("960");
crates/ec-mjpeg/Cargo.tomlmodified+1 -0
@@ -11,5 +11,6 @@ ec-core = { workspace = true }
1111 ec-image = { workspace = true }
1212
1313 [dev-dependencies]
14+ec-testkit.workspace = true
1415 ec-mp4 = { workspace = true }
1516 ec-matroska = { workspace = true }
crates/ec-mjpeg/tests/ffmpeg_parity.rsmodified+2 -46
@@ -3,39 +3,16 @@
33 //!
44 //! All sources are synthetic: lavfi test patterns encoded by ffmpeg, and the Pillow-made JPEGs in
55 //! `tests/data` (restart markers, progressive). Expected pixels are never stored; ffmpeg is the
6-//! oracle at run time. Without ffmpeg the tests skip, unless `EC_REQUIRE_FIXTURES` is set.
6+//! oracle at run time.
77
88 use std::io::BufReader;
99 use std::path::{Path, PathBuf};
10-use std::process::Command;
1110
1211 use ec_core::frame::{Interlace, PixelFormat, VideoFrame};
1312 use ec_core::registry::{CodecId, CodecParameters, Demuxer, MediaParameters};
1413 use ec_image::Limits;
1514 use ec_mjpeg::MjpegDecoder;
1615
17-fn require() -> bool {
18- std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
19-}
20-
21-fn have_ffmpeg() -> bool {
22- Command::new("ffmpeg")
23- .arg("-version")
24- .output()
25- .map(|o| o.status.success())
26- .unwrap_or(false)
27-}
28-
29-/// False (after saying so) when the oracle is missing and fixtures are optional.
30-fn oracle() -> bool {
31- if have_ffmpeg() {
32- return true;
33- }
34- assert!(!require(), "ffmpeg missing and EC_REQUIRE_FIXTURES is set");
35- eprintln!("SKIP: no ffmpeg");
36- false
37-}
38-
3916 fn scratch(tag: &str) -> PathBuf {
4017 let base = std::env::var_os("TMPDIR")
4118 .map(PathBuf::from)
@@ -46,7 +23,7 @@ fn scratch(tag: &str) -> PathBuf {
4623 }
4724
4825 fn ffmpeg(args: &[&str]) {
49- let ok = Command::new("ffmpeg")
26+ let ok = ec_testkit::ffmpeg()
5027 .args(["-v", "error", "-y", "-nostdin"])
5128 .args(args)
5229 .status()
@@ -155,9 +132,6 @@ fn format_name(f: PixelFormat) -> &'static str {
155132
156133 #[test]
157134 fn still_fixtures_match_ffmpeg() {
158- if !oracle() {
159- return;
160- }
161135 let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data");
162136 let work = scratch("stills");
163137 let mut n = 0;
@@ -186,9 +160,6 @@ fn still_fixtures_match_ffmpeg() {
186160 /// into mov and mkv by a stream copy.
187161 #[test]
188162 fn gray_video_matches_ffmpeg() {
189- if !oracle() {
190- return;
191- }
192163 let work = scratch("gray");
193164 for name in ["basegray", "rstgray", "proggray"] {
194165 let jpg = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!("tests/data/{name}.jpg"));
@@ -215,9 +186,6 @@ fn gray_video_matches_ffmpeg() {
215186
216187 #[test]
217188 fn video_matrix_matches_ffmpeg() {
218- if !oracle() {
219- return;
220- }
221189 let work = scratch("matrix");
222190 let mut cases = 0;
223191 for (pix, expect) in [
@@ -372,9 +340,6 @@ fn write_avi(path: &Path, w: u32, h: u32, packets: &[Vec<u8>]) {
372340
373341 #[test]
374342 fn avi1_packets_without_dht_use_the_default_tables() {
375- if !oracle() {
376- return;
377- }
378343 let work = scratch("nodht");
379344 for (pix, size) in [
380345 ("yuvj420p", "64x48"),
@@ -430,9 +395,6 @@ fn avi1_packets_without_dht_use_the_default_tables() {
430395
431396 #[test]
432397 fn two_field_packets_weave_like_ffmpeg() {
433- if !oracle() {
434- return;
435- }
436398 let work = scratch("fields");
437399 // ffmpeg's mjpeg encoder refuses `-flags +ildct` ("interlacing not supported by codec"),
438400 // so the interlaced material is built from separated fields, one JPEG per field.
@@ -755,9 +717,6 @@ fn mjpeg_stream_packets(path: &Path) -> Vec<Vec<u8>> {
755717
756718 #[test]
757719 fn mjpegb_matches_ffmpeg() {
758- if !oracle() {
759- return;
760- }
761720 let work = scratch("mjpegb");
762721 // Progressive: one field per packet, all three layouts, odd sizes.
763722 for (pix, size, w, h, q) in [
@@ -805,9 +764,6 @@ fn mjpegb_matches_ffmpeg() {
805764
806765 #[test]
807766 fn mjpegb_two_fields_match_ffmpeg() {
808- if !oracle() {
809- return;
810- }
811767 let work = scratch("mjpegb2");
812768 for (pix, size, w, h) in [
813769 ("yuvj420p", "64x48", 64u16, 48u16),
crates/ec-mpeg2/Cargo.tomlmodified+3 -0
@@ -8,3 +8,6 @@ authors.workspace = true
88
99 [dependencies]
1010 ec-core = { workspace = true }
11+
12+[dev-dependencies]
13+ec-testkit.workspace = true
crates/ec-mpeg2/tests/common/mod.rsmodified+1 -14
@@ -4,23 +4,10 @@
44 pub mod synth;
55
66 use std::path::{Path, PathBuf};
7-use std::process::Command;
87
98 use ec_core::frame::VideoFrame;
109 use ec_mpeg2::Mpeg2Decoder;
1110
12-pub fn require() -> bool {
13- std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
14-}
15-
16-pub fn have_ffmpeg() -> bool {
17- Command::new("ffmpeg")
18- .arg("-version")
19- .output()
20- .map(|o| o.status.success())
21- .unwrap_or(false)
22-}
23-
2411 pub fn scratch(tag: &str) -> PathBuf {
2512 let base = std::env::var_os("TMPDIR")
2613 .map(PathBuf::from)
@@ -31,7 +18,7 @@ pub fn scratch(tag: &str) -> PathBuf {
3118 }
3219
3320 pub fn run(args: &[&str]) -> bool {
34- Command::new("ffmpeg")
21+ ec_testkit::ffmpeg()
3522 .args(["-v", "error", "-y", "-nostdin"])
3623 .args(args)
3724 .status()
crates/ec-mpeg2/tests/ffmpeg_parity.rsmodified+1 -10
@@ -65,22 +65,13 @@ fn generate(c: &Case) -> Option<std::path::PathBuf> {
6565
6666 #[test]
6767 fn parity_matrix() {
68- if !have_ffmpeg() {
69- assert!(!require(), "ffmpeg missing");
70- eprintln!("SKIP: no ffmpeg");
71- return;
72- }
7368 let only = std::env::var("EC_MPEG2_CASE").ok();
7469 let mut failures = Vec::new();
7570 for c in CASES {
7671 if only.as_deref().is_some_and(|o| o != c.tag) {
7772 continue;
7873 }
79- let Some(es) = generate(c) else {
80- assert!(!require(), "{}: ffmpeg cannot encode", c.tag);
81- eprintln!("SKIP {}", c.tag);
82- continue;
83- };
74+ let es = generate(c).unwrap_or_else(|| panic!("{}: ffmpeg cannot encode", c.tag));
8475 match compare(c.tag, &es, c.pix, &[]) {
8576 Ok(n) => eprintln!("OK {} ({n} frames)", c.tag),
8677 Err(e) => {
crates/ec-mpeg2/tests/synth_parity.rsmodified+0 -5
@@ -16,11 +16,6 @@ fn run_one(tag: &str, cfg: &SynthCfg, pix: &str) -> Result<usize, String> {
1616
1717 #[test]
1818 fn synthetic_streams_match_ffmpeg() {
19- if !have_ffmpeg() {
20- assert!(!require(), "ffmpeg missing");
21- eprintln!("SKIP: no ffmpeg");
22- return;
23- }
2419 let n: u64 = std::env::var("EC_SYNTH_N").ok().and_then(|v| v.parse().ok()).unwrap_or(24);
2520 let base: u64 = std::env::var("EC_SYNTH_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(1);
2621 let heavy = std::env::var_os("EC_SYNTH_LIGHT").is_none();
crates/ec-mpeg4/Cargo.tomlmodified+1 -0
@@ -10,6 +10,7 @@ authors.workspace = true
1010 ec-core = { workspace = true }
1111
1212 [dev-dependencies]
13+ec-testkit.workspace = true
1314 ec-mp4 = { workspace = true }
1415 ec-riff = { workspace = true }
1516 ec-matroska = { workspace = true }
crates/ec-mpeg4/tests/common/mod.rsmodified+1 -40
@@ -8,50 +8,11 @@
88 #![allow(dead_code)]
99
1010 use std::path::{Path, PathBuf};
11-use std::process::Command;
1211
1312 use ec_core::frame::VideoFrame;
1413 use ec_core::registry::{CodecId, CodecParameters};
1514 use ec_mpeg4::{Mpeg4Decoder, PictureInfo};
1615
17-pub fn require() -> bool {
18- std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
19-}
20-
21-pub fn have_ffmpeg() -> bool {
22- Command::new("ffmpeg")
23- .arg("-version")
24- .output()
25- .map(|o| o.status.success())
26- .unwrap_or(false)
27-}
28-
29-/// Whether the local ffmpeg lists `name` as an encoder.
30-pub fn have_encoder(name: &str) -> bool {
31- Command::new("ffmpeg")
32- .args(["-hide_banner", "-encoders"])
33- .output()
34- .map(|o| {
35- String::from_utf8_lossy(&o.stdout)
36- .lines()
37- .any(|l| l.split_whitespace().nth(1) == Some(name))
38- })
39- .unwrap_or(false)
40-}
41-
42-/// `true` when the test may run; under `EC_REQUIRE_FIXTURES` a missing ffmpeg is a failure.
43-pub fn gate() -> bool {
44- if have_ffmpeg() {
45- return true;
46- }
47- assert!(
48- !require(),
49- "ffmpeg is required (EC_REQUIRE_FIXTURES is set)"
50- );
51- eprintln!("skipped: no ffmpeg");
52- false
53-}
54-
5516 pub fn scratch(tag: &str) -> PathBuf {
5617 let base = std::env::var_os("TMPDIR")
5718 .map(PathBuf::from)
@@ -62,7 +23,7 @@ pub fn scratch(tag: &str) -> PathBuf {
6223 }
6324
6425 pub fn run(args: &[&str]) -> bool {
65- Command::new("ffmpeg")
26+ ec_testkit::ffmpeg()
6627 .args(["-v", "error", "-y", "-nostdin"])
6728 .args(args)
6829 .status()
crates/ec-mpeg4/tests/containers.rsmodified+2 -23
@@ -69,9 +69,6 @@ fn decode_registry(params: ec_core::registry::CodecParameters, pk: &[Packet]) ->
6969 }
7070
7171 fn check(tag: &str, file: &str, enc: &[&str]) {
72- if !gate() {
73- return;
74- }
7572 let dir = scratch(tag);
7673 let path = dir.join(file);
7774 assert!(encode("176x144", 30, enc, &path), "encode");
@@ -179,9 +176,6 @@ fn mkv_asp() {
179176 }
180177 #[test]
181178 fn gp3_h263() {
182- if !gate() {
183- return;
184- }
185179 let dir = scratch("3gp");
186180 let path = dir.join("a.3gp");
187181 assert!(encode(
@@ -205,9 +199,6 @@ fn gp3_h263() {
205199 /// where it was.
206200 #[test]
207201 fn packed_bitstream_matches_unpacked() {
208- if !gate() {
209- return;
210- }
211202 let dir = scratch("packed");
212203 let path = dir.join("a.avi");
213204 assert!(encode(
@@ -246,12 +237,9 @@ fn packed_bitstream_matches_unpacked() {
246237
247238 #[test]
248239 fn data_partitioning_is_refused_by_name() {
249- if !gate() {
250- return;
251- }
252240 let dir = scratch("dp");
253241 let path = dir.join("a.m4v");
254- if !encode(
242+ assert!(encode(
255243 "176x144",
256244 4,
257245 &[
@@ -265,10 +253,7 @@ fn data_partitioning_is_refused_by_name() {
265253 "m4v",
266254 ],
267255 &path,
268- ) {
269- eprintln!("SKIP: encoder rejects data partitioning");
270- return;
271- }
256+ ), "encoder rejects data partitioning");
272257 let es = std::fs::read(&path).unwrap();
273258 let mut dec = new_decoder();
274259 let mut err = None;
@@ -288,9 +273,6 @@ fn data_partitioning_is_refused_by_name() {
288273
289274 #[test]
290275 fn corrupt_input_does_not_panic() {
291- if !gate() {
292- return;
293- }
294276 let dir = scratch("corrupt");
295277 let path = dir.join("a.m4v");
296278 assert!(encode(
@@ -349,9 +331,6 @@ fn corrupt_input_does_not_panic() {
349331 #[test]
350332 #[ignore]
351333 fn speed_720p_at_least_120_fps() {
352- if !gate() {
353- return;
354- }
355334 let dir = scratch("speed");
356335 let path = dir.join("hd.m4v");
357336 assert!(encode(
crates/ec-mpeg4/tests/ffmpeg_parity.rsmodified+1 -21
@@ -1,6 +1,5 @@
11 //! 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.
2+//! time (`ffmpeg -c:v mpeg4`, `libxvid`, `h263`).
43
54 mod common;
65
@@ -10,9 +9,6 @@ macro_rules! parity {
109 ($name:ident, $size:expr, $frames:expr, [$($arg:expr),* $(,)?]) => {
1110 #[test]
1211 fn $name() {
13- if !gate() {
14- return;
15- }
1612 let n = parity_es(stringify!($name), $size, $frames, &[$($arg),*], "m4v").unwrap();
1713 assert!(n >= $frames - 2, "decoded only {n} of {} pictures", $frames);
1814 }
@@ -295,9 +291,6 @@ parity!(
295291
296292 #[test]
297293 fn hd_720p_with_everything() {
298- if !gate() {
299- return;
300- }
301294 let n = parity_es(
302295 "hd720",
303296 "1280x720",
@@ -321,9 +314,6 @@ fn hd_720p_with_everything() {
321314 // H.263 baseline (short video header).
322315 #[test]
323316 fn h263_formats() {
324- if !gate() {
325- return;
326- }
327317 for (size, q, gop) in [
328318 ("128x96", "4", "8"),
329319 ("176x144", "4", "10"),
@@ -346,9 +336,6 @@ fn h263_formats() {
346336
347337 #[test]
348338 fn h263_with_gob_headers() {
349- if !gate() {
350- return;
351- }
352339 // `-ps` makes ffmpeg's H.263 encoder start a GOB (with its header) every n macroblocks.
353340 let n = parity_es(
354341 "h263_gob",
@@ -363,13 +350,6 @@ fn h263_with_gob_headers() {
363350
364351 // libxvid: GMC with warp points, N-VOPs, the XviD IDCT and XviD's qpel/bframe habits.
365352 fn 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- }
373353 let mut enc = vec!["-c:v", "libxvid"];
374354 enc.extend_from_slice(extra);
375355 let n = parity_es(tag, size, frames, &enc, "m4v").unwrap_or_else(|e| panic!("{tag}: {e}"));
crates/ec-mpeg4/tests/msmpeg4.rsmodified+0 -8
@@ -12,14 +12,6 @@ use ec_mpeg4::Mpeg4Decoder;
1212
1313 #[allow(clippy::too_many_arguments)]
1414 fn check(tag: &str, vtag: &str, codec: &str, id: CodecId, lavfi: &str, size: &str, frames: u32, enc: &[&str]) {
15- if !gate() {
16- return;
17- }
18- if !have_encoder(codec) {
19- assert!(!require(), "ffmpeg encoder {codec} missing");
20- eprintln!("skipped: no {codec} encoder");
21- return;
22- }
2315 let dir = scratch(tag);
2416 let path = dir.join(format!("{tag}.avi"));
2517 let input = format!("{lavfi}=size={size}:rate=25");
crates/ec-prores/Cargo.tomlmodified+1 -0
@@ -13,4 +13,5 @@ bytemuck = "1"
1313 wide = { workspace = true }
1414
1515 [dev-dependencies]
16+ec-testkit.workspace = true
1617 ec-mp4 = { workspace = true }
crates/ec-prores/tests/common/mod.rsmodified+1 -24
@@ -3,34 +3,11 @@
33
44 use std::io::Cursor;
55 use std::path::PathBuf;
6-use std::process::Command;
76
87 use ec_core::registry::{CodecId, CodecParameters, Demuxer};
98 use ec_mp4::Mp4Demuxer;
109 use ec_prores::{DecodedFrame, ProResDecoder};
1110
12-pub fn require() -> bool {
13- std::env::var_os("EC_REQUIRE_FIXTURES").is_some()
14-}
15-
16-pub fn have_ffmpeg() -> bool {
17- Command::new("ffmpeg")
18- .arg("-version")
19- .output()
20- .map(|o| o.status.success())
21- .unwrap_or(false)
22-}
23-
24-/// Skip (or fail under EC_REQUIRE_FIXTURES) when ffmpeg is missing.
25-pub fn ffmpeg_or_skip() -> bool {
26- if have_ffmpeg() {
27- return true;
28- }
29- assert!(!require(), "EC_REQUIRE_FIXTURES set but ffmpeg is not available");
30- eprintln!("skipping: no ffmpeg");
31- false
32-}
33-
3411 pub fn scratch(tag: &str) -> PathBuf {
3512 let base = std::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir);
3613 let dir = base.join(format!("ec-prores-{}-{}", std::process::id(), tag));
@@ -39,7 +16,7 @@ pub fn scratch(tag: &str) -> PathBuf {
3916 }
4017
4118 pub fn run(args: &[&str]) -> bool {
42- Command::new("ffmpeg")
19+ ec_testkit::ffmpeg()
4320 .args(["-v", "error", "-y", "-nostdin"])
4421 .args(args)
4522 .status()
crates/ec-prores/tests/encode.rsmodified+4 -27
@@ -1,11 +1,9 @@
11 //! The ProRes encoder: ffmpeg decodes what we write exactly as ec-prores does, frame sizes sit on
22 //! Apple's rates, quality matches or beats ffmpeg's `prores_ks`, the .mov probes right.
3-//! All media is synthetic; ffmpeg-dependent tests skip (or fail under `EC_REQUIRE_FIXTURES`)
4-//! when ffmpeg is missing.
3+//! All media is synthetic.
54
65 mod common;
76 use std::io::Cursor;
8-use std::process::Command;
97
108 use common::*;
119 use ec_core::frame::{ColorInfo, PixelFormat, Plane, VideoFrame};
@@ -135,9 +133,6 @@ fn pix(p: Profile) -> &'static str {
135133
136134 #[test]
137135 fn ffmpeg_and_ec_prores_decode_every_profile_identically() {
138- if !ffmpeg_or_skip() {
139- return;
140- }
141136 let dir = scratch("enc-rt");
142137 for (i, p) in ALL.into_iter().enumerate() {
143138 // Odd size: padding macroblocks on both axes, 3 slice widths in a row.
@@ -223,9 +218,6 @@ fn frame_sizes_sit_on_apples_rates() {
223218
224219 #[test]
225220 fn encoder_trait_and_mov_probe() {
226- if !ffmpeg_or_skip() {
227- return;
228- }
229221 let dir = scratch("enc-probe");
230222 let (w, h) = (192, 108);
231223 for p in ALL {
@@ -249,7 +241,7 @@ fn encoder_trait_and_mov_probe() {
249241 assert!(!mov.windows(4).any(|x| x == b"avcC" || x == b"esds"), "{p:?}: a config box");
250242 let path = dir.join(format!("{}.mov", String::from_utf8_lossy(&p.fourcc())));
251243 std::fs::write(&path, &mov).unwrap();
252- let out = Command::new("ffprobe")
244+ let out = ec_testkit::ffprobe()
253245 .args(["-v", "error", "-select_streams", "v:0", "-show_entries"])
254246 .arg("stream=codec_name,profile,pix_fmt,field_order,color_space,color_transfer,color_primaries,codec_tag_string,width,height,nb_frames")
255247 .args(["-of", "default=nw=1"])
@@ -336,25 +328,16 @@ fn psnr_vs_prores_ks(generator: &str, post: &str, tag: &str) {
336328
337329 #[test]
338330 fn quality_matches_prores_ks_testsrc2() {
339- if !ffmpeg_or_skip() {
340- return;
341- }
342331 psnr_vs_prores_ks("testsrc2", "", "q-testsrc2");
343332 }
344333
345334 #[test]
346335 fn quality_matches_prores_ks_mandelbrot() {
347- if !ffmpeg_or_skip() {
348- return;
349- }
350336 psnr_vs_prores_ks("mandelbrot", "", "q-mandel");
351337 }
352338
353339 #[test]
354340 fn quality_matches_prores_ks_noisy() {
355- if !ffmpeg_or_skip() {
356- return;
357- }
358341 psnr_vs_prores_ks("testsrc2", ",noise=alls=12:allf=t", "q-noisy");
359342 }
360343
@@ -404,7 +387,7 @@ fn encode_speed_1080p_hq() {
404387 }
405388
406389 fn probe(path: &std::path::Path, entry: &str) -> String {
407- let out = Command::new("ffprobe")
390+ let out = ec_testkit::ffprobe()
408391 .args(["-v", "error", "-select_streams", "v:0", "-show_entries", &format!("stream={entry}"), "-of", "default=nw=1:nk=1"])
409392 .arg(path)
410393 .output()
@@ -413,7 +396,7 @@ fn probe(path: &std::path::Path, entry: &str) -> String {
413396 }
414397
415398 fn probe_frame(path: &std::path::Path, entry: &str) -> String {
416- let out = Command::new("ffprobe")
399+ let out = ec_testkit::ffprobe()
417400 .args(["-v", "error", "-select_streams", "v:0", "-show_frames", "-read_intervals", "%+#1", "-show_entries", &format!("frame={entry}"), "-of", "default=nw=1:nk=1"])
418401 .arg(path)
419402 .output()
@@ -424,9 +407,6 @@ fn probe_frame(path: &std::path::Path, entry: &str) -> String {
424407 #[test]
425408 fn interlaced_every_profile_ffmpeg_and_ours_agree() {
426409 use ec_core::frame::Interlace;
427- if !ffmpeg_or_skip() {
428- return;
429- }
430410 let dir = scratch("enc-field");
431411 for (i, p) in ALL.into_iter().enumerate() {
432412 for (order, field_order) in [(Interlace::TopFieldFirst, "tt"), (Interlace::BottomFieldFirst, "bb")] {
@@ -508,9 +488,6 @@ fn alpha_pattern(w: usize, h: usize, seed: u64) -> Vec<u16> {
508488 fn alpha_4444_round_trips_and_ffmpeg_agrees() {
509489 use ec_core::frame::Interlace;
510490 use ec_prores::AlphaPlane;
511- if !ffmpeg_or_skip() {
512- return;
513- }
514491 let dir = scratch("enc-alpha");
515492 let mut n = 0;
516493 for p in [Profile::P4444, Profile::P4444Xq] {
crates/ec-prores/tests/ffmpeg_parity.rsmodified+0 -3
@@ -112,9 +112,6 @@ fn generate(c: &Case) -> std::path::PathBuf {
112112
113113 #[test]
114114 fn matches_ffmpeg() {
115- if !ffmpeg_or_skip() {
116- return;
117- }
118115 let mut bad = Vec::new();
119116 for c in CASES {
120117 let mov = generate(c);
crates/ec-prores/tests/perf.rsmodified+0 -3
@@ -6,9 +6,6 @@ use common::*;
66
77 #[test]
88 fn hd_hq_throughput() {
9- if !ffmpeg_or_skip() {
10- return;
11- }
129 let dir = scratch("perf");
1310 let mov = dir.join("hd.mov");
1411 assert!(run(&[
crates/ec-prores/tests/robust.rsmodified+8 -11
@@ -19,15 +19,12 @@ impl Rng {
1919 }
2020
2121 /// Small frames: progressive 422, interlaced 422, 4444 with alpha.
22-fn frames() -> Option<Vec<Vec<u8>>> {
23- static CACHE: std::sync::OnceLock<Option<Vec<Vec<u8>>>> = std::sync::OnceLock::new();
22+fn frames() -> Vec<Vec<u8>> {
23+ static CACHE: std::sync::OnceLock<Vec<Vec<u8>>> = std::sync::OnceLock::new();
2424 CACHE.get_or_init(make_frames).clone()
2525 }
2626
27-fn make_frames() -> Option<Vec<Vec<u8>>> {
28- if !ffmpeg_or_skip() {
29- return None;
30- }
27+fn make_frames() -> Vec<Vec<u8>> {
3128 let dir = scratch("robust");
3229 let mut out = Vec::new();
3330 for (i, (prof, fmt, extra)) in [
@@ -51,12 +48,12 @@ fn make_frames() -> Option<Vec<Vec<u8>>> {
5148 out.push(packets(&std::fs::read(&mov).unwrap()).remove(0));
5249 }
5350 let _ = std::fs::remove_dir_all(dir);
54- Some(out)
51+ out
5552 }
5653
5754 #[test]
5855 fn truncations_never_panic() {
59- let Some(fs) = frames() else { return };
56+ let fs = frames();
6057 for f in &fs {
6158 let mut d = decoder(2);
6259 assert!(d.decode(f).is_ok());
@@ -68,7 +65,7 @@ fn truncations_never_panic() {
6865
6966 #[test]
7067 fn corruptions_never_panic() {
71- let Some(fs) = frames() else { return };
68+ let fs = frames();
7269 let mut rng = Rng(0x9E3779B97F4A7C15);
7370 for f in &fs {
7471 let mut d = decoder(3);
@@ -105,7 +102,7 @@ fn garbage_is_refused_by_name() {
105102
106103 #[test]
107104 fn hostile_dimensions_are_bounded() {
108- let Some(fs) = frames() else { return };
105+ let fs = frames();
109106 let mut g = fs[0].clone();
110107 // width/height at frame-header bytes 8..12 (after size+icpf: offset 8+8).
111108 g[16..20].copy_from_slice(&[0xFF, 0xFF, 0xFF, 0xFF]);
@@ -131,7 +128,7 @@ fn wrong_codec_is_unsupported() {
131128 fn dump_seeds() {
132129 let dir = std::env::var("EC_SEED_DIR").expect("EC_SEED_DIR");
133130 std::fs::create_dir_all(&dir).unwrap();
134- let Some(fs) = frames() else { return };
131+ let fs = frames();
135132 for (i, f) in fs.iter().enumerate() {
136133 std::fs::write(format!("{dir}/seed{i}.bin"), f).unwrap();
137134 }