From a5f823fb95b658e2c02b51d8d96d7279d332473a 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 12:40:26 +0300 Subject: [PATCH] ec-av1 RateLoop::update: do not lower q on a tiny frame (actual < target/4). Root cause: the 48-frame 384 kbps gate's fade (n=36..44, actual 818,799,41,452,193,76,278,125,50 vs targets 1.7k-4.5k) stepped q down by STEP_CLAMP each frame to q=1 (census base_q 61.6->1.6->0.0); the scene cut at n=45..47 then coded at raw_q 1 for 9619,9338,6085 bytes, the whole +7.4% overshoot (103132 vs 96000). Fix: a frame under target/TINY_FRAME_DIVISOR (4) carries no slope information, so a negative step is held at 0; q may still rise. Census reasoning: n=38..44 held at eff_q 50, n=45 coded near q 50 instead of 1. Not run; orchestrator to verify with the 48-frame gate. --- crates/ec-av1/src/encoder/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ec-av1/src/encoder/mod.rs b/crates/ec-av1/src/encoder/mod.rs index 21c12c9a..eb3b9068 100644 --- a/crates/ec-av1/src/encoder/mod.rs +++ b/crates/ec-av1/src/encoder/mod.rs @@ -298,6 +298,7 @@ impl RateLoop { /// target), which is how the first cut of this fix froze every level of a /// run at whatever quantizer it had reached. const REPLAN_FLOOR: f64 = 0.25; + const TINY_FRAME_DIVISOR: f64 = 4.0; 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 @@ -437,6 +438,10 @@ impl RateLoop { } else { raw }; + let step = match ratio < 1.0 / Self::TINY_FRAME_DIVISOR && step < 0.0 { + true => 0.0, + false => step, + }; self.q[slot] = (self.q[slot] + step).clamp(0.0, 255.0); let bound = !(1..=255).contains(&raw_q); if let Some(plan) = self