From 59483b88cedbfc050ba9efe4bc970025b86d7c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 23 Aug 2026 18:08:25 +0300 Subject: [PATCH] docs(lanes): h264-vs-x264 rank-1 lane report --- lanes/h264x264-r1.report.md | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 lanes/h264x264-r1.report.md diff --git a/lanes/h264x264-r1.report.md b/lanes/h264x264-r1.report.md new file mode 100644 index 00000000..9c896b8c --- /dev/null +++ b/lanes/h264x264-r1.report.md @@ -0,0 +1,76 @@ +# lane h264x264-r1 — first rate-quality reference for ec-h264 + +Rank 1 of `lanes/survey-r1.report.md` ("ec-h264 has no rate-quality reference at all"). +Closed 2026-08-23. Commits `1dee93e`, `aa1cd35`, `d994e4c`, `7252dbe` on `main`. + +## What landed + +`bd_psnr_vs_x264` in `crates/ec-h264/tests/encode.rs` — a run-by-default gate (skips loudly, +with the exact runnable command, when ffmpeg/libx264 is absent). It encodes the same pictures +at QP 22/26/30/34 with both encoders under matched features, decodes our own stream with +ffmpeg to prove our reported PSNR is the stream's and not just our reconstruction's +(`|recon - decoded| < 0.05 dB`), and reports BD-PSNR. Default source is a synthetic clip; +`EC_H264_CLIP=` sweeps a real one, `EC_H264_GOP` and `EC_H264_PRESET_BALANCED` vary +the configuration. + +## Two instrument defects found before any number was trusted + +1. **x264's `-qp` is not constant QP.** `ipratio` (1.4) and `pbratio` scale the I/B quantiser + off the requested value; `qcomp`, `aq-mode`, `psy`, `chroma-qp-offset` perturb it further. + All-intra diagnosis: x264 read +37% bits at +4.5 dB — a different quantiser reading as a + rate-quality win. Pinned with + `scenecut=0:aq-mode=0:psy=0:8x8dct=0:ipratio=1.0:pbratio=1.0:qcomp=1.0:chroma-qp-offset=0`. +2. **A noisy synthetic source measures residual abandonment, not coding gain.** On an + incompressible noise field x264 spent 224k bits at QP 30 where we spent 672k and landed + 0.5 dB *below* us, yet scored a large BD win. The tell was `Preset::Balanced` scoring + *worse* than `Preset::Fast` there while scoring far better on real content. Replaced with + `Clip::render_smooth`. + +Both are recorded as a class in memory (`x264-cqp-and-noise-gates`): an encoder-vs-reference +gate must first prove the two encoders sit at the same operating point. + +## Where the gap was + +3840x1608 clip from the library, 24 pictures 1 s apart, GOP 10, matched features: + +| configuration | BD-PSNR vs x264 | encode time | +|---|---|---| +| `Preset::Fast` (baseline) | **-2.992 dB** | 20.67 s | +| all-intra (`EC_H264_GOP=1`) | -0.749 dB | 19.27 s | +| `Preset::Balanced` | -1.587 dB | 29.24 s | + +All-intra costs only 0.7 dB, so about two thirds of the distance was in P pictures. + +Ablation of the four places `Fast` and `Balanced` differ, one at a time, same clip: + +| ablation | BD-PSNR | encode time | +|---|---|---| +| baseline | -2.992 dB | 20.67 s | +| half-macroblock partitions | -3.009 dB | 26.38 s | +| + subpel refinement | -3.035 dB | 29.28 s | +| 48-sample search range | -3.039 dB | 20.86 s | +| **Intra_4x4 in P** | **-1.557 dB** | 21.75 s | +| Intra_4x4 + range | -1.574 dB | 21.88 s | +| all four (= `Balanced`) | -1.587 dB | 29.24 s | + +The whole `Balanced` advantage is Intra_4x4 in P pictures, for 5% encode time. The other +three buy nothing measurable — range and the half-partitions are marginally negative, i.e. +inside the noise, and the half-partitions cost 28% encode time for it. + +## Fix + +`allow_i4: true` unconditionally in `crates/ec-h264/src/enc/mb.rs` (`7252dbe`). After it, on +the same clip: -1.557 dB, +5-10% bits at 0.3-1.3 dB lower PSNR (was +19% bits at 1.0-1.7 dB). +Synthetic default -5.202 -> -5.140 dB, floor retightened to -5.25. Full `ec-h264` suite green +(109 tests, release). No test in the repo pins encoder bytes. + +## Open, not fixed here + +- **`Preset::Balanced` no longer earns its 40% encode time.** With Intra_4x4 on everywhere it + reads -1.587 dB against `Fast`'s -1.557 dB — slower and marginally worse. Either its search + changes need to be replaced with something that measures, or the preset should go. Needs the + user's call because it is public API. +- **The remaining -1.557 dB is still unattributed.** All-intra was -0.749 dB before this fix; + re-measure it now and split the rest between prediction and quantisation. The untested + hypothesis on record: our dead zone is inverted against x264's (ours 1/3 intra, 1/6 inter; + x264 uses 11/64 intra, 21/64 inter), and we have no trellis/RDOQ and no P_8x8 sub-partitions.