From a5aa64ea0d1c1bcff5c6cc6335f29dcdea729dd0 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 00:17:36 +0300 Subject: [PATCH] docs(h264): name and sweep the search's motion-vector weight The motion search halved a vector's signalling cost with a bare `/ 2.0`. Swept on consecutive pictures it holds: 0.25/0.5/1.0/2.0 read -1.074/-1.043/-1.225/ -1.618 dB BD-PSNR against x264 on the film clip and -0.676/-0.661/-0.795/-1.201 on the screen capture, so a half is the flat part and charging the whole rate is worse on both contents. --- crates/ec-h264/src/enc/mb.rs | 10 +++++++++- lanes/h264x264-r2.report.md | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ec-h264/src/enc/mb.rs b/crates/ec-h264/src/enc/mb.rs index 7c97cc62..d5625f99 100644 --- a/crates/ec-h264/src/enc/mb.rs +++ b/crates/ec-h264/src/enc/mb.rs @@ -469,6 +469,14 @@ fn intra_pre_cost( } } +/// How much of a motion vector's signalling the search pays for. Half, which +/// is not the true rate: swept on consecutive pictures (BD-PSNR against x264, +/// GOP 10), 0.25/0.5/1.0/2.0 read -1.074/-1.043/-1.225/-1.618 on the film clip +/// and -0.676/-0.661/-0.795/-1.201 on the screen capture. Charging the whole +/// rate is worse than charging half on both contents, and the curve is flat +/// below a half and falls away above it. +const MV_BITS_WEIGHT: f64 = 0.5; + /// What going intra costs to signal in a P picture, in bits: the macroblock /// type and, when Intra_4x4 wins later, sixteen prediction modes. Swept at the /// decision site above. @@ -581,7 +589,7 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter let bits = motion_rate( e, f64::from(se_bits(i32::from(mv[0] - mvp[0])) + se_bits(i32::from(mv[1] - mvp[1]))) - / 2.0, + * MV_BITS_WEIGHT, ); if !satd && mv[0] & 3 == 0 && mv[1] & 3 == 0 { let o = integer_origin( diff --git a/lanes/h264x264-r2.report.md b/lanes/h264x264-r2.report.md index 5b661975..83a152f2 100644 --- a/lanes/h264x264-r2.report.md +++ b/lanes/h264x264-r2.report.md @@ -140,3 +140,9 @@ Iterating our own sub-sample refinement to convergence at `Fast` (it stopped after one pass) is the first 0.111 dB of that, for 2% of the comparison's wall clock: film -1.154 -> -1.043, screen capture -0.696 -> -0.661, synthetic -4.542 -> -4.449. + +The search's motion-vector weight was swept with it and held at a half: +0.25/0.5/1.0/2.0 read -1.074/-1.043/-1.225/-1.618 on film and +-0.676/-0.661/-0.795/-1.201 on screen capture. Charging a vector's whole +signalling cost is worse than charging half on both contents; it now says so in +a named constant rather than a bare `/ 2.0`.