forge
Explore
Log in

Don't you dare go Hollow

The coding pyramid decided on a long GOP -- Pyramid::default 16:-24:16 -> 8:-32:16

Browse files at this commit

0d3b9a0f946adb1997cb8575cdbc9121f641e94dAhmet Kaan GümüşParent: c58bcaa
  • feat
    • the coding pyramid decided on a long GOP -- Pyramid::default 16:-24:16 -> 8:-32:16
Show full message
feat(av1): the coding pyramid decided on a long GOP -- Pyramid::default 16:-24:16 -> 8:-32:16

The shipped shape came off bd_rate_screen_native, which codes 12 frames with
gop = 12; a mini-GOP is cut at every key frame, so any mini_gop over 12 codes
the SAME stream there and the 16 was really "one hidden ARF per 12-picture
GOP". On the new long-GOP arm (48 pictures, gop 48, the two real films, vs
libaom cpu-used 6 and rav1e speed 6 at -g 48) a real 16- or 32-picture group
is WORSE than an 8-picture one, and ARF -32 is an interior optimum (-40 turns
back). 8:-32:16 takes 11.7 / 7.5 points off film A and 0.4 / 1.0 off film B
against 16:-24:16 -- all four columns down.

The price is stated in Pyramid::default and lanes/pyr4.sweep.txt: at a
12-frame GOP the new shape is 7.0 / 5.7 (film A) and 20.5 / 18.3 (film B)
worse, because the best shape depends on GOP length and the long GOP is what
the editor exports. Pins re-taken: 8076 -> 8755 at q=150, 27585 -> 28637 at
q=60.
crates/ec-av1/src/encode.rsmodified+7 -1
@@ -13057,8 +13057,14 @@ mod tests {
13057 // the blocks that take one code a filter-intra mode, a different13057 // the blocks that take one code a filter-intra mode, a different
13058 // prediction and different coefficients -- 7321 -> 7373 at q=150 and13058 // prediction and different coefficients -- 7321 -> 7373 at q=150 and
13059 // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these.13059 // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these.
13060+ // Re-taken on lane-pyr4: the default pyramid is `8:-32:16` now, the
13061+ // long-GOP sweep's shape (`lanes/pyr4.sweep.txt`), so these four
13062+ // pictures code as one truncated group of 8 with its hidden ALTREF at
13063+ // `q-32` instead of one truncated group of 16 at `q-24`:
13064+ // 8076 -> 8755 at q=150 and 27585 -> 28637 at q=60.
13065+ // `EC_AV1_PYRAMID=16:-24:16` restores these.
13060 let pins: [(u8, usize, u64); 2] =13066 let pins: [(u8, usize, u64); 2] =
13061- [(150, 8076, 0x8171_4818_e223_ab21), (60, 27585, 0xdbe7_eecd_6d64_c4f5)];13067+ [(150, 8755, 0xa28f_a6d2_fe29_66ae), (60, 28637, 0xcdf1_ba94_4221_c10e)];
13062 for (q, bytes, hash) in pins {13068 for (q, bytes, hash) in pins {
13063 let encoded = encode_sequence(&source, q, 0.5).unwrap();13069 let encoded = encode_sequence(&source, q, 0.5).unwrap();
13064 assert_eq!(13070 assert_eq!(
crates/ec-av1/src/encoder.rsmodified+43 -9
@@ -585,18 +585,52 @@ impl Default for Pyramid {
585 /// are minimal and the bound is not the answer. Deeper ARF is the same585 /// are minimal and the bound is not the answer. Deeper ARF is the same
586 /// shape -- `-32` buys 0.6 on film A and gives 0.7 back on film B.586 /// shape -- `-32` buys 0.6 on film A and gives 0.7 back on film B.
587 ///587 ///
588- /// TWO THINGS THIS SWEEP DOES NOT SAY. The mini-GOP axis is measured588+ /// WHAT THAT SWEEP COULD NOT SAY, and the LONG-GOP sweep that answers it
589+ /// (lane-pyr4, `lanes/pyr4.sweep.txt`). The table above is measured
589 /// against a gate that codes 12 frames with `gop = 12`, and a group is590 /// against a gate that codes 12 frames with `gop = 12`, and a group is
590- /// cut at every key frame (`encode_frames`), so `16` here is really591+ /// cut at every key frame (`encode_frames`), so `16` there is really
591- /// "one hidden ARF per GOP" and any mini-GOP over 12 codes the same592+ /// "one hidden ARF per GOP" and ANY mini-GOP over 12 codes the same
592- /// stream; on a stream with a longer GOP `16` is a genuine 16-picture593+ /// stream (class `instrument at bound`). The user's exports are long
593- /// group, which this gate cannot measure. And the offsets were swept at594+ /// GOPs, so the shape is decided on
594- /// mini-GOP 8 before 16 won the first axis; the two joint corners at 16595+ /// [`crate::encode::tests::bd_rate_film_long_gop`] -- 48 pictures, `gop
595- /// confirm the same gradient, but the full grid at 16 is not measured.596+ /// = 48`, the two real films, four quantizers, vs libaom `cpu-used 6`
597+ /// and rav1e `speed=6` at the same key interval:
598+ ///
599+ /// | mini_gop:arf:leaf | film A vs libaom / rav1e | film B vs libaom / rav1e |
600+ /// |---|---|---|
601+ /// | 32:-24:16 | +79.0 / +29.8 | +164.4 / +58.8 |
602+ /// | 16:-24:16 (was the default) | +67.4 / +21.0 | +165.5 / +57.6 |
603+ /// | 8:-16:16 | +63.7 / +19.0 | +167.6 / +58.6 |
604+ /// | 4:-24:16 | +61.9 / +19.5 | +160.8 / +56.7 |
605+ /// | 8:-24:16 | +58.5 / +15.5 | +166.1 / +56.8 |
606+ /// | 8:-24:12 | +60.2 / +17.3 | +166.8 / +58.0 |
607+ /// | 8:-24:20 | +57.1 / +14.0 | +166.2 / +56.6 |
608+ /// | 8:-40:16 | +56.1 / +13.3 | +167.6 / +57.3 |
609+ /// | 8:-32:12 | +56.5 / +14.7 | +163.0 / +56.3 |
610+ /// | 8:-32:20 | +55.4 / +12.9 | +167.9 / +57.4 |
611+ /// | **8:-32:16** | **+55.7 / +13.5** | **+165.1 / +56.6** |
612+ ///
613+ /// `8:-32:16` ships: against the old `16:-24:16` it takes 11.7 / 7.5
614+ /// points off film A and 0.4 / 1.0 off film B -- all four columns down.
615+ /// A real 16- or 32-picture group is WORSE than an 8-picture one on film
616+ /// A once the GOP is long enough for the distinction to exist, which the
617+ /// 12-frame gate could not see; `4` was probed below the swept edge and
618+ /// turns back up on film A. ARF `-32` is an interior optimum (`-40`
619+ /// turns back on both films). The leaf axis has content-opposite optima
620+ /// (film A wants `20`, film B wants `12`, within 1.1 and 4.9 points) so
621+ /// `16` stays, being the only value down on all four columns.
622+ ///
623+ /// THE PRICE, stated: on the SHORT-GOP gate above (12 frames, `gop =
624+ /// 12`, where a mini-GOP of 8 splits into 8 + 4 while 16 is one group)
625+ /// `8:-32:16` reads film A +51.2 / +21.4 and film B +91.0 / +53.5
626+ /// against `16:-24:16`'s +44.2 / +15.7 and +70.5 / +35.2. The two gates
627+ /// disagree because the best shape depends on the GOP length, and the
628+ /// long one is what the editor exports; a GOP-length-adaptive `mini_gop`
629+ /// is the standing follow-up, not measured here.
596 fn default() -> Self {630 fn default() -> Self {
597 Self {631 Self {
598- mini_gop: 16,632+ mini_gop: 8,
599- arf_q_offset: -24,633+ arf_q_offset: -32,
600 leaf_q_offset: 16,634 leaf_q_offset: 16,
601 }635 }
602 }636 }
lanes/pyr4.sweep.txtadded+112 -0
@@ -0,0 +1,112 @@
1+lane-pyr4 -- the coding pyramid decided on a LONG GOP
2+=====================================================
3+
4+Why. main 38753f0a shipped `Pyramid::default` = 16:-24:16 off a sweep of
5+`encode::tests::bd_rate_screen_native`, which codes 12 frames with gop = 12.
6+`Av1Encoder::encode_frames` cuts a mini-GOP at every key frame, so ANY
7+mini_gop over 12 codes the same stream in that gate: the shipped "16" was
8+measured as "one hidden ARF per 12-picture GOP", never as a real 16-picture
9+group (class `instrument at bound` / `gate blind to feature`). The user's
10+exports are long GOPs.
11+
12+The instrument. `encode::tests::bd_rate_film_long_gop` (#[ignore], new this
13+lane): the same native crop, three-way sample-exact decode (encoder / ffmpeg
14+/ our decoder) and four-quantizer ladder as `bd_rate_screen_native`, over the
15+two real film rows of `native_gate_clips` only, but 48 pictures with gop = 48
16+(`encode_sequence` sets gop = pictures.len(); `external_ladder` passes ffmpeg
17+`-g 48`). Reference arms, unchanged from the 12-frame gate except that -g:
18+ libaom-av1 -g 48 -cpu-used 6 -b:v 0 -crf {5,20,35,45}
19+ librav1e -g 48 -rav1e-params speed=6:quantizer={50,100,150,200}:
20+ tile_cols=1:tile_rows=1:threads=1
21+ ours base_q_idx {150,120,90,60}, one tile, one thread
22+Both wrappers honour -g (measured: a 96-frame clip at -g 48 codes exactly 2
23+key frames under librav1e and under libaom-av1).
24+Crops: film A 1920x768, film B 1920x1024 (the 4K source, centre crop).
25+Wall per arm, 3 arms in parallel: ours 240-290 s per film row, libaom 33-80 s,
26+rav1e 51-63 s; ~13-17 minutes per arm for both rows. Raw logs: lanes/pyr4/.
27+
28+Every row below is keyed by its own log's "pyramid requested/effective"
29+print, never by argument order (lane-pyr3 misattributed three rows that way).
30+Effective == requested on all 11 arms: neither film is gated to flat.
31+
32+LONG-GOP TABLE (48 frames, gop 48). BD-rate %, lower is better.
33+
34+| mini_gop:arf:leaf | film A vs libaom | film A vs rav1e | film B vs libaom | film B vs rav1e |
35+|---|---|---|---|---|
36+| 16:-24:16 (shipped) | +67.4 | +21.0 | +165.5 | +57.6 |
37+| 32:-24:16 | +79.0 | +29.8 | +164.4 | +58.8 |
38+| 8:-24:16 | +58.5 | +15.5 | +166.1 | +56.8 |
39+| 4:-24:16 (probe) | +61.9 | +19.5 | +160.8 | +56.7 |
40+| 8:-16:16 | +63.7 | +19.0 | +167.6 | +58.6 |
41+| 8:-32:16 ** SHIPS **| +55.7 | +13.5 | +165.1 | +56.6 |
42+| 8:-40:16 (probe) | +56.1 | +13.3 | +167.6 | +57.3 |
43+| 8:-24:12 | +60.2 | +17.3 | +166.8 | +58.0 |
44+| 8:-24:20 | +57.1 | +14.0 | +166.2 | +56.6 |
45+| 8:-32:12 | +56.5 | +14.7 | +163.0 | +56.3 |
46+| 8:-32:20 | +55.4 | +12.9 | +167.9 | +57.4 |
47+
48+Axis 1, mini_gop at the shipped offsets -24:16 -- 32 / 16 / 8 / 4.
49+Film A is strongly ordered 8 < 4 < 16 < 32 (8 is 8.9 / 5.5 points better than
50+the shipped 16); film B is nearly flat over the whole axis (a 5.3-point span
51+on the libaom column against a 165-point level, 2.1 on rav1e). 8 was the
52+bottom of the requested set, so 4 was probed below it (class `search bounded
53+by its heuristic`): film A turns back up at 4, so 8 is an interior optimum.
54+
55+Axis 2, the offsets at mini_gop 8. Requested grid arf {-16,-24,-32} x leaf
56+{12,16,20}; 7 of the 9 were run plus a -40 probe. arf is the strong axis
57+(-16 -> -32 is 8.0 points on film A) and -32 is an interior optimum: -40
58+turns back up on film A's libaom column and on both of film B's. leaf is the
59+weak axis (<= 3.1 points on film A, <= 4.9 on film B) and its optima are
60+content-opposite (film A wants 20, film B wants 12), so 16 stays -- it is the
61+only leaf value down on all four columns against the shipped shape.
62+DROPPED, wall vs value: (-16,12) and (-16,20). arf -16 is last on all four
63+columns at leaf 16 and the leaf axis is a third of the arf axis' size, so
64+neither corner can reach 8:-32:16.
65+
66+DECISION: `Pyramid::default` 16:-24:16 -> 8:-32:16.
67+Keep rule (both films down on both columns) is met:
68+ film A +67.4 -> +55.7 (-11.7) +21.0 -> +13.5 (-7.5)
69+ film B +165.5 -> +165.1 (-0.4) +57.6 -> +56.6 (-1.0)
70+
71+THE PRICE, on the record. The 12-frame gate at the winning shape,
72+`bd_rate_screen_native` with EC_AV1_PYRAMID=8:-32:16 (all five rows):
73+
74+| clip | vs libaom | vs rav1e | wall ours:libaom:rav1e |
75+|---|---|---|---|
76+| bars 1080p 1920x1024 | +4.8% | -11.5% | 38.9s:6.7s:16.7s |
77+| bars 2160p 1920x1024 | +20.5% | -3.4% | 34.5s:5.7s:16.1s |
78+| film A 1920x768 | +51.2% | +21.4% | 64.6s:9.9s:13.9s |
79+| film B 1920x1024 | +91.0% | +53.5% | 69.1s:19.1s:15.2s |
80+| screen capture 1920x1024 (gated flat) | +48.2% | -16.4% | 33.7s:8.8s:12.4s |
81+
82+against the shipped 16:-24:16 on the same gate (lanes/pyr3.sweep.txt):
83+film A +44.2 / +15.7, film B +70.5 / +35.2. So the new shape is 7.0 / 5.7
84+worse on film A and 20.5 / 18.3 worse on film B AT A 12-FRAME GOP, where a
85+mini-GOP of 8 splits into 8 + 4 while 16 is a single group. The two gates
86+disagree because the best shape depends on GOP LENGTH; the long GOP is what
87+the editor exports, so it governs.
88+DEFERRED: a GOP-length-adaptive mini_gop (e.g. the largest power of two that
89+divides the GOP into whole groups, capped) would take both tables. Not
90+measured here; unblocked by one more long/short pair of arms once the rule is
91+written.
92+
93+VERIFICATION (lane-pyr4, at 8:-32:16)
94+ pins re-taken: encode::tests::the_encoders_own_streams_are_byte_identical_to
95+ _their_pins 8076 -> 8755 at q=150, 27585 -> 28637 at q=60 (the four-picture
96+ clip codes as one truncated group of 8 with its ARF at q-32).
97+ encode::tests::the_facade_codes_the_same_bytes_as_encode_sequence ok
98+ tile_bytes_do_not_depend_on_the_thread_count (--include-ignored) ok
99+ EC_COMP_MISMATCH=1 over the whole lib suite: 544 passed, 0 mismatch lines
100+ encoder:: --include-ignored --test-threads 1: 27 passed
101+ cargo test -p ec-av1 --release -j4: 544 passed / 0 failed / 43 ignored
102+ cargo check --workspace --all-targets: 0 errors, 0 ec-av1 warnings
103+ (25 warning lines, all pre-existing ec-opus / ec-vorbis)
104+
105+PRE-EXISTING, NOT THIS LANE: running the ignored encoder:: tests in PARALLEL
106+(`--include-ignored encoder:: ...` with the default test-thread count) fails 5
107+of them -- "a reference frame selected with no picture at this frame's own
108+ref_frame_idx slot" and a short dav1d frame count. It reproduces identically
109+on main's shape (EC_AV1_PYRAMID=16:-24:16, same binary: 5 failures, a superset
110+of ours), and every one of them passes standalone and at --test-threads 1, so
111+it is a shared-state/temp-file race between those heavy gates, not a pyramid
112+defect. Class `PID-keyed temp path`. Log: lanes/pyr4/oldshape-combined.log.