From f61cd974c015e2649a9e24e7cb6804db690ca27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 10:05:51 +0300 Subject: [PATCH] ec-av1 rate loop: flat path key frame no longer slams shared q 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.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/ec-av1/src/encoder/mod.rs b/crates/ec-av1/src/encoder/mod.rs index dce7801a..bfb0d87a 100644 --- a/crates/ec-av1/src/encoder/mod.rs +++ b/crates/ec-av1/src/encoder/mod.rs @@ -226,7 +226,7 @@ impl LevelPlan { /// cannot build a debt a later transient has to repay; each frame's step is /// bounded by `STEP_CLAMP` regardless of history. /// -/// In pyramid mode the state is kept PER LEVEL: each frame's size is +/// The state is kept PER LEVEL, flat path included: each frame's size is /// predicted from the previous frame of its own level, against that level's /// own share of the budget, which is the whole "two-pass-free model" this /// encoder carries. @@ -297,11 +297,7 @@ impl RateLoop { fn new(target_bytes: f64, start_q: f64, pyramid: Option, gop: usize) -> Self { // THE LEVEL MODEL. Every coded frame of the run is priced by its own // q offset through `WEIGHT_LEVEL_GAIN`, in units of one leaf, and the - // run's `gop` frame targets are shared out in those units. The flat - // path is the same run with no hidden levels and no offsets, so the - // key frame is budgeted against the GOP there too: its overshoot is - // re-planned over the leaves, never slammed into their shared `q`. - // The old pyramid model priced a group as "one hidden frame worth + // run's `gop` frame targets are shared out in those units. The old pyramid model priced a group as "one hidden frame worth // `ARF_WEIGHT` = 2 leaves plus `m - 1` leaves", which was wrong twice // over and the two errors cancelled (lane-pyr6): the group has coded // TWO hidden frames since the mid level landed (four with @@ -372,8 +368,6 @@ impl RateLoop { .position(|p| p.is_some_and(|p| p.slot == slot && (slot != 1 || p.offset == offset))) } - /// Which controller a level uses: the key, the hidden ARF levels and the - /// leaves each steer their own `q`. fn slot(&self, level: Level) -> usize { match level { Level::Key => 0,