From a57f393d974be3c865ea20b20139f6cc4721b95a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 03:21:19 -0800 Subject: [PATCH] craft-video: the ffmpeg MJPEG round-trip test encodes the same picture every run we_decode_what_ffmpeg_encodes_to_what_ffmpeg_decodes built its input with ffmpeg's gradients source, which picks random colors on every run, so the agreement it measured changed from run to run. On one CI run the 4:2:0 case scored 30.5 dB against the 38 dB floor. The test now writes the file's own picture(67, 41, 3) as raw RGB and feeds it to ffmpeg through rawvideo, for both the plain and the default-tables encodes. --- crates/video/tests/mjpeg.rs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/crates/video/tests/mjpeg.rs b/crates/video/tests/mjpeg.rs index d83b61438..fcd9cacd6 100644 --- a/crates/video/tests/mjpeg.rs +++ b/crates/video/tests/mjpeg.rs @@ -150,12 +150,14 @@ fn we_decode_what_ffmpeg_encodes_to_what_ffmpeg_decodes() { let Some(ff) = craft_media_testkit::ffmpeg() else { return }; let dir = craft_media_testkit::fixture_subdir("mjpeg"); let s = |p: &Path| p.to_str().expect("path").to_string(); + // the same input every run: ffmpeg's own test sources draw random colors + let input = dir.join("input.rgb"); + std::fs::write(&input, picture(67, 41, 3)).expect("write"); + let input = s(&input); + let source = ["-f", "rawvideo", "-pix_fmt", "rgb24", "-s", "67x41", "-i", input.as_str()]; for (name, pix_fmt, rgb_pix, channels) in [("420", "yuvj420p", "rgb24", 3), ("422", "yuvj422p", "rgb24", 3), ("444", "yuvj444p", "rgb24", 3)] { let jpg = dir.join(format!("{name}.jpg")); - ffmpeg( - &ff, - &["-f", "lavfi", "-i", "gradients=size=67x41:rate=1", "-frames:v", "1", "-c:v", "mjpeg", "-pix_fmt", pix_fmt, "-q:v", "2", &s(&jpg)], - ); + ffmpeg(&ff, &[&source[..], &["-frames:v", "1", "-c:v", "mjpeg", "-pix_fmt", pix_fmt, "-q:v", "2", &s(&jpg)]].concat()); let reference = dir.join(format!("{name}.raw")); ffmpeg(&ff, &["-i", &s(&jpg), "-f", "rawvideo", "-pix_fmt", rgb_pix, &s(&reference)]); let packet = std::fs::read(&jpg).expect("read"); @@ -170,23 +172,7 @@ fn we_decode_what_ffmpeg_encodes_to_what_ffmpeg_decodes() { let plain = dir.join(format!("{name}_default_tables.jpg")); ffmpeg( &ff, - &[ - "-f", - "lavfi", - "-i", - "gradients=size=67x41:rate=1", - "-frames:v", - "1", - "-c:v", - "mjpeg", - "-pix_fmt", - pix_fmt, - "-q:v", - "2", - "-huffman", - "default", - &s(&plain), - ], + &[&source[..], &["-frames:v", "1", "-c:v", "mjpeg", "-pix_fmt", pix_fmt, "-q:v", "2", "-huffman", "default", &s(&plain)]].concat(), ); let stripped = without_huffman_tables(&std::fs::read(&plain).expect("read")); let with_tables = Decoder::new().decode(&std::fs::read(&plain).expect("read")).expect("decode");