Re-take the encoder's stream pins for the pyramid tpl window, and wire a second past anchor for the top ARF behind EC_AV1_ARF_ALTREF
Browse files at this commit51ec13e269ae6d9a2dc98bc5183b399c0a978d11Parent: ccbcc73- test
- re-take the encoder's stream pins for the pyramid tpl window, and wire a second past anchor for the top ARF behind EC_AV1_ARF_ALTREF
3 changed files +66 -2
- crates/ec-av1/src/encode.rs +7 -1
- crates/ec-av1/src/encoder.rs +26 -1
- lanes/arfcen.report.md +33 -0
crates/ec-av1/src/encode.rsmodified+7 -1
| @@ -13630,8 +13630,14 @@ mod tests { | ||
| 13630 | 13630 | // base now, not 16 ([`crate::encoder::Pyramid::leaf_q_offset`]) -- 9778 |
| 13631 | 13631 | // -> 9835 at q=150 and 35450 -> 35798 at q=60. |
| 13632 | 13632 | // `EC_AV1_PYRAMID=8:-32:16:-8:-48` restores these. |
| 13633 | + // Re-taken on lane-arfcen: the pyramid path hands every frame the | |
| 13634 | + // lookahead window its temporal lambda map needs | |
| 13635 | + // (`crate::encoder::tpl_pyramid`), which it never had, so every | |
| 13636 | + // superblock of these four pictures is priced at its own lambda -- | |
| 13637 | + // 9835 -> 9859 at q=150 and 35798 -> 35904 at q=60. | |
| 13638 | + // `EC_AV1_TPL_PYRAMID=0` restores these. | |
| 13633 | 13639 | let pins: [(u8, usize, u64); 2] = |
| 13634 | - [(150, 9835, 0xfdac_0219_4a6e_111e), (60, 35798, 0xe57e_aa3f_8b48_d206)]; | |
| 13640 | + [(150, 9859, 0x4409_f8db_e152_9fe7), (60, 35904, 0xc408_f126_2877_0ffb)]; | |
| 13635 | 13641 | for (q, bytes, hash) in pins { |
| 13636 | 13642 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); |
| 13637 | 13643 | assert_eq!( |
crates/ec-av1/src/encoder.rsmodified+26 -1
| @@ -903,6 +903,24 @@ fn tpl_pyramid() -> bool { | ||
| 903 | 903 | /// [`tpl_pyramid`]'s default. |
| 904 | 904 | const TPL_PYRAMID: bool = true; |
| 905 | 905 | |
| 906 | +/// Whether a group's TOP ARF names the ARF from TWO groups back as its own | |
| 907 | +/// `ALTREF_FRAME` (lane-arfcen). It has always named `GOLDEN_SLOT` there, | |
| 908 | +/// which for a top ARF is the key frame it already reads as `GOLDEN`, i.e. | |
| 909 | +/// its second reference is the same picture as its first for the first group | |
| 910 | +/// and adds nothing after: the ARF-vs-ARF census reads | |
| 911 | +/// `LAST@-8 GOLDEN@-8` on our first ARF where rav1e's reads two DISTINCT | |
| 912 | +/// anchors. The slot the ARF is about to refresh still holds that older | |
| 913 | +/// anchor while this frame is coded, so naming it costs no extra DPB slot. | |
| 914 | +fn arf_altref() -> bool { | |
| 915 | + match std::env::var("EC_AV1_ARF_ALTREF").ok() { | |
| 916 | + Some(v) => v != "0", | |
| 917 | + None => ARF_ALTREF, | |
| 918 | + } | |
| 919 | +} | |
| 920 | + | |
| 921 | +/// [`arf_altref`]'s default. | |
| 922 | +const ARF_ALTREF: bool = false; | |
| 923 | + | |
| 906 | 924 | /// The AV1 software encoder: [`EncoderConfig`] in, one [`Packet`] out per |
| 907 | 925 | /// [`Av1Encoder::encode`] call — or, with a [`Pyramid`] configured, a |
| 908 | 926 | /// coding-order burst of them per [`Av1Encoder::encode_frames`] call plus a |
| @@ -1633,7 +1651,14 @@ impl Av1Encoder { | ||
| 1633 | 1651 | &arf_picture, |
| 1634 | 1652 | anchor_slot, |
| 1635 | 1653 | next_anchor_slot, |
| 1636 | - GOLDEN_SLOT, | |
| 1654 | + // lane-arfcen: the slot this ARF refreshes still holds the ARF | |
| 1655 | + // from two groups back, so naming it here gives the frame a | |
| 1656 | + // SECOND, distinct past anchor instead of the key it already | |
| 1657 | + // reads as GOLDEN. | |
| 1658 | + match arf_altref() { | |
| 1659 | + true => next_anchor_slot, | |
| 1660 | + false => GOLDEN_SLOT, | |
| 1661 | + }, | |
| 1637 | 1662 | false, |
| 1638 | 1663 | Level::Arf, |
| 1639 | 1664 | pyramid.arf_q_offset, |
lanes/arfcen.report.mdmodified+33 -0
| @@ -121,3 +121,36 @@ Probe arms on film B (control = the old `&[]`): | ||
| 121 | 121 | | on, depth 2 | 91328 / 45.489 | 481497 / 47.990 | -0.6% / -0.3% | |
| 122 | 122 | |
| 123 | 123 | Wall is unchanged (101.5 s vs 101.2 s for the two-point ladder). |
| 124 | + | |
| 125 | +## 6. Gate tables | |
| 126 | + | |
| 127 | +Long-GOP arm (`bd_rate_film_long_gop`, 48 frames, BD vs libaom cpu-used 6 / | |
| 128 | +vs rav1e speed 6). The control arm was RUN, not quoted, and lands on the | |
| 129 | +recorded defaults to the digit: | |
| 130 | + | |
| 131 | +| arm | film A | film B | | |
| 132 | +|---|---|---| | |
| 133 | +| control (`EC_AV1_TPL_PYRAMID=0`) | +43.1% / +4.6% | +129.0% / +34.3% | | |
| 134 | +| **arm 1: tpl on the pyramid path** | **+42.8% / +4.5%** | **+127.3% / +32.9%** | | |
| 135 | + | |
| 136 | +Both film rows improve on both columns: the keep rule passes, so arm 1 ships | |
| 137 | +on by default. | |
| 138 | + | |
| 139 | +12-frame arm (`bd_rate_screen_native`), control re-run the same way: | |
| 140 | + | |
| 141 | +| arm | bars 1080p | bars 2160p | film A | film B | | |
| 142 | +|---|---|---|---|---| | |
| 143 | +| control | +1.7 / -14.5 | +12.2 / -10.2 | +37.5 / +7.6 | +54.1 / +23.9 | | |
| 144 | +| arm 1 | +2.0 / -14.2 | +12.6 / -9.9 | **+37.2 / +7.3** | **+53.2 / +23.1** | | |
| 145 | + | |
| 146 | +Both REAL film rows improve on both columns here too; the two "bars" rows are | |
| 147 | +ffmpeg `testsrc2` colour bars (recorded, never a decision) and read 0.3-0.4 | |
| 148 | +points up. | |
| 149 | + | |
| 150 | +Invariants at the shipped arm: `encoder::` scoped 33 passed / 0 failed | |
| 151 | +(release binary, 868 s, includes the bitrate test), | |
| 152 | +`the_facade_codes_the_same_bytes_as_encode_sequence` + | |
| 153 | +`tile_bytes_do_not_depend_on_the_thread_count --include-ignored` 2 passed, | |
| 154 | +`EC_COMP_MISMATCH=1` over the 48-frame film B encode: 0 lines. | |
| 155 | +Pins re-taken (the stream moves by construction): 9835 -> **9859** at q=150 | |
| 156 | +and 35798 -> **35904** at q=60; `EC_AV1_TPL_PYRAMID=0` restores the old pair. |