diff --git a/crates/ec-av1/src/encoder/mod.rs b/crates/ec-av1/src/encoder/mod.rs index 494d4318..e319a9a6 100644 --- a/crates/ec-av1/src/encoder/mod.rs +++ b/crates/ec-av1/src/encoder/mod.rs @@ -125,6 +125,7 @@ impl RateTarget { /// (`None` for the two open-loop variants). `mini_gop` is `Some` in /// pyramid mode, which is what makes the loop keep a quantizer per level. fn into_loop(self, config: &mut EncoderConfig, pyramid: Option) -> Option { + let repay = matches!(self, RateTarget::Bitrate { .. }); let target_bytes = match self { RateTarget::QIndex(q) => { config.base_q_idx = q; @@ -140,12 +141,14 @@ impl RateTarget { frames_per_second, } => f64::from(bits_per_second) / 8.0 / frames_per_second.max(1.0), }; - Some(RateLoop::new( + let mut rate_loop = RateLoop::new( target_bytes, f64::from(config.base_q_idx), pyramid, config.gop, - )) + ); + rate_loop.repay = repay; + Some(rate_loop) } } @@ -268,6 +271,7 @@ struct RateLoop { /// a level held at its bound hands its unspent bytes to the others, but /// no level's target may exceed this many times its own opening share. scale0: f64, + repay: bool, /// `EC_AV1_RL_CENSUS=1`: one line per coded frame on stderr. census: bool, coded: usize, @@ -350,6 +354,7 @@ impl RateLoop { left_bytes: target_bytes * gop.max(1) as f64, plans, scale0: scale, + repay: true, census: census_on(), coded: 0, } @@ -445,7 +450,9 @@ impl RateLoop { ); self.coded += 1; } - self.replan(level, slot, offset, frame_weight, actual_bytes as f64); + if self.repay { + self.replan(level, slot, offset, frame_weight, actual_bytes as f64); + } } /// Re-plans the REST OF THE RUN from what it has actually spent: the