forge
Explore
Log in

Don't you dare go Hollow

ec-av1 rate: BytesPerFrame no longer replans. Root cause of settled mean 3102 vs 4000: RateLoop::replan re-solves target = left_bytes/left_weight after every frame, so the key overshoot (22289-4000) was repaid over the remaining 23 frames, target ~3200 (observed 2950-3100). BytesPerFrame now keeps its fixed per-frame target (repay=false); Bitrate keeps the budget-remaining replan. cargo check -p ec-av1 --all-targets clean; tests left to orchestrator

Browse files at this commit

5c168bf7d7aadb5fdf0131de93f0f74601a6148cAhmet Kaan GümüşParent: 96338e5
crates/ec-av1/src/encoder/mod.rsmodified+10 -3
@@ -125,6 +125,7 @@ impl RateTarget {
125125 /// (`None` for the two open-loop variants). `mini_gop` is `Some` in
126126 /// pyramid mode, which is what makes the loop keep a quantizer per level.
127127 fn into_loop(self, config: &mut EncoderConfig, pyramid: Option<Pyramid>) -> Option<RateLoop> {
128+ let repay = matches!(self, RateTarget::Bitrate { .. });
128129 let target_bytes = match self {
129130 RateTarget::QIndex(q) => {
130131 config.base_q_idx = q;
@@ -140,12 +141,14 @@ impl RateTarget {
140141 frames_per_second,
141142 } => f64::from(bits_per_second) / 8.0 / frames_per_second.max(1.0),
142143 };
143- Some(RateLoop::new(
144+ let mut rate_loop = RateLoop::new(
144145 target_bytes,
145146 f64::from(config.base_q_idx),
146147 pyramid,
147148 config.gop,
148- ))
149+ );
150+ rate_loop.repay = repay;
151+ Some(rate_loop)
149152 }
150153 }
151154
@@ -268,6 +271,7 @@ struct RateLoop {
268271 /// a level held at its bound hands its unspent bytes to the others, but
269272 /// no level's target may exceed this many times its own opening share.
270273 scale0: f64,
274+ repay: bool,
271275 /// `EC_AV1_RL_CENSUS=1`: one line per coded frame on stderr.
272276 census: bool,
273277 coded: usize,
@@ -350,6 +354,7 @@ impl RateLoop {
350354 left_bytes: target_bytes * gop.max(1) as f64,
351355 plans,
352356 scale0: scale,
357+ repay: true,
353358 census: census_on(),
354359 coded: 0,
355360 }
@@ -445,7 +450,9 @@ impl RateLoop {
445450 );
446451 self.coded += 1;
447452 }
448- self.replan(level, slot, offset, frame_weight, actual_bytes as f64);
453+ if self.repay {
454+ self.replan(level, slot, offset, frame_weight, actual_bytes as f64);
455+ }
449456 }
450457
451458 /// Re-plans the REST OF THE RUN from what it has actually spent: the