forge
Explore
Log in

Don't you dare go Hollow

Report chroma per plane, and stop dropping the first x264 param

Browse files at this commit

8adad232839ba07c43c488e228fb3d9816981be5Ahmet Kaan GümüşParent: 49e08f5
  • test
    • report chroma per plane, and stop dropping the first x264 param
Show full message
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.rsmodified+39 -1
@@ -980,7 +980,13 @@ fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) ->
980 &format!(980 &format!(
981 "scenecut=0:aq-mode=0:psy=0:8x8dct=0:ipratio=1.0:pbratio=1.0:qcomp=1.0:chroma-qp-offset=0{}",981 "scenecut=0:aq-mode=0:psy=0:8x8dct=0:ipratio=1.0:pbratio=1.0:qcomp=1.0:chroma-qp-offset=0{}",
982 match std::env::var("EC_H264_X264_PARAMS") {982 match std::env::var("EC_H264_X264_PARAMS") {
983- Ok(extra) if !extra.trim().is_empty() => format!(":{}", extra.trim()),983+ // The value may or may not carry its own leading colon;
984+ // both spell the same thing. Passing it through would not:
985+ // ffmpeg drops the token after an empty one, so "::subme=1"
986+ // silently encodes at the preset's subme and the sweep
987+ // reads as "the feature does nothing".
988+ Ok(extra) if !extra.trim().trim_matches(':').is_empty() =>
989+ format!(":{}", extra.trim().trim_matches(':')),
984 _ => String::new(),990 _ => String::new(),
985 }991 }
986 ),992 ),
@@ -1088,6 +1094,23 @@ fn bd_psnr_vs_x264() {
1088 .zip(&decoded)1094 .zip(&decoded)
1089 .map(|(s, d)| psnr_yuv(s, d))1095 .map(|(s, d)| psnr_yuv(s, d))
1090 .sum();1096 .sum();
1097+ let (sum_u, sum_v) = (
1098+ sources
1099+ .iter()
1100+ .zip(&decoded)
1101+ .map(|(s, d)| psnr(&s.1, &d.1))
1102+ .sum::<f64>(),
1103+ sources
1104+ .iter()
1105+ .zip(&decoded)
1106+ .map(|(s, d)| psnr(&s.2, &d.2))
1107+ .sum::<f64>(),
1108+ );
1109+ eprintln!(
1110+ " ours qp {qp}: u {:.2} dB v {:.2} dB",
1111+ sum_u / sources.len() as f64,
1112+ sum_v / sources.len() as f64
1113+ );
1091 let (decoded_psnr, recon_psnr) =1114 let (decoded_psnr, recon_psnr) =
1092 (sum / sources.len() as f64, sum_recon / sources.len() as f64);1115 (sum / sources.len() as f64, sum_recon / sources.len() as f64);
1093 assert!(1116 assert!(
@@ -1122,6 +1145,21 @@ fn bd_psnr_vs_x264() {
1122 .map(|(s, d)| psnr_yuv(s, d))1145 .map(|(s, d)| psnr_yuv(s, d))
1123 .sum();1146 .sum();
1124 let n = sources.len() as f64;1147 let n = sources.len() as f64;
1148+ eprintln!(
1149+ " x264 qp {qp}: u {:.2} dB v {:.2} dB",
1150+ sources
1151+ .iter()
1152+ .zip(&decoded)
1153+ .map(|(s, d)| psnr(&s.1, &d.1))
1154+ .sum::<f64>()
1155+ / n,
1156+ sources
1157+ .iter()
1158+ .zip(&decoded)
1159+ .map(|(s, d)| psnr(&s.2, &d.2))
1160+ .sum::<f64>()
1161+ / n
1162+ );
1125 ((stream.len() * 8) as f64, sum / n, sum_yuv / n)1163 ((stream.len() * 8) as f64, sum / n, sum_yuv / n)
1126 };1164 };
1127 1165