forge
Explore
Log in

Don't you dare go Hollow

ec-av1 rate loop: flat path key frame no longer slams shared q

Browse files at this commit

f61cd974c015e2649a9e24e7cb6804db690ca27bAhmet Kaan GümüşParent: 4b94175
Root cause: RateLoop::slot() returned 0 for every level on the flat path,
so the key frame's unclamped seed step drove the single q to 255 and inter
frames ramped back at STEP_CLAMP (12/frame). Fix: flat path runs the same
per-level plan as the pyramid (key slot 0, leaf slot 2, gop budget, replan).
gop=1 and pyramid output unchanged. Comments removed, struct doc updated.
Tests not run here; orchestrator to verify against ffmpeg 9.0.2.
crates/ec-av1/src/encoder/mod.rsmodified+2 -8
@@ -226,7 +226,7 @@ impl LevelPlan {
226226 /// cannot build a debt a later transient has to repay; each frame's step is
227227 /// bounded by `STEP_CLAMP` regardless of history.
228228 ///
229-/// In pyramid mode the state is kept PER LEVEL: each frame's size is
229+/// The state is kept PER LEVEL, flat path included: each frame's size is
230230 /// predicted from the previous frame of its own level, against that level's
231231 /// own share of the budget, which is the whole "two-pass-free model" this
232232 /// encoder carries.
@@ -297,11 +297,7 @@ impl RateLoop {
297297 fn new(target_bytes: f64, start_q: f64, pyramid: Option<Pyramid>, gop: usize) -> Self {
298298 // THE LEVEL MODEL. Every coded frame of the run is priced by its own
299299 // q offset through `WEIGHT_LEVEL_GAIN`, in units of one leaf, and the
300- // run's `gop` frame targets are shared out in those units. The flat
301- // path is the same run with no hidden levels and no offsets, so the
302- // key frame is budgeted against the GOP there too: its overshoot is
303- // re-planned over the leaves, never slammed into their shared `q`.
304- // The old pyramid model priced a group as "one hidden frame worth
300+ // run's `gop` frame targets are shared out in those units. The old pyramid model priced a group as "one hidden frame worth
305301 // `ARF_WEIGHT` = 2 leaves plus `m - 1` leaves", which was wrong twice
306302 // over and the two errors cancelled (lane-pyr6): the group has coded
307303 // TWO hidden frames since the mid level landed (four with
@@ -372,8 +368,6 @@ impl RateLoop {
372368 .position(|p| p.is_some_and(|p| p.slot == slot && (slot != 1 || p.offset == offset)))
373369 }
374370
375- /// Which controller a level uses: the key, the hidden ARF levels and the
376- /// leaves each steer their own `q`.
377371 fn slot(&self, level: Level) -> usize {
378372 match level {
379373 Level::Key => 0,