From cdf385826b075f40d294a0fc955e99623976f4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 04:52:39 +0300 Subject: [PATCH] test(av1): exercise the 16x16 straddle-leaf inter path on real content real_clip_encodes_within_its_quality_and_size_budget uses 640x384 (both axes 32-aligned), so Quadrant::Split never fires and the e19bb47 NEARESTMV leaf path was untouched by real, mixed intra/inter content. Add a sibling at 704x400 (400 mod 32 == 16, the exactly-half straddle class), same three gates: dav1d decodes every frame, mean luma PSNR floor, byte ceiling. --- crates/ec-av1/src/encode.rs | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index ac37c3d2..1c8f31ed 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -4420,6 +4420,68 @@ mod tests { ); } + /// Sibling of `real_clip_encodes_within_its_quality_and_size_budget` at a + /// straddle size: 640x384 is exact on both axes (32-aligned), so + /// `Quadrant::Split` never fires there and the 16x16 `NEARESTMV` leaf + /// path landed in e19bb47 goes unexercised by real, mixed intra/inter + /// content. 704x400 has 400 mod 32 == 16 -- the same "exactly half + /// straddle" class as `a_sequence_round_trips_at_the_exactly_half_ + /// straddle_size`'s 1280x720, but that test is a synthetic panned test + /// card; this one is the real-clip gate, same three floors. + /// + /// Measured 2026-08-27 at q=100, 8 frames: stream 54525 bytes, average + /// luma PSNR 45.48 dB across the 8 decoded frames vs the source. + /// Floor/ceiling below carry the same margin as the sibling test (PSNR + /// floor = measured - 0.5 dB; byte ceiling = measured * 1.15). + #[test] + fn real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size() { + if !have_ffmpeg() { + eprintln!( + "SKIP real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size: \ + no ffmpeg" + ); + return; + } + let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4"); + if !clip.exists() { + eprintln!( + "SKIP real_clip_encodes_within_its_quality_and_size_budget_at_a_straddle_size: \ + {} missing", + clip.display() + ); + return; + } + let (width, height, frame_count) = (704usize, 400usize, 8usize); + let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count); + let encoded = encode_sequence(&source, 100, 0.5).unwrap(); + assert_eq!(encoded.frames.len(), frame_count); + + // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole + // stream and hands back every frame. + let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frame_count); + assert_eq!(decoded.len(), frame_count, "dav1d decoded every frame"); + + // Gate 2: quality vs the source did not silently collapse. + let mean_psnr: f64 = decoded + .iter() + .zip(&source) + .map(|(d, s)| psnr(&d.y, &s.y)) + .sum::() + / frame_count as f64; + assert!( + mean_psnr >= 44.98, + "mean luma PSNR {mean_psnr:.2} dB fell below the 44.98 dB floor" + ); + + // Gate 3: the stream did not silently bloat. + assert!( + encoded.stream.len() <= 62_703, + "stream grew to {} bytes, over the 62703-byte ceiling", + encoded.stream.len() + ); + } + /// The replica-shaped path: 24 frames, 1280x720, one key frame followed /// by inter frames -- the same GOP shape [`encode_sequence`] gives the /// facade -- timed end to end, so the edith export-time projection is a