forge
Explore
Log in

Don't you dare go Hollow

The top ARF is coded from a temporally filtered source

Browse files at this commit

7b957990e57ad8e5082aba7b1da531d53eea682aAhmet Kaan GümüşParent: 56d80b6
  • feat
    • the top ARF is coded from a temporally filtered source
Show full message
feat(av1): the top ARF is coded from a temporally filtered source

The 48-picture film B census names the top ARF as the overspent level (55%
of the stream, 6992 B a frame against rav1e's 3872 at a FINER quantizer) and
splits its per-frame gap 61% residual / 28% mode+partition / 9% mv. The new
arf_pred_census instrument then separates the two candidate causes of that
residual: the anchor's lag is worth 7.1% of its prediction SAD (film B 1.199
per pixel at lag 8 vs 1.114 at lag 4) while a motion-compensated average of
the group's own display neighbours removes 11.7% of it -- the residual is
mostly source grain, which no search at any lag can predict.

speed::ARF_TF now defaults to 3.0: the top ARF's source is filtered against
its two buffered display neighbours with weight exp(-mse/strength). Long-GOP
gate, BD vs libaom / rav1e: film A +23.5/-8.0 -> +22.7/-7.9, film B
+85.3/+6.7 -> +79.0/+2.7. Strength is sharply single-peaked (8, 15, 30 all
lose); EC_AV1_ARF_TF=0 restores the old streams.

Pins re-taken -- the hidden frames' pixels move by construction:
8269 -> 8218 at q=150 and 33044 -> 33017 at q=60.
crates/ec-av1/src/encode.rsmodified+5 -1
@@ -17032,7 +17032,11 @@ mod tests {
17032 // ([`crate::speed::DQ_LEVEL_K`]), so the hidden frames' quantizer17032 // ([`crate::speed::DQ_LEVEL_K`]), so the hidden frames' quantizer
17033 // grids -- and every decision priced against them -- moved:17033 // grids -- and every decision priced against them -- moved:
17034 // 8252 -> 8269 bytes at q=150 and 33053 -> 33044 at q=60.17034 // 8252 -> 8269 bytes at q=150 and 33053 -> 33044 at q=60.
17035- let pins: [(u8, usize, u64); 2] = [(150, 8269, 0xf0a10bafe7b45fe2), (60, 33044, 0x077e9c22ff6f41fb)];17035+ // Re-taken on lane-arfpred: the top ARF is coded from a temporally
17036+ // FILTERED source ([`crate::speed::ARF_TF`]), so every hidden frame's
17037+ // pixels -- and the leaves that predict from them -- moved:
17038+ // 8269 -> 8218 bytes at q=150 and 33044 -> 33017 at q=60.
17039+ let pins: [(u8, usize, u64); 2] = [(150, 8218, 0xd533_c8ea_14ca_ae6e), (60, 33017, 0xbced_b694_dcfe_9146)];
17036 let coded: Vec<(u8, usize, u64)> = pins17040 let coded: Vec<(u8, usize, u64)> = pins
17037 .iter()17041 .iter()
17038 .map(|&(q, _, _)| {17042 .map(|&(q, _, _)| {
crates/ec-av1/src/speed.rsmodified+16 -1
@@ -378,7 +378,22 @@ pub(crate) const DQ_LEVEL_K: [f64; 3] = [1.5, 1.0, 1.0];
378 /// vs lag 4 1.114 per pixel), so what the residual codes is mostly source378 /// vs lag 4 1.114 per pixel), so what the residual codes is mostly source
379 /// grain. Filtering it out of the picture the anchor is coded from is the379 /// grain. Filtering it out of the picture the anchor is coded from is the
380 /// mechanism libaom uses (`arnr`) and rav1e 0.8.1 does not have at all.380 /// mechanism libaom uses (`arnr`) and rav1e 0.8.1 does not have at all.
381-pub(crate) const ARF_TF: [f64; 11] = [0.0; 11];381+/// Long-GOP gate (48 pictures, BD vs libaom / rav1e), strength 3 against the
382+/// control: film A +23.5/-8.0 -> **+22.7/-7.9**, film B +85.3/+6.7 ->
383+/// **+79.0/+2.7**. Film B takes 6.3 and 4.0 points off; film A takes 0.8 off
384+/// the libaom column and hands back 0.1 on the rav1e one, which is the
385+/// keep rule's "one column >=0.5 down, the other flat" clause. It is also
386+/// FASTER (film B two-point probe 167 s -> 147 s): the anchor has fewer
387+/// coefficients to code. Uniform over the presets -- above preset 6
388+/// [`TPL_DEPTH`] leaves the group window empty and the filter is inert by
389+/// construction.
390+///
391+/// Strength is single-peaked and SHARP: the film B two-point probe reads
392+/// -1.4% bytes at equal PSNR at 3, +3.4% at 8, +6.9% at 15 and +15.8% at 30
393+/// (`lanes/arfpred.report.md` section 3). Hard filtering does remove 6-7% of
394+/// the stream's bytes and gives all of it back in quality, because the leaves
395+/// still carry the grain the anchor no longer has.
396+pub(crate) const ARF_TF: [f64; 11] = [3.0; 11];
382 397
383 /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split398 /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split
384 /// trial is withheld. The single biggest wall lever in the tile search.399 /// trial is withheld. The single biggest wall lever in the tile search.
lanes/arfpred.report.mdadded+108 -0
@@ -0,0 +1,108 @@
1+# lane-arfpred — the top ARF's PREDICTION, and a temporal filter of its source
2+
3+Worktree `edith_codecs-arfpred`, branch `lane-arfpred` off main `35874aef`.
4+Deciding gate `encode::tests::bd_rate_film_long_gop` (48 pictures, both film
5+rows, BD vs libaom `cpu-used 6` / rav1e `speed 6`). **The control was RUN, not
6+quoted: film A +23.5 / −8.0, film B +85.3 / +6.7 — the charter's numbers to
7+the digit.**
8+
9+## 0. The matched-rate point (film B, 48 pictures, the gate's own window)
10+
11+| stream | bytes | PSNR-Y |
12+|---|---|---|
13+| ours `q150` (this HEAD) | 76409 | 45.564 |
14+| rav1e `speed 6 quantizer 110` | 75452 | 45.751 |
15+| libaom `cpu-used 6 crf 34` | 70345 | 46.539 |
16+
17+Ours is +1.3% bytes for −0.19 dB against rav1e; every table below is read by
18+OUR decoder (`EC_AV1_BITCENSUS=1 EC_CENSUS_PERFRAME=1 syntax_census`), so all
19+three streams are measured by the same reader. `syntax_census` now prints
20+per-plane PSNR (`PSNR-Y ... U ... V`) per coded frame.
21+
22+## 1. Per-level census — bytes per FAMILY per frame (B/frame)
23+
24+| level | n | q | B/frame | PSNR-Y | U | V | intra% | comp% | skip% | NEW% | blocks/f | coeff | literal | mode | mv | part |
25+|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
26+| **ours top ARF** | 6 | 118 | **6992** | 45.88 | 51.60 | 51.91 | 4.7 | 20.4 | 61.4 | 38.7 | 2196 | 3483 | 1151 | 1323 | 700 | 281 |
27+| **rav1e L1 ARF** | 11 | 104 | **3872** | 45.97 | 51.61 | 52.01 | 0.5 | 0.0 | 80.7 | 26.0 | 1507 | 1996 | 730 | 608 | 410 | 125 |
28+| ours mid ARF | 6 | 142 | 1354 | 45.74 | 51.69 | 51.96 | 0.4 | 58.1 | 88.9 | 41.0 | 954 | 343 | 104 | 450 | 356 | 92 |
29+| rav1e L2 | 12 | 122 | 537 | 45.48 | 51.60 | 52.02 | 0.1 | 52.7 | 98.7 | 21.1 | 732 | 60 | 20 | 228 | 186 | 41 |
30+| ours leaf | 35 | 162 | 267 | 45.43 | 51.60 | 51.96 | 0.0 | 56.5 | 98.0 | 27.5 | 552 | 24 | 6 | 142 | 73 | 18 |
31+| rav1e leaf | 24 | 139 | 179 | 45.69 | 51.55 | 52.06 | 0.0 | 62.5 | 99.8 | 16.7 | 528 | 6 | 1 | 103 | 55 | 11 |
32+| ours key | 1 | 102 | 15827 | 47.34 | 51.94 | 52.26 | 100 | 0 | 0 | — | 1479 | 10666 | 3788 | 1046 | 0 | 148 |
33+| rav1e key | 1 | 80 | 20763 | 47.95 | 51.94 | 52.45 | 100 | 0 | 0 | — | 1266 | 14646 | 5102 | 828 | 0 | 140 |
34+
35+**WHERE THE +3120 B/frame GOES** (top ARF, ours − rav1e): residual
36+(coeff+literal) **+1908 B = 61%**, mode+partition **+871 B = 28%**, mv
37+**+290 B = 9%**.
38+
39+Three readings the charter asked for, in one line each:
40+
41+* **NOT the quantizer.** rav1e codes its anchor at a FINER qindex than ours
42+ (104 vs 118) and still spends 45% of our bytes for +0.09 dB. Nothing on the
43+ q axis explains this (and lane-arfq refuted the offsets twice).
44+* **NOT chroma.** Per-plane PSNR at the anchor is 51.60/51.91 ours against
45+ 51.61/52.01 rav1e's — matched to a hundredth. The whole deficit is luma.
46+* **NOT intra fallback.** Our anchor codes 4.7% of its AREA intra where
47+ rav1e codes 0.5% (lane-arfcen read 8-10% before the merges since), so the
48+ ceiling of an intra-decision lever at this level is a few percent of one
49+ level — the same order as its own noise.
50+
51+What is left is the residual, and its two possible causes are the anchor's
52+LAG (we predict across 8 pictures, rav1e across 4) and the SOURCE the
53+residual is coding.
54+
55+## 2. `arf_pred_census` — pricing lag against source grain (new instrument)
56+
57+`encode::tests::arf_pred_census` (`--ignored`, 6 s, no encoder change): every
58+16x16 luma block of every ARF position of the gate's own 48-picture window
59+gets the SAME log-step diamond search (`last2_census`'s) against the picture
60+8 back, the picture 4 back, and — with the block temporally filtered first —
61+the picture 8 back again.
62+
63+| clip | ARFs | lag 8 SAD/px | lag 4 SAD/px | tf lag 8 SAD/px | tf removes | filtered-vs-source PSNR |
64+|---|---|---|---|---|---|---|
65+| film A | 5 | 2.484 | 2.369 | 2.337 | 5.9% | 48.30 dB |
66+| film B | 5 | 1.199 | 1.114 | 1.059 | 11.7% | 50.14 dB |
67+
68+(strength 30, the two DISPLAY-PAST neighbours — the only ones the encoder's
69+own group buffer holds when it codes its top ARF. With ±2 both sides it is
70+6.8% / 14.3% at 47.74 / 49.54 dB; strengths 10/30/60/120 are in
71+`$HOME/.cache/arfpred/predsweep.log`.)
72+
73+**THE LAG IS NOT THE CAUSE.** Halving the anchor's prediction distance —
74+rav1e's whole structural advantage at this level — is worth 7.1% of the
75+prediction SAD on film B and 4.6% on film A, where the byte gap is 81%. What
76+our anchor's residual codes is mostly SOURCE GRAIN, which no motion search at
77+any lag can predict; a motion-compensated average of the neighbours removes
78+1.6x more of it than the lag does.
79+
80+## 3. The lever: `arf_temporal_filter` (libaom's `arnr` in the small)
81+
82+Built (`encode::arf_temporal_filter`, `speed::ARF_TF`,
83+`EC_AV1_ARF_TF=<strength>`): the top ARF's source picture is replaced by a
84+motion-compensated average of itself and its two group-buffered display
85+neighbours, weight `exp(-mse / strength)` per 16x16 block, chroma on the
86+halved luma vector with its own weight sum. **rav1e 0.8.1 has NO temporal
87+filter at all** (`grep -rn "temporal_filter\|arnr" rav1e-0.8.1/src` — empty),
88+so this is a libaom-only mechanism, not the thing rav1e beats us with.
89+
90+Probe ladder, film B 48 pictures, `q150` and `q90`, each arm judged at the
91+CONTROL's own PSNR through the arm's own two-point slope (arfcen's rule):
92+
93+| strength | q150 B / dB | q90 B / dB | slope dB/doubling | bytes at 45.564 dB | vs control |
94+|---|---|---|---|---|---|
95+| 0 (control) | 76409 / 45.564 | 346678 / 47.838 | 1.042 | 76409 | — |
96+| **3** | 72278 / 45.498 | 308172 / 47.759 | 1.081 | **75378** | **−1.35%** |
97+| 8 | 71636 / 45.413 | 308366 / 47.669 | 1.071 | 78996 | +3.4% |
98+| 15 | 70975 / 45.351 | 312607 / 47.606 | 1.054 | 81657 | +6.9% |
99+| 30 | 71814 / 45.246 | 321413 / 47.533 | 1.058 | 88453 | +15.8% |
100+| 60 | 73252 / 45.158 | 331390 / 47.470 | — | — | worse still |
101+
102+The filter does exactly what the census said it would — 6-7% of the stream's
103+bytes come off at strength 15-30 — and the BD metric takes it straight back,
104+because the gate scores PSNR against the UNFILTERED source and the leaves
105+still carry the grain the anchor no longer has. Note the non-monotone byte
106+column: past strength 15 the stream gets BIGGER again, which is the leaves
107+paying for a reference that no longer resembles their own sources.
108+