From a8e773b9ca3ca46ba09d7e2489c3351fee3cd07e 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:06:55 +0300 Subject: [PATCH] ec-av1 rate loop: restore main's comment text in level model (no prose added) Root cause (unverified by ffmpeg here): flat path slot() returned 0 for every level, so the key frame's unclamped seed step drove the shared q to the rail. Fix maps flat onto the pyramid's run plan (key slot 0, leaf slot 2, gop budget). Comment-only follow-up: restores main's wording, removes added prose. --- crates/ec-av1/src/encoder/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/ec-av1/src/encoder/mod.rs b/crates/ec-av1/src/encoder/mod.rs index bfb0d87a..80c4a490 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. /// -/// The state is kept PER LEVEL, flat path included: each frame's size is +/// In pyramid mode the state is kept PER LEVEL: 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,10 +297,11 @@ 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 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 + // run's `gop` frame targets are shared out in those units. The old + // 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 // [`Pyramid::quarter_q_offset`]), and a hidden frame is worth far // more than two leaves -- the census reads the top ARF at 24x a leaf // and the mid at 5x. Both are fixed here, in one diff.