From 8adad232839ba07c43c488e228fb3d9816981be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 24 Aug 2026 05:23:13 +0300 Subject: [PATCH] test(h264): report chroma per plane, and stop dropping the first x264 param The gate compared two encoders on a pooled all-plane number without ever saying which plane either one was losing. Print U and V separately per QP for both sides; on the film clip they say our chroma trails x264 by 0.48-0.90 dB uniformly across QP while we spend more bits, which is a prediction deficit rather than a starved one. EC_H264_X264_PARAMS was spliced in with a colon of its own, so a value written with a leading colon produced "::subme=1" -- and ffmpeg drops the token that follows an empty one. The parameter silently did not apply and the sweep read as "this x264 feature is worth nothing". Trim the colons off the value instead. Corrected attribution of x264's lead on the film clip, as BD-PSNR-YUV: its RD mode decision is worth 0.739 dB, its trellis quantisation 0.206, and the two are additive -- with both stripped we lead by 0.278 dB. --- crates/ec-h264/tests/encode.rs | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/ec-h264/tests/encode.rs b/crates/ec-h264/tests/encode.rs index 85a58884..457a3f88 100644 --- a/crates/ec-h264/tests/encode.rs +++ b/crates/ec-h264/tests/encode.rs @@ -980,7 +980,13 @@ fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) -> &format!( "scenecut=0:aq-mode=0:psy=0:8x8dct=0:ipratio=1.0:pbratio=1.0:qcomp=1.0:chroma-qp-offset=0{}", match std::env::var("EC_H264_X264_PARAMS") { - Ok(extra) if !extra.trim().is_empty() => format!(":{}", extra.trim()), + // The value may or may not carry its own leading colon; + // both spell the same thing. Passing it through would not: + // ffmpeg drops the token after an empty one, so "::subme=1" + // silently encodes at the preset's subme and the sweep + // reads as "the feature does nothing". + Ok(extra) if !extra.trim().trim_matches(':').is_empty() => + format!(":{}", extra.trim().trim_matches(':')), _ => String::new(), } ), @@ -1088,6 +1094,23 @@ fn bd_psnr_vs_x264() { .zip(&decoded) .map(|(s, d)| psnr_yuv(s, d)) .sum(); + let (sum_u, sum_v) = ( + sources + .iter() + .zip(&decoded) + .map(|(s, d)| psnr(&s.1, &d.1)) + .sum::(), + sources + .iter() + .zip(&decoded) + .map(|(s, d)| psnr(&s.2, &d.2)) + .sum::(), + ); + eprintln!( + " ours qp {qp}: u {:.2} dB v {:.2} dB", + sum_u / sources.len() as f64, + sum_v / sources.len() as f64 + ); let (decoded_psnr, recon_psnr) = (sum / sources.len() as f64, sum_recon / sources.len() as f64); assert!( @@ -1122,6 +1145,21 @@ fn bd_psnr_vs_x264() { .map(|(s, d)| psnr_yuv(s, d)) .sum(); let n = sources.len() as f64; + eprintln!( + " x264 qp {qp}: u {:.2} dB v {:.2} dB", + sources + .iter() + .zip(&decoded) + .map(|(s, d)| psnr(&s.1, &d.1)) + .sum::() + / n, + sources + .iter() + .zip(&decoded) + .map(|(s, d)| psnr(&s.2, &d.2)) + .sum::() + / n + ); ((stream.len() * 8) as f64, sum / n, sum_yuv / n) };