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