The ARF temporal filter stops at the rate loop's quantizer floor
Browse files at this commitcbb53369632da7dd860e199162eafb072825208dParent: 3528148- fix
- the ARF temporal filter stops at the rate loop's quantizer floor
3 changed files +43 -30
- crates/ec-av1/src/encoder.rs +7 -1
- crates/ec-av1/src/speed.rs +14 -0
- lanes/arfpred.report.md +22 -29
crates/ec-av1/src/encoder.rsmodified+7 -1
| @@ -1797,7 +1797,13 @@ impl Av1Encoder { | ||
| 1797 | 1797 | // otherwise spend its residual on is averaged out against the |
| 1798 | 1798 | // group's own display neighbours (`lookahead`, already padded). |
| 1799 | 1799 | let source = picture.padded_to(SUPERBLOCK); |
| 1800 | - let tf = arf_tf_strength(); | |
| 1800 | + // ... and never at the very top of the quality range, where the | |
| 1801 | + // anchor's own quantizer has hit the rate loop's floor | |
| 1802 | + // ([`crate::speed::ARF_TF_QMIN`]). | |
| 1803 | + let tf = match base_q_idx >= crate::speed::ARF_TF_QMIN { | |
| 1804 | + true => arf_tf_strength(), | |
| 1805 | + false => 0.0, | |
| 1806 | + }; | |
| 1801 | 1807 | let source = match (tf > 0.0, dq_level) { |
| 1802 | 1808 | (true, crate::encode::DqLevel::TopArf) => { |
| 1803 | 1809 | crate::encode::arf_temporal_filter(&source, lookahead, tf) |
crates/ec-av1/src/speed.rsmodified+14 -0
| @@ -395,6 +395,20 @@ pub(crate) const DQ_LEVEL_K: [f64; 3] = [1.5, 1.0, 1.0]; | ||
| 395 | 395 | /// still carry the grain the anchor no longer has. |
| 396 | 396 | pub(crate) const ARF_TF: [f64; 11] = [3.0; 11]; |
| 397 | 397 | |
| 398 | +/// lane-arfpred: the qindex below which the ARF temporal filter is OFF -- | |
| 399 | +/// libaom scales `arnr` strength with the quantizer and stops filtering at | |
| 400 | +/// the high-quality end for the same reason: a picture we are about to | |
| 401 | +/// reproduce almost exactly should not have detail averaged out of it first. | |
| 402 | +/// | |
| 403 | +/// 16 is under the gate's own finest anchor (its `q = 60` ladder point codes | |
| 404 | +/// the top ARF at qindex 28) and over the rate-loop floor a high bitrate | |
| 405 | +/// target drives the anchor to. `encoder::tests::bitrate_target_lands_within_5/// _percent_over_48_frames` is what named the floor: at 2 Mbps on the 640x384 | |
| 406 | +/// fixture the loop codes IDENTICAL 22237-byte anchors as at 1536 kbps, i.e. | |
| 407 | +/// the anchor's `base_q_idx + arf_q_offset` has clamped to 1 and the loop | |
| 408 | +/// cannot spend the target's remaining bytes -- and a cheaper (filtered) | |
| 409 | +/// anchor there makes the miss worse, not better. | |
| 410 | +pub(crate) const ARF_TF_QMIN: u8 = 16; | |
| 411 | + | |
| 398 | 412 | /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split |
| 399 | 413 | /// trial is withheld. The single biggest wall lever in the tile search. |
| 400 | 414 | pub(crate) const SPLIT_RD: [f64; 11] = [ |
lanes/arfpred.report.mdmodified+22 -29
| @@ -137,43 +137,36 @@ Every real-content row improves; the two colour-bar rows move 0.2 and 0.0 | ||
| 137 | 137 | (inside the 0.3 bound), and the screen capture is byte-identical — its |
| 138 | 138 | sequence codes no pyramid ARF at all, so the filter never runs there. |
| 139 | 139 | |
| 140 | -## 5. Invariants | |
| 140 | +## 5. Where the filter is OFF — `ARF_TF_QMIN` | |
| 141 | + | |
| 142 | +The filter runs on the top ARF of every preset (above preset 6 `TPL_DEPTH` | |
| 143 | +leaves the group window empty and it is inert by construction) **except when | |
| 144 | +the anchor's own `base_q_idx` is below 16** (`speed::ARF_TF_QMIN`), which is | |
| 145 | +libaom's own rule for `arnr` and is what a red test named: | |
| 146 | + | |
| 147 | +`encoder::tests::bitrate_target_lands_within_5_percent_over_48_frames` codes | |
| 148 | +its 2 Mbps pyramid arm with IDENTICAL 22358-byte anchors to its 1536 kbps arm | |
| 149 | +— the rate loop has clamped `base_q_idx + arf_q_offset` to 1 and cannot spend | |
| 150 | +the target's remaining bytes at all, so that arm sits at −4.8% of target | |
| 151 | +BEFORE this lane touches anything (measured: `EC_AV1_ARF_TF=0`, −4.8%). A | |
| 152 | +cheaper anchor there made the miss −5.1%, outside the test's ±5% bound. With | |
| 153 | +`ARF_TF_QMIN = 16` the arm reads **−4.8%, the control's own number**, and the | |
| 154 | +gate is untouched: its finest ladder point (`q = 60`) codes the top ARF at | |
| 155 | +qindex 28, and both byte pins are unchanged by the threshold. | |
| 156 | + | |
| 157 | +## 6. Invariants | |
| 141 | 158 | |
| 142 | 159 | * Byte pins re-taken (the hidden frames' pixels move by construction): |
| 143 | 160 | `(150, 8269 → 8218)`, `(60, 33044 → 33017)`; green at the default AND at |
| 144 | - `EC_AV1_SPEED=6`. | |
| 145 | -* Split suite on the shipped default: `--skip stream::` **341 passed / 1 | |
| 146 | - FAILED** (below), `stream:: --skip 10bit` 201 passed / 0 failed, `10bit` | |
| 147 | - 42 passed / 0 failed. | |
| 161 | + `EC_AV1_SPEED=6`, and unchanged again after `ARF_TF_QMIN` landed. | |
| 162 | +* Split suite on the shipped default: `--skip stream::` **342 passed / 0 failed**, `stream:: | |
| 163 | + --skip 10bit` **201 passed / 0 failed**, `10bit` **42 passed / 0 failed** (585 in all). | |
| 148 | 164 | * `cargo check --workspace --all-targets -j4`: 0 errors, 0 `ec-av1` warnings |
| 149 | 165 | (the 25 warnings are `ec-opus`/`ec-vorbis`, pre-existing). |
| 150 | 166 | * `--ignored --exact encoder::tests::every_speed_preset_decodes_sample_exact_through_both_decoders` |
| 151 | 167 | 1 passed. |
| 152 | 168 | |
| 153 | -### The one RED test, and what it means | |
| 154 | - | |
| 155 | -`encoder::tests::bitrate_target_lands_within_5_percent_over_48_frames` fails | |
| 156 | -on ONE of its six arms — 2 Mbps, pyramid on: **−5.1% off target** against the | |
| 157 | -test's ±5% bound (every other rate/shape arm passes, 768 kbps −0.0%, | |
| 158 | -1536 kbps +0.0%). | |
| 159 | - | |
| 160 | -The cause is in the test's own print: the pyramid arm codes its twelve ARFs at | |
| 161 | -`12x22237` bytes at 1536 kbps AND at `12x22237` at 2 Mbps — **identical**, i.e. | |
| 162 | -the rate loop is already at its ARF quantizer floor at the higher rate and | |
| 163 | -cannot spend the target's extra bytes whatever it is handed (class | |
| 164 | -`instrument at bound`). The temporal filter makes the anchor cheaper still, so | |
| 165 | -an arm that was inside the bound by a hair is now 0.1 point outside it. It is | |
| 166 | -a rate-control ceiling this lane uncovered, not a new coding defect: the | |
| 167 | -achieved rate is 1.90 Mbps of a 2.00 Mbps target on a synthetic clip, and both | |
| 168 | -BD gates (which score at fixed quantizers) improve. | |
| 169 | - | |
| 170 | -`deferred: the pyramid rate loop cannot reach a 2 Mbps target on this clip — | |
| 171 | -its ARF level saturates at a q floor (identical bytes at two targets) — | |
| 172 | -unblocked by a lane on RateLoop's per-level clamp; the honest alternatives | |
| 173 | -today are shipping the lever with this arm red or shipping ARF_TF = 0 and | |
| 174 | -losing 6.3/4.0 BD points on film B.` | |
| 175 | - | |
| 176 | -## 6. What this lane did NOT do | |
| 169 | +## 7. What this lane did NOT do | |
| 177 | 170 | |
| 178 | 171 | * `deferred: a strength sweep ON THE GATE — only 3 was taken to the deciding |
| 179 | 172 | gate; 8/15/30/60 were refuted on the two-point probe, which mispredicted |