edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
h264rd r3 — deblock-aware inter trial distortion: rejected
Lane h264rd3, worktree ec-wt-h264rd3. Charter: mirror r2's intra change
on the inter trial — price encode_inter_mb's cost4/cost8 pair with a
deblocked SSD whose per-edge boundary strength is derived per 8.7.2.1
(coded → 2, mv/ref difference → 1, intra MB → 4/3), reusing the decoder's
own bS derivation rather than a second rule.
Verdict: every variant regressed the 720p clip; the encoder change is
reverted. What ships is the behaviour-preserving extraction of the bS
derivation in decoder.rs (BsSide/bs_side/bs_between, boundary_strength
now composed from them) and the intra trial's ssd_mb_deblocked parametrised
by a bs closure (intra_bs) — output byte-identical to r2, confirmed by the
suite's byte-identity determinism tests and by the harness reproducing r2's
numbers exactly.
Variants measured (720p film / obs 1440p BD-PSNR, flag-on vs flag-off)
Baseline = r2 (da6a6bb): +0.827 dB / -0.000 dB. Tolerance: no clip
below its baseline by > 0.005 dB; rise on 720p.
| variant | 720p BD | Δ vs r2 | obs BD | verdict |
|---|---|---|---|---|
| r2 baseline | +0.827 | — | -0.000 | — |
| V1 derived bS on cost4/cost8 | +0.818 | -0.009 | +0.001 | fail |
| V2 = V1 + deblocked skip re-check | +0.794 | -0.033 | +0.000 | fail |
| V3 = V1, weak edge-0 bS dropped | +0.821 | -0.006 | +0.000 | fail |
| reverted (shipped) | +0.827 | 0 | -0.000 | pass (=r2) |
V1 per-qp, 720p flag-on (off rows identical to r2's, elided): q22 9347720 bits 50.86 dB, q26 6095880 48.16, q30 3893464 45.24, q34 2428872 42.36; 8x8 share 14.7/13.3/14.6/11.3 %. V2: 9345712/50.86, 6087104/48.07, 3892752/45.24, 2429568/42.39. V3: 9348064/50.86, 6097064/48.16, 3894768/45.24, 2428080/42.40. obs per-qp rows moved by ≤ 0.01 dB in every variant; its BD stayed within ±0.001 of flat the whole time.
The four points are monotone: the more inter-edge filtering the trial metric applies, the worse 720p gets. The deblocked-metric gain r2 found on intra candidates does not transfer to inter candidates on this content.
Mechanism (what was built, why it loses)
inter_trial_bs(pic, mb_addr, mb_x, mb_y, lv) answered bs(edge, seg, vertical) with the decoder's own rule: the q side is always the candidate —
BsSide { intra: false, coded: <lv.nz at that 4x4, or any-nonzero luma8 for trans8>, mv/ref from pic (write_block already ran) } — the p side is the
candidate again on internal edges, bs_side(pic, …) on macroblock edges.
ssd_mb_deblocked filtered its 24x24 scratch per (edge, seg) at that
strength.
Why it loses: the trial's aprons are the neighbours' pre-filter samples — the one state the encoder cannot know at decision time (the decoder filters after the whole frame is coded, cascaded). For intra candidates (r2) the forced bS 4/3 filtering dominates that staleness. For inter candidates the derived strengths are mostly 1/2 — weak filters whose benefit is the same order as the apron error — so pricing them adds model noise, not signal. The variant ladder confirms the split: V3 (which dropped exactly the weak macroblock-edge strengths against stale aprons, keeping the self-consistent internal edges) recovered 0.003 of V1's 0.009 loss, and V2 (more deblocking of the skip re-check, same stale aprons) lost a further 0.024. The remaining -0.006 in V3 is the honest price of the internal bS-2 modelling: on this film content even the self-consistent part does not pay for the inter trial.
What ships
crates/ec-h264/src/decoder.rs:bs_side/bs_betweenextracted fromboundary_strength(the 8.7.2.1 rule in one place,pub(crate)so the encoder can reach it);boundary_strengthis now coords →bs_between(&bs_side(p), &bs_side(q), mb_edge). No behaviour change.crates/ec-h264/src/enc/mb.rs:ssd_mb_deblockedtakes abs(edge, seg, vertical)closure instead of hard-coded 4/3; the three intra trial costs passintra_bs(edge 0 → 4, else 3 — the same values). Per-segment strengths are now plumbed (uniform-segment fast path kept). Inter cost4/cost8 and the skip re-check stay pre-filter, exactly r2.
Gates (reverted state)
cargo test --release -p ec-h264— 75+23+9+1 passed, 0 failed (byte-identity determinism tests confirm flag-off/flag-on output matches r2 bit-for-bit).- Harness both clips: 720p +0.827 dB, obs -0.000 dB — identical to the r2 baselines (pass, no regression, no gain).
cargo test --release -p ec-h264 --test conformance— 23 passed, 0 failed.
Scope cuts (moot after the revert, but measured as V2): the skip re-check was chartered as the fallback variant and made things worse, so it stays pre-filter permanently on this evidence. Chroma half and right/bottom edges remain r2's scope cuts.