Keep the rate loop's one-hidden-frame group split
Browse files at this commit84491e128f82d48728723ae94c32a0d1148e0b93Parent: d47ee71- fix
- keep the rate loop's one-hidden-frame group split
2 changed files +33 -19
- crates/ec-av1/src/encoder.rs +15 -19
- lanes/pyr6.sweep.txt +18 -0
crates/ec-av1/src/encoder.rsmodified+15 -19
| @@ -234,13 +234,21 @@ impl RateLoop { | |||
| 234 | false => target_bytes, | 234 | false => target_bytes, |
| 235 | }; | 235 | }; |
| 236 | // A group of `m` pictures gets `m * rest`, split one `ARF_WEIGHT` | 236 | // A group of `m` pictures gets `m * rest`, split one `ARF_WEIGHT` |
| 237 | - // share to EACH of its `h` hidden frames and one each to the `m - h` | 237 | + // share to the hidden frame and one each to the `m - 1` leaves, so |
| 238 | - // leaves, so the group's own average is `rest` exactly. `h` is the | 238 | + // the group's own average is `rest` exactly. |
| 239 | - // pyramid's depth, not 1: a four-level group of eight codes four | 239 | + // |
| 240 | - // hidden frames, and pricing that group as one ARF plus seven leaves | 240 | + // ONE hidden frame, deliberately, even though the group has coded two |
| 241 | - // gave the ARF slot a target its four frames could not share. | 241 | + // since the mid level landed (and four with |
| 242 | - let h = p.hidden_per_group(gop); | 242 | + // [`Pyramid::quarter_q_offset`] on). Pricing the real count |
| 243 | - let share = rest * m / (m - h + h * ARF_WEIGHT); | 243 | + // (`m / (m - h + h * ARF_WEIGHT)`, h = 2) is the truthful model and |
| 244 | + // it lands the 48-frame bitrate gate -9.4% / -14.9% under target | ||
| 245 | + // against this line's -1.8% / -6.3%: the h = 1 split over-allocates | ||
| 246 | + // the group by exactly the amount `ARF_WEIGHT` under-prices a hidden | ||
| 247 | + // frame, and the two errors cancel. Fixing the split alone therefore | ||
| 248 | + // makes the loop WORSE; `ARF_WEIGHT` has to be recalibrated in the | ||
| 249 | + // same diff, which is a rate-control lane, not a pyramid-shape one | ||
| 250 | + // (lane-pyr6, `lanes/pyr6.sweep.txt`). | ||
| 251 | + let share = rest * m / (m - 1.0 + ARF_WEIGHT); | ||
| 244 | Self { | 252 | Self { |
| 245 | target: [target_bytes * key, share * ARF_WEIGHT, share], | 253 | target: [target_bytes * key, share * ARF_WEIGHT, share], |
| 246 | q: [start_q; 3], | 254 | q: [start_q; 3], |
| @@ -503,18 +511,6 @@ impl Pyramid { | |||
| 503 | }, | 511 | }, |
| 504 | }) | 512 | }) |
| 505 | } | 513 | } |
| 506 | - | ||
| 507 | - /// How many hidden frames a FULL mini-GOP of this shape codes, in a run | ||
| 508 | - /// of `gop` pictures: the top ARF, plus the mid one and the two | ||
| 509 | - /// quarter-point ones when they are switched on. Mirrors the gating in | ||
| 510 | - /// [`Av1Encoder::drain_pending`] -- the rate loop prices the group from | ||
| 511 | - /// it ([`RateLoop::new`]), so the two must move together. | ||
| 512 | - fn hidden_per_group(&self, gop: usize) -> f64 { | ||
| 513 | - let long_run = gop > self.mini_gop + self.mini_gop / 2; | ||
| 514 | - let mid = long_run && self.mid_q_offset.is_some() && self.mini_gop >= 4; | ||
| 515 | - let quarters = mid && self.quarter_q_offset.is_some() && self.mini_gop >= 8; | ||
| 516 | - 1.0 + f64::from(mid) + 2.0 * f64::from(quarters) | ||
| 517 | - } | ||
| 518 | } | 514 | } |
| 519 | 515 | ||
| 520 | impl Default for Pyramid { | 516 | impl Default for Pyramid { |
lanes/pyr6.sweep.txtmodified+18 -0
| @@ -57,3 +57,21 @@ So the depth lever is spent at THIS group size: our per-hidden-frame overhead, n | |||
| 57 | level count, is what separates us from rav1e's 23-hidden-per-48 shape. The code stays | 57 | level count, is what separates us from rav1e's 23-hidden-per-48 shape. The code stays |
| 58 | in (six-field EC_AV1_PYRAMID, slot map documented, round trip gated) so the next lane | 58 | in (six-field EC_AV1_PYRAMID, slot map documented, round trip gated) so the next lane |
| 59 | can re-measure it the moment a hidden frame gets cheaper. | 59 | can re-measure it the moment a hidden frame gets cheaper. |
| 60 | + | ||
| 61 | +## the rate loop: the truthful group split makes it WORSE (kept at h = 1) | ||
| 62 | +`RateLoop::new` splits a group's byte budget as one `ARF_WEIGHT` share plus `m - 1` | ||
| 63 | +leaf shares -- a model from when the pyramid had ONE hidden frame per group. Extending | ||
| 64 | +it to the real count (`m / (m - h + h * ARF_WEIGHT)`, h = 2 with the mid level, 4 with | ||
| 65 | +quarters) is the truthful model and it FAILS the 48-frame bitrate gate: | ||
| 66 | + | ||
| 67 | +| model | 768 kbps, pyramid | 1536 kbps, pyramid | | ||
| 68 | +|---|---|---| | ||
| 69 | +| h = 1 (main, kept) | -1.8% | -6.3% | | ||
| 70 | +| h = real hidden count | -9.4% | -14.9% (gate limit 10%) | | ||
| 71 | + | ||
| 72 | +The h = 1 split over-allocates a group by exactly what `ARF_WEIGHT` = 2.0 under-prices a | ||
| 73 | +hidden frame at, and the two errors cancel; fixing one alone un-cancels them. So the | ||
| 74 | +extension was REVERTED and the coupling documented at the line -- recalibrating | ||
| 75 | +`ARF_WEIGHT` belongs to a rate-control lane, not to a pyramid-shape one. deferred: | ||
| 76 | +truthful group split + ARF_WEIGHT recalibration -- needs the bitrate gate as its own | ||
| 77 | +keep rule -- unblocked by a rate lane. | ||