forge
Explore
Log in

Don't you dare go Hollow

H264-vs-x264 rank-1 lane report

Browse files at this commit

59483b88cedbfc050ba9efe4bc970025b86d7c06Ahmet Kaan GümüşParent: f0a6733
  • docs
    • h264-vs-x264 rank-1 lane report
Show full message
docs(lanes): h264-vs-x264 rank-1 lane report
lanes/h264x264-r1.report.mdadded+76 -0
@@ -0,0 +1,76 @@
1+# lane h264x264-r1 — first rate-quality reference for ec-h264
2+
3+Rank 1 of `lanes/survey-r1.report.md` ("ec-h264 has no rate-quality reference at all").
4+Closed 2026-08-23. Commits `1dee93e`, `aa1cd35`, `d994e4c`, `7252dbe` on `main`.
5+
6+## What landed
7+
8+`bd_psnr_vs_x264` in `crates/ec-h264/tests/encode.rs` — a run-by-default gate (skips loudly,
9+with the exact runnable command, when ffmpeg/libx264 is absent). It encodes the same pictures
10+at QP 22/26/30/34 with both encoders under matched features, decodes our own stream with
11+ffmpeg to prove our reported PSNR is the stream's and not just our reconstruction's
12+(`|recon - decoded| < 0.05 dB`), and reports BD-PSNR. Default source is a synthetic clip;
13+`EC_H264_CLIP=<file>` sweeps a real one, `EC_H264_GOP` and `EC_H264_PRESET_BALANCED` vary
14+the configuration.
15+
16+## Two instrument defects found before any number was trusted
17+
18+1. **x264's `-qp` is not constant QP.** `ipratio` (1.4) and `pbratio` scale the I/B quantiser
19+ off the requested value; `qcomp`, `aq-mode`, `psy`, `chroma-qp-offset` perturb it further.
20+ All-intra diagnosis: x264 read +37% bits at +4.5 dB — a different quantiser reading as a
21+ rate-quality win. Pinned with
22+ `scenecut=0:aq-mode=0:psy=0:8x8dct=0:ipratio=1.0:pbratio=1.0:qcomp=1.0:chroma-qp-offset=0`.
23+2. **A noisy synthetic source measures residual abandonment, not coding gain.** On an
24+ incompressible noise field x264 spent 224k bits at QP 30 where we spent 672k and landed
25+ 0.5 dB *below* us, yet scored a large BD win. The tell was `Preset::Balanced` scoring
26+ *worse* than `Preset::Fast` there while scoring far better on real content. Replaced with
27+ `Clip::render_smooth`.
28+
29+Both are recorded as a class in memory (`x264-cqp-and-noise-gates`): an encoder-vs-reference
30+gate must first prove the two encoders sit at the same operating point.
31+
32+## Where the gap was
33+
34+3840x1608 clip from the library, 24 pictures 1 s apart, GOP 10, matched features:
35+
36+| configuration | BD-PSNR vs x264 | encode time |
37+|---|---|---|
38+| `Preset::Fast` (baseline) | **-2.992 dB** | 20.67 s |
39+| all-intra (`EC_H264_GOP=1`) | -0.749 dB | 19.27 s |
40+| `Preset::Balanced` | -1.587 dB | 29.24 s |
41+
42+All-intra costs only 0.7 dB, so about two thirds of the distance was in P pictures.
43+
44+Ablation of the four places `Fast` and `Balanced` differ, one at a time, same clip:
45+
46+| ablation | BD-PSNR | encode time |
47+|---|---|---|
48+| baseline | -2.992 dB | 20.67 s |
49+| half-macroblock partitions | -3.009 dB | 26.38 s |
50+| + subpel refinement | -3.035 dB | 29.28 s |
51+| 48-sample search range | -3.039 dB | 20.86 s |
52+| **Intra_4x4 in P** | **-1.557 dB** | 21.75 s |
53+| Intra_4x4 + range | -1.574 dB | 21.88 s |
54+| all four (= `Balanced`) | -1.587 dB | 29.24 s |
55+
56+The whole `Balanced` advantage is Intra_4x4 in P pictures, for 5% encode time. The other
57+three buy nothing measurable — range and the half-partitions are marginally negative, i.e.
58+inside the noise, and the half-partitions cost 28% encode time for it.
59+
60+## Fix
61+
62+`allow_i4: true` unconditionally in `crates/ec-h264/src/enc/mb.rs` (`7252dbe`). After it, on
63+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).
64+Synthetic default -5.202 -> -5.140 dB, floor retightened to -5.25. Full `ec-h264` suite green
65+(109 tests, release). No test in the repo pins encoder bytes.
66+
67+## Open, not fixed here
68+
69+- **`Preset::Balanced` no longer earns its 40% encode time.** With Intra_4x4 on everywhere it
70+ reads -1.587 dB against `Fast`'s -1.557 dB — slower and marginally worse. Either its search
71+ changes need to be replaced with something that measures, or the preset should go. Needs the
72+ user's call because it is public API.
73+- **The remaining -1.557 dB is still unattributed.** All-intra was -0.749 dB before this fix;
74+ re-measure it now and split the rest between prediction and quantisation. The untested
75+ hypothesis on record: our dead zone is inverted against x264's (ours 1/3 intra, 1/6 inter;
76+ x264 uses 11/64 intra, 21/64 inter), and we have no trellis/RDOQ and no P_8x8 sub-partitions.