Merge branch 'simplify/w0-m6' into simplify/w0
Browse files at this commit27 changed files +55 -346
- Cargo.lock +6 -0
- crates/ec-dnxhd/Cargo.toml +1 -0
- crates/ec-dnxhd/tests/common/mod.rs +1 -24
- crates/ec-dnxhd/tests/ffmpeg_parity.rs +0 -15
- crates/ec-dnxhd/tests/refusals.rs +8 -11
- crates/ec-dv/Cargo.toml +1 -0
- crates/ec-dv/tests/common/mod.rs +1 -20
- crates/ec-dv/tests/containers.rs +10 -29
- crates/ec-dv/tests/ffmpeg_parity.rs +0 -9
- crates/ec-dv/tests/perf.rs +0 -3
- crates/ec-mjpeg/Cargo.toml +1 -0
- crates/ec-mjpeg/tests/ffmpeg_parity.rs +2 -46
- crates/ec-mpeg2/Cargo.toml +3 -0
- crates/ec-mpeg2/tests/common/mod.rs +1 -14
- crates/ec-mpeg2/tests/ffmpeg_parity.rs +1 -10
- crates/ec-mpeg2/tests/synth_parity.rs +0 -5
- crates/ec-mpeg4/Cargo.toml +1 -0
- crates/ec-mpeg4/tests/common/mod.rs +1 -40
- crates/ec-mpeg4/tests/containers.rs +2 -23
- crates/ec-mpeg4/tests/ffmpeg_parity.rs +1 -21
- crates/ec-mpeg4/tests/msmpeg4.rs +0 -8
- crates/ec-prores/Cargo.toml +1 -0
- crates/ec-prores/tests/common/mod.rs +1 -24
- crates/ec-prores/tests/encode.rs +4 -27
- crates/ec-prores/tests/ffmpeg_parity.rs +0 -3
- crates/ec-prores/tests/perf.rs +0 -3
- crates/ec-prores/tests/robust.rs +8 -11
Cargo.lockmodified+6 -0
| @@ -437,6 +437,7 @@ dependencies = [ | ||
| 437 | 437 | "ec-matroska", |
| 438 | 438 | "ec-mp4", |
| 439 | 439 | "ec-riff", |
| 440 | + "ec-testkit", | |
| 440 | 441 | ] |
| 441 | 442 | |
| 442 | 443 | [[package]] |
| @@ -462,6 +463,7 @@ dependencies = [ | ||
| 462 | 463 | "ec-core", |
| 463 | 464 | "ec-mp4", |
| 464 | 465 | "ec-riff", |
| 466 | + "ec-testkit", | |
| 465 | 467 | ] |
| 466 | 468 | |
| 467 | 469 | [[package]] |
| @@ -584,6 +586,7 @@ dependencies = [ | ||
| 584 | 586 | "ec-image", |
| 585 | 587 | "ec-matroska", |
| 586 | 588 | "ec-mp4", |
| 589 | + "ec-testkit", | |
| 587 | 590 | ] |
| 588 | 591 | |
| 589 | 592 | [[package]] |
| @@ -608,6 +611,7 @@ name = "ec-mpeg2" | ||
| 608 | 611 | version = "0.1.0" |
| 609 | 612 | dependencies = [ |
| 610 | 613 | "ec-core", |
| 614 | + "ec-testkit", | |
| 611 | 615 | ] |
| 612 | 616 | |
| 613 | 617 | [[package]] |
| @@ -618,6 +622,7 @@ dependencies = [ | ||
| 618 | 622 | "ec-matroska", |
| 619 | 623 | "ec-mp4", |
| 620 | 624 | "ec-riff", |
| 625 | + "ec-testkit", | |
| 621 | 626 | ] |
| 622 | 627 | |
| 623 | 628 | [[package]] |
| @@ -698,6 +703,7 @@ dependencies = [ | ||
| 698 | 703 | "bytemuck", |
| 699 | 704 | "ec-core", |
| 700 | 705 | "ec-mp4", |
| 706 | + "ec-testkit", | |
| 701 | 707 | "wide", |
| 702 | 708 | ] |
| 703 | 709 |
crates/ec-dnxhd/Cargo.tomlmodified+1 -0
| @@ -10,6 +10,7 @@ authors.workspace = true | ||
| 10 | 10 | ec-core = { workspace = true } |
| 11 | 11 | |
| 12 | 12 | [dev-dependencies] |
| 13 | +ec-testkit.workspace = true | |
| 13 | 14 | ec-mp4 = { workspace = true } |
| 14 | 15 | ec-matroska = { workspace = true } |
| 15 | 16 | ec-riff = { workspace = true } |
crates/ec-dnxhd/tests/common/mod.rsmodified+1 -24
| @@ -2,33 +2,10 @@ | ||
| 2 | 2 | #![allow(dead_code)] |
| 3 | 3 | |
| 4 | 4 | use std::path::{Path, PathBuf}; |
| 5 | -use std::process::Command; | |
| 6 | 5 | |
| 7 | 6 | use ec_core::Demuxer; |
| 8 | 7 | use ec_core::frame::VideoFrame; |
| 9 | 8 | |
| 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 | - | |
| 32 | 9 | pub fn scratch(tag: &str) -> PathBuf { |
| 33 | 10 | let base = std::env::var_os("TMPDIR") |
| 34 | 11 | .map(PathBuf::from) |
| @@ -39,7 +16,7 @@ pub fn scratch(tag: &str) -> PathBuf { | ||
| 39 | 16 | } |
| 40 | 17 | |
| 41 | 18 | pub fn ffmpeg(args: &[&str]) -> bool { |
| 42 | - let out = Command::new("ffmpeg") | |
| 19 | + let out = ec_testkit::ffmpeg() | |
| 43 | 20 | .args(["-v", "error", "-y", "-nostdin"]) |
| 44 | 21 | .args(args) |
| 45 | 22 | .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 | ||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | fn run_cases(tag: &str, cases: &[Case]) { |
| 163 | - if !can_run() { | |
| 164 | - return; | |
| 165 | - } | |
| 166 | 163 | let dir = scratch(tag); |
| 167 | 164 | let mut failures = Vec::new(); |
| 168 | 165 | for case in cases { |
| @@ -283,9 +280,6 @@ fn patched(frames: &[Vec<u8>], f: impl Fn(&mut [u8])) -> Vec<Vec<u8>> { | ||
| 283 | 280 | |
| 284 | 281 | #[test] |
| 285 | 282 | fn twelve_bit_streams_by_patching_the_depth_field() { |
| 286 | - if !can_run() { | |
| 287 | - return; | |
| 288 | - } | |
| 289 | 283 | let dir = scratch("p12"); |
| 290 | 284 | let mut failures = Vec::new(); |
| 291 | 285 | for (tag, size, pix, prof, src) in [ |
| @@ -311,9 +305,6 @@ fn twelve_bit_streams_by_patching_the_depth_field() { | ||
| 311 | 305 | |
| 312 | 306 | #[test] |
| 313 | 307 | fn mbaff_cid_1260_by_patching_the_header() { |
| 314 | - if !can_run() { | |
| 315 | - return; | |
| 316 | - } | |
| 317 | 308 | let dir = scratch("mbaff"); |
| 318 | 309 | let mut failures = Vec::new(); |
| 319 | 310 | for (tag, src) in [("mbaff_t", T), ("mbaff_n", N)] { |
| @@ -358,9 +349,6 @@ fn mbaff_cid_1260_by_patching_the_header() { | ||
| 358 | 349 | |
| 359 | 350 | #[test] |
| 360 | 351 | fn video_frame_output_formats_and_interlace_flag() { |
| 361 | - if !can_run() { | |
| 362 | - return; | |
| 363 | - } | |
| 364 | 352 | use ec_core::frame::{Interlace, PixelFormat}; |
| 365 | 353 | let dir = scratch("vf"); |
| 366 | 354 | let mut dec = DnxhdDecoder::new(CodecParameters::new(CodecId::Dnxhd)).unwrap(); |
| @@ -382,9 +370,6 @@ fn video_frame_output_formats_and_interlace_flag() { | ||
| 382 | 370 | |
| 383 | 371 | #[test] |
| 384 | 372 | fn matroska_carries_dnxhd_too() { |
| 385 | - if !can_run() { | |
| 386 | - return; | |
| 387 | - } | |
| 388 | 373 | let dir = scratch("mkv"); |
| 389 | 374 | let mkv = dir.join("a.mkv"); |
| 390 | 375 | let mov = dir.join("a.mov"); |
crates/ec-dnxhd/tests/refusals.rsmodified+8 -11
| @@ -11,10 +11,7 @@ fn decoder() -> DnxhdDecoder { | ||
| 11 | 11 | DnxhdDecoder::new(CodecParameters::new(CodecId::Dnxhd)).unwrap() |
| 12 | 12 | } |
| 13 | 13 | |
| 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> { | |
| 18 | 15 | let dir = scratch(tag); |
| 19 | 16 | let out = dir.join("a.mov"); |
| 20 | 17 | 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>> { | ||
| 24 | 21 | assert!(ffmpeg(&args)); |
| 25 | 22 | let f = mov_frames(&out).remove(0); |
| 26 | 23 | let _ = std::fs::remove_dir_all(&dir); |
| 27 | - Some(f) | |
| 24 | + f | |
| 28 | 25 | } |
| 29 | 26 | |
| 30 | 27 | 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) { | ||
| 38 | 35 | |
| 39 | 36 | #[test] |
| 40 | 37 | 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"]); | |
| 42 | 39 | assert!(decoder().decode_bytes(&sq).is_ok()); |
| 43 | 40 | |
| 44 | 41 | let mut alpha = sq.clone(); |
| @@ -50,16 +47,16 @@ fn alpha_rgb_and_act_variants_are_refused_by_name() { | ||
| 50 | 47 | refused(decoder().decode_bytes(&act), "adaptive colour transform"); |
| 51 | 48 | |
| 52 | 49 | // 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"]); | |
| 54 | 51 | refused(decoder().decode_bytes(&rgb), "RGB"); |
| 55 | 52 | // 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"]); | |
| 57 | 54 | assert!(decoder().decode_bytes(&yuv).is_ok()); |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | #[test] |
| 61 | 58 | 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"]); | |
| 63 | 60 | let mut bad = sq.clone(); |
| 64 | 61 | bad[0x28..0x2c].copy_from_slice(&1239u32.to_be_bytes()); |
| 65 | 62 | assert!(matches!(decoder().decode_bytes(&bad), Err(Error::Unsupported { .. }))); |
| @@ -76,7 +73,7 @@ fn unknown_cids_and_bad_headers_are_errors() { | ||
| 76 | 73 | |
| 77 | 74 | #[test] |
| 78 | 75 | 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"]); | |
| 80 | 77 | let mut dec = decoder(); |
| 81 | 78 | let mut s = 0x9E37_79B9_7F4A_7C15u64; |
| 82 | 79 | let mut next = move || { |
| @@ -119,7 +116,7 @@ fn damaged_frames_never_panic() { | ||
| 119 | 116 | #[test] |
| 120 | 117 | fn registry_decoder_path_returns_a_frame() { |
| 121 | 118 | 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"]); | |
| 123 | 120 | let mut d = decoder(); |
| 124 | 121 | let pkt = ec_core::packet::Packet::new(0, ec_core::timebase::TimeBase::new(1, 25), hq); |
| 125 | 122 | d.send_packet(&pkt).unwrap(); |
crates/ec-dv/Cargo.tomlmodified+1 -0
| @@ -10,5 +10,6 @@ authors.workspace = true | ||
| 10 | 10 | ec-core = { workspace = true } |
| 11 | 11 | |
| 12 | 12 | [dev-dependencies] |
| 13 | +ec-testkit.workspace = true | |
| 13 | 14 | ec-mp4 = { workspace = true } |
| 14 | 15 | ec-riff = { workspace = true } |
crates/ec-dv/tests/common/mod.rsmodified+1 -20
| @@ -2,25 +2,6 @@ | ||
| 2 | 2 | #![allow(dead_code)] |
| 3 | 3 | |
| 4 | 4 | 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 | -} | |
| 24 | 5 | |
| 25 | 6 | pub fn scratch(tag: &str) -> PathBuf { |
| 26 | 7 | 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 { | ||
| 30 | 11 | } |
| 31 | 12 | |
| 32 | 13 | 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(); | |
| 34 | 15 | match out { |
| 35 | 16 | Ok(o) => { |
| 36 | 17 | if !o.status.success() { |
crates/ec-dv/tests/containers.rsmodified+10 -29
| @@ -35,9 +35,6 @@ fn native(frames: &[Vec<u8>]) -> Vec<u8> { | ||
| 35 | 35 | |
| 36 | 36 | #[test] |
| 37 | 37 | fn avi_and_mov_carry_dv() { |
| 38 | - if !ffmpeg_or_skip() { | |
| 39 | - return; | |
| 40 | - } | |
| 41 | 38 | for f in [&FLAVOURS[0], &FLAVOURS[1], &FLAVOURS[3], &FLAVOURS[5]] { |
| 42 | 39 | for ext in ["avi", "mov"] { |
| 43 | 40 | let Some(path) = make(f, "c", ext, true, 8) else { |
| @@ -65,9 +62,6 @@ fn avi_and_mov_carry_dv() { | ||
| 65 | 62 | |
| 66 | 63 | #[test] |
| 67 | 64 | fn decoder_trait_output_formats() { |
| 68 | - if !ffmpeg_or_skip() { | |
| 69 | - return; | |
| 70 | - } | |
| 71 | 65 | use ec_core::frame::{Frame, Interlace, PixelFormat}; |
| 72 | 66 | use ec_core::registry::CodecParameters; |
| 73 | 67 | let cases = [(0usize, PixelFormat::I422), (1, PixelFormat::I420), (3, PixelFormat::I422), (5, PixelFormat::I422)]; |
| @@ -110,9 +104,6 @@ fn decoder_trait_output_formats() { | ||
| 110 | 104 | |
| 111 | 105 | #[test] |
| 112 | 106 | fn field_order_matches_ffprobe_view() { |
| 113 | - if !ffmpeg_or_skip() { | |
| 114 | - return; | |
| 115 | - } | |
| 116 | 107 | use ec_core::frame::Interlace; |
| 117 | 108 | // ffmpeg's encoder: +ilme marks the stream interlaced; SD output is bottom-field-first |
| 118 | 109 | // unless the (top-field-first) flag is requested. |
| @@ -125,27 +116,23 @@ fn field_order_matches_ffprobe_view() { | ||
| 125 | 116 | }; |
| 126 | 117 | let a = first(&ilme); |
| 127 | 118 | let b = first(&prog); |
| 128 | - let out = std::process::Command::new("ffprobe") | |
| 119 | + let out = ec_testkit::ffprobe() | |
| 129 | 120 | .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"]) |
| 130 | 121 | .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}"); | |
| 140 | 130 | } |
| 141 | 131 | assert!(!b.is_interlaced() || a.is_interlaced()); |
| 142 | 132 | } |
| 143 | 133 | |
| 144 | 134 | #[test] |
| 145 | 135 | fn raw_demuxer_sniff_seek_and_junk() { |
| 146 | - if !ffmpeg_or_skip() { | |
| 147 | - return; | |
| 148 | - } | |
| 149 | 136 | let f = &FLAVOURS[0]; |
| 150 | 137 | let path = make(f, "s", "dv", true, 8).unwrap(); |
| 151 | 138 | let data = std::fs::read(&path).unwrap(); |
| @@ -178,19 +165,13 @@ fn raw_demuxer_sniff_seek_and_junk() { | ||
| 178 | 165 | |
| 179 | 166 | #[test] |
| 180 | 167 | fn audio_rates_and_12bit_match_ffmpeg() { |
| 181 | - if !ffmpeg_or_skip() { | |
| 182 | - return; | |
| 183 | - } | |
| 184 | 168 | let f = &FLAVOURS[1]; // PAL |
| 185 | 169 | for ar in ["44100", "32000"] { |
| 186 | 170 | let dir = scratch("ar"); |
| 187 | 171 | let p = dir.join(format!("a{ar}.dv")); |
| 188 | 172 | let vsrc = "testsrc2=size=720x576:rate=25:duration=2,noise=alls=8:allf=t"; |
| 189 | 173 | 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"); | |
| 194 | 175 | compare_audio(&p, ar.parse().unwrap()); |
| 195 | 176 | // flip the audio source pack to 12-bit non-linear and compare again |
| 196 | 177 | 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 { | ||
| 67 | 67 | ($name:ident, $idx:expr) => { |
| 68 | 68 | #[test] |
| 69 | 69 | fn $name() { |
| 70 | - if !ffmpeg_or_skip() { | |
| 71 | - return; | |
| 72 | - } | |
| 73 | 70 | let f = &FLAVOURS[$idx]; |
| 74 | 71 | for (ilme, noise) in [(false, 0), (true, 6), (true, 25), (false, 40)] { |
| 75 | 72 | check_flavour(f, ilme, noise); |
| @@ -90,9 +87,6 @@ flavour_test!(hd_720p60, 8); | ||
| 90 | 87 | |
| 91 | 88 | #[test] |
| 92 | 89 | fn native_formats() { |
| 93 | - if !ffmpeg_or_skip() { | |
| 94 | - return; | |
| 95 | - } | |
| 96 | 90 | for (i, want) in [Chroma::Yuv411, Chroma::Yuv420, Chroma::Yuv411, Chroma::Yuv422, Chroma::Yuv422].into_iter().enumerate() { |
| 97 | 91 | let f = &FLAVOURS[i]; |
| 98 | 92 | let path = make(f, "fmt", "dv", false, 5).unwrap(); |
| @@ -187,9 +181,6 @@ fn check_mutated(f: &Flavour, mode: u32, seed: u64) { | ||
| 187 | 181 | |
| 188 | 182 | #[test] |
| 189 | 183 | fn mutated_streams_match_ffmpeg() { |
| 190 | - if !ffmpeg_or_skip() { | |
| 191 | - return; | |
| 192 | - } | |
| 193 | 184 | for f in FLAVOURS { |
| 194 | 185 | for mode in 0..5 { |
| 195 | 186 | for seed in [1u64, 2, 3] { |
crates/ec-dv/tests/perf.rsmodified+0 -3
| @@ -37,9 +37,6 @@ fn machine_is_busy() -> bool { | ||
| 37 | 37 | |
| 38 | 38 | #[test] |
| 39 | 39 | fn decode_speed() { |
| 40 | - if !ffmpeg_or_skip() { | |
| 41 | - return; | |
| 42 | - } | |
| 43 | 40 | let mut bad = Vec::new(); |
| 44 | 41 | for f in FLAVOURS { |
| 45 | 42 | 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 } | ||
| 11 | 11 | ec-image = { workspace = true } |
| 12 | 12 | |
| 13 | 13 | [dev-dependencies] |
| 14 | +ec-testkit.workspace = true | |
| 14 | 15 | ec-mp4 = { workspace = true } |
| 15 | 16 | ec-matroska = { workspace = true } |
crates/ec-mjpeg/tests/ffmpeg_parity.rsmodified+2 -46
| @@ -3,39 +3,16 @@ | ||
| 3 | 3 | //! |
| 4 | 4 | //! All sources are synthetic: lavfi test patterns encoded by ffmpeg, and the Pillow-made JPEGs in |
| 5 | 5 | //! `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. | |
| 7 | 7 | |
| 8 | 8 | use std::io::BufReader; |
| 9 | 9 | use std::path::{Path, PathBuf}; |
| 10 | -use std::process::Command; | |
| 11 | 10 | |
| 12 | 11 | use ec_core::frame::{Interlace, PixelFormat, VideoFrame}; |
| 13 | 12 | use ec_core::registry::{CodecId, CodecParameters, Demuxer, MediaParameters}; |
| 14 | 13 | use ec_image::Limits; |
| 15 | 14 | use ec_mjpeg::MjpegDecoder; |
| 16 | 15 | |
| 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 | - | |
| 39 | 16 | fn scratch(tag: &str) -> PathBuf { |
| 40 | 17 | let base = std::env::var_os("TMPDIR") |
| 41 | 18 | .map(PathBuf::from) |
| @@ -46,7 +23,7 @@ fn scratch(tag: &str) -> PathBuf { | ||
| 46 | 23 | } |
| 47 | 24 | |
| 48 | 25 | fn ffmpeg(args: &[&str]) { |
| 49 | - let ok = Command::new("ffmpeg") | |
| 26 | + let ok = ec_testkit::ffmpeg() | |
| 50 | 27 | .args(["-v", "error", "-y", "-nostdin"]) |
| 51 | 28 | .args(args) |
| 52 | 29 | .status() |
| @@ -155,9 +132,6 @@ fn format_name(f: PixelFormat) -> &'static str { | ||
| 155 | 132 | |
| 156 | 133 | #[test] |
| 157 | 134 | fn still_fixtures_match_ffmpeg() { |
| 158 | - if !oracle() { | |
| 159 | - return; | |
| 160 | - } | |
| 161 | 135 | let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data"); |
| 162 | 136 | let work = scratch("stills"); |
| 163 | 137 | let mut n = 0; |
| @@ -186,9 +160,6 @@ fn still_fixtures_match_ffmpeg() { | ||
| 186 | 160 | /// into mov and mkv by a stream copy. |
| 187 | 161 | #[test] |
| 188 | 162 | fn gray_video_matches_ffmpeg() { |
| 189 | - if !oracle() { | |
| 190 | - return; | |
| 191 | - } | |
| 192 | 163 | let work = scratch("gray"); |
| 193 | 164 | for name in ["basegray", "rstgray", "proggray"] { |
| 194 | 165 | let jpg = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!("tests/data/{name}.jpg")); |
| @@ -215,9 +186,6 @@ fn gray_video_matches_ffmpeg() { | ||
| 215 | 186 | |
| 216 | 187 | #[test] |
| 217 | 188 | fn video_matrix_matches_ffmpeg() { |
| 218 | - if !oracle() { | |
| 219 | - return; | |
| 220 | - } | |
| 221 | 189 | let work = scratch("matrix"); |
| 222 | 190 | let mut cases = 0; |
| 223 | 191 | for (pix, expect) in [ |
| @@ -372,9 +340,6 @@ fn write_avi(path: &Path, w: u32, h: u32, packets: &[Vec<u8>]) { | ||
| 372 | 340 | |
| 373 | 341 | #[test] |
| 374 | 342 | fn avi1_packets_without_dht_use_the_default_tables() { |
| 375 | - if !oracle() { | |
| 376 | - return; | |
| 377 | - } | |
| 378 | 343 | let work = scratch("nodht"); |
| 379 | 344 | for (pix, size) in [ |
| 380 | 345 | ("yuvj420p", "64x48"), |
| @@ -430,9 +395,6 @@ fn avi1_packets_without_dht_use_the_default_tables() { | ||
| 430 | 395 | |
| 431 | 396 | #[test] |
| 432 | 397 | fn two_field_packets_weave_like_ffmpeg() { |
| 433 | - if !oracle() { | |
| 434 | - return; | |
| 435 | - } | |
| 436 | 398 | let work = scratch("fields"); |
| 437 | 399 | // ffmpeg's mjpeg encoder refuses `-flags +ildct` ("interlacing not supported by codec"), |
| 438 | 400 | // 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>> { | ||
| 755 | 717 | |
| 756 | 718 | #[test] |
| 757 | 719 | fn mjpegb_matches_ffmpeg() { |
| 758 | - if !oracle() { | |
| 759 | - return; | |
| 760 | - } | |
| 761 | 720 | let work = scratch("mjpegb"); |
| 762 | 721 | // Progressive: one field per packet, all three layouts, odd sizes. |
| 763 | 722 | for (pix, size, w, h, q) in [ |
| @@ -805,9 +764,6 @@ fn mjpegb_matches_ffmpeg() { | ||
| 805 | 764 | |
| 806 | 765 | #[test] |
| 807 | 766 | fn mjpegb_two_fields_match_ffmpeg() { |
| 808 | - if !oracle() { | |
| 809 | - return; | |
| 810 | - } | |
| 811 | 767 | let work = scratch("mjpegb2"); |
| 812 | 768 | for (pix, size, w, h) in [ |
| 813 | 769 | ("yuvj420p", "64x48", 64u16, 48u16), |
crates/ec-mpeg2/Cargo.tomlmodified+3 -0
| @@ -8,3 +8,6 @@ authors.workspace = true | ||
| 8 | 8 | |
| 9 | 9 | [dependencies] |
| 10 | 10 | 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 @@ | ||
| 4 | 4 | pub mod synth; |
| 5 | 5 | |
| 6 | 6 | use std::path::{Path, PathBuf}; |
| 7 | -use std::process::Command; | |
| 8 | 7 | |
| 9 | 8 | use ec_core::frame::VideoFrame; |
| 10 | 9 | use ec_mpeg2::Mpeg2Decoder; |
| 11 | 10 | |
| 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 | 11 | pub fn scratch(tag: &str) -> PathBuf { |
| 25 | 12 | let base = std::env::var_os("TMPDIR") |
| 26 | 13 | .map(PathBuf::from) |
| @@ -31,7 +18,7 @@ pub fn scratch(tag: &str) -> PathBuf { | ||
| 31 | 18 | } |
| 32 | 19 | |
| 33 | 20 | pub fn run(args: &[&str]) -> bool { |
| 34 | - Command::new("ffmpeg") | |
| 21 | + ec_testkit::ffmpeg() | |
| 35 | 22 | .args(["-v", "error", "-y", "-nostdin"]) |
| 36 | 23 | .args(args) |
| 37 | 24 | .status() |
crates/ec-mpeg2/tests/ffmpeg_parity.rsmodified+1 -10
| @@ -65,22 +65,13 @@ fn generate(c: &Case) -> Option<std::path::PathBuf> { | ||
| 65 | 65 | |
| 66 | 66 | #[test] |
| 67 | 67 | fn parity_matrix() { |
| 68 | - if !have_ffmpeg() { | |
| 69 | - assert!(!require(), "ffmpeg missing"); | |
| 70 | - eprintln!("SKIP: no ffmpeg"); | |
| 71 | - return; | |
| 72 | - } | |
| 73 | 68 | let only = std::env::var("EC_MPEG2_CASE").ok(); |
| 74 | 69 | let mut failures = Vec::new(); |
| 75 | 70 | for c in CASES { |
| 76 | 71 | if only.as_deref().is_some_and(|o| o != c.tag) { |
| 77 | 72 | continue; |
| 78 | 73 | } |
| 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)); | |
| 84 | 75 | match compare(c.tag, &es, c.pix, &[]) { |
| 85 | 76 | Ok(n) => eprintln!("OK {} ({n} frames)", c.tag), |
| 86 | 77 | 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> { | ||
| 16 | 16 | |
| 17 | 17 | #[test] |
| 18 | 18 | fn synthetic_streams_match_ffmpeg() { |
| 19 | - if !have_ffmpeg() { | |
| 20 | - assert!(!require(), "ffmpeg missing"); | |
| 21 | - eprintln!("SKIP: no ffmpeg"); | |
| 22 | - return; | |
| 23 | - } | |
| 24 | 19 | let n: u64 = std::env::var("EC_SYNTH_N").ok().and_then(|v| v.parse().ok()).unwrap_or(24); |
| 25 | 20 | let base: u64 = std::env::var("EC_SYNTH_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(1); |
| 26 | 21 | 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 | ||
| 10 | 10 | ec-core = { workspace = true } |
| 11 | 11 | |
| 12 | 12 | [dev-dependencies] |
| 13 | +ec-testkit.workspace = true | |
| 13 | 14 | ec-mp4 = { workspace = true } |
| 14 | 15 | ec-riff = { workspace = true } |
| 15 | 16 | ec-matroska = { workspace = true } |
crates/ec-mpeg4/tests/common/mod.rsmodified+1 -40
| @@ -8,50 +8,11 @@ | ||
| 8 | 8 | #![allow(dead_code)] |
| 9 | 9 | |
| 10 | 10 | use std::path::{Path, PathBuf}; |
| 11 | -use std::process::Command; | |
| 12 | 11 | |
| 13 | 12 | use ec_core::frame::VideoFrame; |
| 14 | 13 | use ec_core::registry::{CodecId, CodecParameters}; |
| 15 | 14 | use ec_mpeg4::{Mpeg4Decoder, PictureInfo}; |
| 16 | 15 | |
| 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 | - | |
| 55 | 16 | pub fn scratch(tag: &str) -> PathBuf { |
| 56 | 17 | let base = std::env::var_os("TMPDIR") |
| 57 | 18 | .map(PathBuf::from) |
| @@ -62,7 +23,7 @@ pub fn scratch(tag: &str) -> PathBuf { | ||
| 62 | 23 | } |
| 63 | 24 | |
| 64 | 25 | pub fn run(args: &[&str]) -> bool { |
| 65 | - Command::new("ffmpeg") | |
| 26 | + ec_testkit::ffmpeg() | |
| 66 | 27 | .args(["-v", "error", "-y", "-nostdin"]) |
| 67 | 28 | .args(args) |
| 68 | 29 | .status() |
crates/ec-mpeg4/tests/containers.rsmodified+2 -23
| @@ -69,9 +69,6 @@ fn decode_registry(params: ec_core::registry::CodecParameters, pk: &[Packet]) -> | ||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | fn check(tag: &str, file: &str, enc: &[&str]) { |
| 72 | - if !gate() { | |
| 73 | - return; | |
| 74 | - } | |
| 75 | 72 | let dir = scratch(tag); |
| 76 | 73 | let path = dir.join(file); |
| 77 | 74 | assert!(encode("176x144", 30, enc, &path), "encode"); |
| @@ -179,9 +176,6 @@ fn mkv_asp() { | ||
| 179 | 176 | } |
| 180 | 177 | #[test] |
| 181 | 178 | fn gp3_h263() { |
| 182 | - if !gate() { | |
| 183 | - return; | |
| 184 | - } | |
| 185 | 179 | let dir = scratch("3gp"); |
| 186 | 180 | let path = dir.join("a.3gp"); |
| 187 | 181 | assert!(encode( |
| @@ -205,9 +199,6 @@ fn gp3_h263() { | ||
| 205 | 199 | /// where it was. |
| 206 | 200 | #[test] |
| 207 | 201 | fn packed_bitstream_matches_unpacked() { |
| 208 | - if !gate() { | |
| 209 | - return; | |
| 210 | - } | |
| 211 | 202 | let dir = scratch("packed"); |
| 212 | 203 | let path = dir.join("a.avi"); |
| 213 | 204 | assert!(encode( |
| @@ -246,12 +237,9 @@ fn packed_bitstream_matches_unpacked() { | ||
| 246 | 237 | |
| 247 | 238 | #[test] |
| 248 | 239 | fn data_partitioning_is_refused_by_name() { |
| 249 | - if !gate() { | |
| 250 | - return; | |
| 251 | - } | |
| 252 | 240 | let dir = scratch("dp"); |
| 253 | 241 | let path = dir.join("a.m4v"); |
| 254 | - if !encode( | |
| 242 | + assert!(encode( | |
| 255 | 243 | "176x144", |
| 256 | 244 | 4, |
| 257 | 245 | &[ |
| @@ -265,10 +253,7 @@ fn data_partitioning_is_refused_by_name() { | ||
| 265 | 253 | "m4v", |
| 266 | 254 | ], |
| 267 | 255 | &path, |
| 268 | - ) { | |
| 269 | - eprintln!("SKIP: encoder rejects data partitioning"); | |
| 270 | - return; | |
| 271 | - } | |
| 256 | + ), "encoder rejects data partitioning"); | |
| 272 | 257 | let es = std::fs::read(&path).unwrap(); |
| 273 | 258 | let mut dec = new_decoder(); |
| 274 | 259 | let mut err = None; |
| @@ -288,9 +273,6 @@ fn data_partitioning_is_refused_by_name() { | ||
| 288 | 273 | |
| 289 | 274 | #[test] |
| 290 | 275 | fn corrupt_input_does_not_panic() { |
| 291 | - if !gate() { | |
| 292 | - return; | |
| 293 | - } | |
| 294 | 276 | let dir = scratch("corrupt"); |
| 295 | 277 | let path = dir.join("a.m4v"); |
| 296 | 278 | assert!(encode( |
| @@ -349,9 +331,6 @@ fn corrupt_input_does_not_panic() { | ||
| 349 | 331 | #[test] |
| 350 | 332 | #[ignore] |
| 351 | 333 | fn speed_720p_at_least_120_fps() { |
| 352 | - if !gate() { | |
| 353 | - return; | |
| 354 | - } | |
| 355 | 334 | let dir = scratch("speed"); |
| 356 | 335 | let path = dir.join("hd.m4v"); |
| 357 | 336 | assert!(encode( |
crates/ec-mpeg4/tests/ffmpeg_parity.rsmodified+1 -21
| @@ -1,6 +1,5 @@ | ||
| 1 | 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. | |
| 2 | +//! time (`ffmpeg -c:v mpeg4`, `libxvid`, `h263`). | |
| 4 | 3 | |
| 5 | 4 | mod common; |
| 6 | 5 | |
| @@ -10,9 +9,6 @@ macro_rules! parity { | ||
| 10 | 9 | ($name:ident, $size:expr, $frames:expr, [$($arg:expr),* $(,)?]) => { |
| 11 | 10 | #[test] |
| 12 | 11 | fn $name() { |
| 13 | - if !gate() { | |
| 14 | - return; | |
| 15 | - } | |
| 16 | 12 | let n = parity_es(stringify!($name), $size, $frames, &[$($arg),*], "m4v").unwrap(); |
| 17 | 13 | assert!(n >= $frames - 2, "decoded only {n} of {} pictures", $frames); |
| 18 | 14 | } |
| @@ -295,9 +291,6 @@ parity!( | ||
| 295 | 291 | |
| 296 | 292 | #[test] |
| 297 | 293 | fn hd_720p_with_everything() { |
| 298 | - if !gate() { | |
| 299 | - return; | |
| 300 | - } | |
| 301 | 294 | let n = parity_es( |
| 302 | 295 | "hd720", |
| 303 | 296 | "1280x720", |
| @@ -321,9 +314,6 @@ fn hd_720p_with_everything() { | ||
| 321 | 314 | // H.263 baseline (short video header). |
| 322 | 315 | #[test] |
| 323 | 316 | fn h263_formats() { |
| 324 | - if !gate() { | |
| 325 | - return; | |
| 326 | - } | |
| 327 | 317 | for (size, q, gop) in [ |
| 328 | 318 | ("128x96", "4", "8"), |
| 329 | 319 | ("176x144", "4", "10"), |
| @@ -346,9 +336,6 @@ fn h263_formats() { | ||
| 346 | 336 | |
| 347 | 337 | #[test] |
| 348 | 338 | fn h263_with_gob_headers() { |
| 349 | - if !gate() { | |
| 350 | - return; | |
| 351 | - } | |
| 352 | 339 | // `-ps` makes ffmpeg's H.263 encoder start a GOB (with its header) every n macroblocks. |
| 353 | 340 | let n = parity_es( |
| 354 | 341 | "h263_gob", |
| @@ -363,13 +350,6 @@ fn h263_with_gob_headers() { | ||
| 363 | 350 | |
| 364 | 351 | // libxvid: GMC with warp points, N-VOPs, the XviD IDCT and XviD's qpel/bframe habits. |
| 365 | 352 | 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 | - } | |
| 373 | 353 | let mut enc = vec!["-c:v", "libxvid"]; |
| 374 | 354 | enc.extend_from_slice(extra); |
| 375 | 355 | 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; | ||
| 12 | 12 | |
| 13 | 13 | #[allow(clippy::too_many_arguments)] |
| 14 | 14 | 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 | - } | |
| 23 | 15 | let dir = scratch(tag); |
| 24 | 16 | let path = dir.join(format!("{tag}.avi")); |
| 25 | 17 | let input = format!("{lavfi}=size={size}:rate=25"); |
crates/ec-prores/Cargo.tomlmodified+1 -0
| @@ -13,4 +13,5 @@ bytemuck = "1" | ||
| 13 | 13 | wide = { workspace = true } |
| 14 | 14 | |
| 15 | 15 | [dev-dependencies] |
| 16 | +ec-testkit.workspace = true | |
| 16 | 17 | ec-mp4 = { workspace = true } |
crates/ec-prores/tests/common/mod.rsmodified+1 -24
| @@ -3,34 +3,11 @@ | ||
| 3 | 3 | |
| 4 | 4 | use std::io::Cursor; |
| 5 | 5 | use std::path::PathBuf; |
| 6 | -use std::process::Command; | |
| 7 | 6 | |
| 8 | 7 | use ec_core::registry::{CodecId, CodecParameters, Demuxer}; |
| 9 | 8 | use ec_mp4::Mp4Demuxer; |
| 10 | 9 | use ec_prores::{DecodedFrame, ProResDecoder}; |
| 11 | 10 | |
| 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 | - | |
| 34 | 11 | pub fn scratch(tag: &str) -> PathBuf { |
| 35 | 12 | let base = std::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(std::env::temp_dir); |
| 36 | 13 | let dir = base.join(format!("ec-prores-{}-{}", std::process::id(), tag)); |
| @@ -39,7 +16,7 @@ pub fn scratch(tag: &str) -> PathBuf { | ||
| 39 | 16 | } |
| 40 | 17 | |
| 41 | 18 | pub fn run(args: &[&str]) -> bool { |
| 42 | - Command::new("ffmpeg") | |
| 19 | + ec_testkit::ffmpeg() | |
| 43 | 20 | .args(["-v", "error", "-y", "-nostdin"]) |
| 44 | 21 | .args(args) |
| 45 | 22 | .status() |
crates/ec-prores/tests/encode.rsmodified+4 -27
| @@ -1,11 +1,9 @@ | ||
| 1 | 1 | //! The ProRes encoder: ffmpeg decodes what we write exactly as ec-prores does, frame sizes sit on |
| 2 | 2 | //! 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. | |
| 5 | 4 | |
| 6 | 5 | mod common; |
| 7 | 6 | use std::io::Cursor; |
| 8 | -use std::process::Command; | |
| 9 | 7 | |
| 10 | 8 | use common::*; |
| 11 | 9 | use ec_core::frame::{ColorInfo, PixelFormat, Plane, VideoFrame}; |
| @@ -135,9 +133,6 @@ fn pix(p: Profile) -> &'static str { | ||
| 135 | 133 | |
| 136 | 134 | #[test] |
| 137 | 135 | fn ffmpeg_and_ec_prores_decode_every_profile_identically() { |
| 138 | - if !ffmpeg_or_skip() { | |
| 139 | - return; | |
| 140 | - } | |
| 141 | 136 | let dir = scratch("enc-rt"); |
| 142 | 137 | for (i, p) in ALL.into_iter().enumerate() { |
| 143 | 138 | // Odd size: padding macroblocks on both axes, 3 slice widths in a row. |
| @@ -223,9 +218,6 @@ fn frame_sizes_sit_on_apples_rates() { | ||
| 223 | 218 | |
| 224 | 219 | #[test] |
| 225 | 220 | fn encoder_trait_and_mov_probe() { |
| 226 | - if !ffmpeg_or_skip() { | |
| 227 | - return; | |
| 228 | - } | |
| 229 | 221 | let dir = scratch("enc-probe"); |
| 230 | 222 | let (w, h) = (192, 108); |
| 231 | 223 | for p in ALL { |
| @@ -249,7 +241,7 @@ fn encoder_trait_and_mov_probe() { | ||
| 249 | 241 | assert!(!mov.windows(4).any(|x| x == b"avcC" || x == b"esds"), "{p:?}: a config box"); |
| 250 | 242 | let path = dir.join(format!("{}.mov", String::from_utf8_lossy(&p.fourcc()))); |
| 251 | 243 | std::fs::write(&path, &mov).unwrap(); |
| 252 | - let out = Command::new("ffprobe") | |
| 244 | + let out = ec_testkit::ffprobe() | |
| 253 | 245 | .args(["-v", "error", "-select_streams", "v:0", "-show_entries"]) |
| 254 | 246 | .arg("stream=codec_name,profile,pix_fmt,field_order,color_space,color_transfer,color_primaries,codec_tag_string,width,height,nb_frames") |
| 255 | 247 | .args(["-of", "default=nw=1"]) |
| @@ -336,25 +328,16 @@ fn psnr_vs_prores_ks(generator: &str, post: &str, tag: &str) { | ||
| 336 | 328 | |
| 337 | 329 | #[test] |
| 338 | 330 | fn quality_matches_prores_ks_testsrc2() { |
| 339 | - if !ffmpeg_or_skip() { | |
| 340 | - return; | |
| 341 | - } | |
| 342 | 331 | psnr_vs_prores_ks("testsrc2", "", "q-testsrc2"); |
| 343 | 332 | } |
| 344 | 333 | |
| 345 | 334 | #[test] |
| 346 | 335 | fn quality_matches_prores_ks_mandelbrot() { |
| 347 | - if !ffmpeg_or_skip() { | |
| 348 | - return; | |
| 349 | - } | |
| 350 | 336 | psnr_vs_prores_ks("mandelbrot", "", "q-mandel"); |
| 351 | 337 | } |
| 352 | 338 | |
| 353 | 339 | #[test] |
| 354 | 340 | fn quality_matches_prores_ks_noisy() { |
| 355 | - if !ffmpeg_or_skip() { | |
| 356 | - return; | |
| 357 | - } | |
| 358 | 341 | psnr_vs_prores_ks("testsrc2", ",noise=alls=12:allf=t", "q-noisy"); |
| 359 | 342 | } |
| 360 | 343 | |
| @@ -404,7 +387,7 @@ fn encode_speed_1080p_hq() { | ||
| 404 | 387 | } |
| 405 | 388 | |
| 406 | 389 | fn probe(path: &std::path::Path, entry: &str) -> String { |
| 407 | - let out = Command::new("ffprobe") | |
| 390 | + let out = ec_testkit::ffprobe() | |
| 408 | 391 | .args(["-v", "error", "-select_streams", "v:0", "-show_entries", &format!("stream={entry}"), "-of", "default=nw=1:nk=1"]) |
| 409 | 392 | .arg(path) |
| 410 | 393 | .output() |
| @@ -413,7 +396,7 @@ fn probe(path: &std::path::Path, entry: &str) -> String { | ||
| 413 | 396 | } |
| 414 | 397 | |
| 415 | 398 | fn probe_frame(path: &std::path::Path, entry: &str) -> String { |
| 416 | - let out = Command::new("ffprobe") | |
| 399 | + let out = ec_testkit::ffprobe() | |
| 417 | 400 | .args(["-v", "error", "-select_streams", "v:0", "-show_frames", "-read_intervals", "%+#1", "-show_entries", &format!("frame={entry}"), "-of", "default=nw=1:nk=1"]) |
| 418 | 401 | .arg(path) |
| 419 | 402 | .output() |
| @@ -424,9 +407,6 @@ fn probe_frame(path: &std::path::Path, entry: &str) -> String { | ||
| 424 | 407 | #[test] |
| 425 | 408 | fn interlaced_every_profile_ffmpeg_and_ours_agree() { |
| 426 | 409 | use ec_core::frame::Interlace; |
| 427 | - if !ffmpeg_or_skip() { | |
| 428 | - return; | |
| 429 | - } | |
| 430 | 410 | let dir = scratch("enc-field"); |
| 431 | 411 | for (i, p) in ALL.into_iter().enumerate() { |
| 432 | 412 | 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> { | ||
| 508 | 488 | fn alpha_4444_round_trips_and_ffmpeg_agrees() { |
| 509 | 489 | use ec_core::frame::Interlace; |
| 510 | 490 | use ec_prores::AlphaPlane; |
| 511 | - if !ffmpeg_or_skip() { | |
| 512 | - return; | |
| 513 | - } | |
| 514 | 491 | let dir = scratch("enc-alpha"); |
| 515 | 492 | let mut n = 0; |
| 516 | 493 | 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 { | ||
| 112 | 112 | |
| 113 | 113 | #[test] |
| 114 | 114 | fn matches_ffmpeg() { |
| 115 | - if !ffmpeg_or_skip() { | |
| 116 | - return; | |
| 117 | - } | |
| 118 | 115 | let mut bad = Vec::new(); |
| 119 | 116 | for c in CASES { |
| 120 | 117 | let mov = generate(c); |
crates/ec-prores/tests/perf.rsmodified+0 -3
| @@ -6,9 +6,6 @@ use common::*; | ||
| 6 | 6 | |
| 7 | 7 | #[test] |
| 8 | 8 | fn hd_hq_throughput() { |
| 9 | - if !ffmpeg_or_skip() { | |
| 10 | - return; | |
| 11 | - } | |
| 12 | 9 | let dir = scratch("perf"); |
| 13 | 10 | let mov = dir.join("hd.mov"); |
| 14 | 11 | assert!(run(&[ |
crates/ec-prores/tests/robust.rsmodified+8 -11
| @@ -19,15 +19,12 @@ impl Rng { | ||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /// 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(); | |
| 24 | 24 | CACHE.get_or_init(make_frames).clone() |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -fn make_frames() -> Option<Vec<Vec<u8>>> { | |
| 28 | - if !ffmpeg_or_skip() { | |
| 29 | - return None; | |
| 30 | - } | |
| 27 | +fn make_frames() -> Vec<Vec<u8>> { | |
| 31 | 28 | let dir = scratch("robust"); |
| 32 | 29 | let mut out = Vec::new(); |
| 33 | 30 | for (i, (prof, fmt, extra)) in [ |
| @@ -51,12 +48,12 @@ fn make_frames() -> Option<Vec<Vec<u8>>> { | ||
| 51 | 48 | out.push(packets(&std::fs::read(&mov).unwrap()).remove(0)); |
| 52 | 49 | } |
| 53 | 50 | let _ = std::fs::remove_dir_all(dir); |
| 54 | - Some(out) | |
| 51 | + out | |
| 55 | 52 | } |
| 56 | 53 | |
| 57 | 54 | #[test] |
| 58 | 55 | fn truncations_never_panic() { |
| 59 | - let Some(fs) = frames() else { return }; | |
| 56 | + let fs = frames(); | |
| 60 | 57 | for f in &fs { |
| 61 | 58 | let mut d = decoder(2); |
| 62 | 59 | assert!(d.decode(f).is_ok()); |
| @@ -68,7 +65,7 @@ fn truncations_never_panic() { | ||
| 68 | 65 | |
| 69 | 66 | #[test] |
| 70 | 67 | fn corruptions_never_panic() { |
| 71 | - let Some(fs) = frames() else { return }; | |
| 68 | + let fs = frames(); | |
| 72 | 69 | let mut rng = Rng(0x9E3779B97F4A7C15); |
| 73 | 70 | for f in &fs { |
| 74 | 71 | let mut d = decoder(3); |
| @@ -105,7 +102,7 @@ fn garbage_is_refused_by_name() { | ||
| 105 | 102 | |
| 106 | 103 | #[test] |
| 107 | 104 | fn hostile_dimensions_are_bounded() { |
| 108 | - let Some(fs) = frames() else { return }; | |
| 105 | + let fs = frames(); | |
| 109 | 106 | let mut g = fs[0].clone(); |
| 110 | 107 | // width/height at frame-header bytes 8..12 (after size+icpf: offset 8+8). |
| 111 | 108 | g[16..20].copy_from_slice(&[0xFF, 0xFF, 0xFF, 0xFF]); |
| @@ -131,7 +128,7 @@ fn wrong_codec_is_unsupported() { | ||
| 131 | 128 | fn dump_seeds() { |
| 132 | 129 | let dir = std::env::var("EC_SEED_DIR").expect("EC_SEED_DIR"); |
| 133 | 130 | std::fs::create_dir_all(&dir).unwrap(); |
| 134 | - let Some(fs) = frames() else { return }; | |
| 131 | + let fs = frames(); | |
| 135 | 132 | for (i, f) in fs.iter().enumerate() { |
| 136 | 133 | std::fs::write(format!("{dir}/seed{i}.bin"), f).unwrap(); |
| 137 | 134 | } |