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+9 -2
@@ -125,6 +125,7 @@ impl RateTarget {
125 /// (`None` for the two open-loop variants). `mini_gop` is `Some` in125 /// (`None` for the two open-loop variants). `mini_gop` is `Some` in
126 /// pyramid mode, which is what makes the loop keep a quantizer per level.126 /// pyramid mode, which is what makes the loop keep a quantizer per level.
127 fn into_loop(self, config: &mut EncoderConfig, pyramid: Option<Pyramid>) -> Option<RateLoop> {127 fn into_loop(self, config: &mut EncoderConfig, pyramid: Option<Pyramid>) -> Option<RateLoop> {
128+ let repay = matches!(self, RateTarget::Bitrate { .. });
128 let target_bytes = match self {129 let target_bytes = match self {
129 RateTarget::QIndex(q) => {130 RateTarget::QIndex(q) => {
130 config.base_q_idx = q;131 config.base_q_idx = q;
@@ -140,12 +141,14 @@ impl RateTarget {
140 frames_per_second,141 frames_per_second,
141 } => f64::from(bits_per_second) / 8.0 / frames_per_second.max(1.0),142 } => f64::from(bits_per_second) / 8.0 / frames_per_second.max(1.0),
142 };143 };
143- Some(RateLoop::new(144+ let mut rate_loop = RateLoop::new(
144 target_bytes,145 target_bytes,
145 f64::from(config.base_q_idx),146 f64::from(config.base_q_idx),
146 pyramid,147 pyramid,
147 config.gop,148 config.gop,
148- ))149+ );
150+ rate_loop.repay = repay;
151+ Some(rate_loop)
149 }152 }
150 }153 }
151 154
@@ -268,6 +271,7 @@ struct RateLoop {
268 /// a level held at its bound hands its unspent bytes to the others, but271 /// a level held at its bound hands its unspent bytes to the others, but
269 /// no level's target may exceed this many times its own opening share.272 /// no level's target may exceed this many times its own opening share.
270 scale0: f64,273 scale0: f64,
274+ repay: bool,
271 /// `EC_AV1_RL_CENSUS=1`: one line per coded frame on stderr.275 /// `EC_AV1_RL_CENSUS=1`: one line per coded frame on stderr.
272 census: bool,276 census: bool,
273 coded: usize,277 coded: usize,
@@ -350,6 +354,7 @@ impl RateLoop {
350 left_bytes: target_bytes * gop.max(1) as f64,354 left_bytes: target_bytes * gop.max(1) as f64,
351 plans,355 plans,
352 scale0: scale,356 scale0: scale,
357+ repay: true,
353 census: census_on(),358 census: census_on(),
354 coded: 0,359 coded: 0,
355 }360 }
@@ -445,8 +450,10 @@ impl RateLoop {
445 );450 );
446 self.coded += 1;451 self.coded += 1;
447 }452 }
453+ if self.repay {
448 self.replan(level, slot, offset, frame_weight, actual_bytes as f64);454 self.replan(level, slot, offset, frame_weight, actual_bytes as f64);
449 }455 }
456+ }
450 457
451 /// Re-plans the REST OF THE RUN from what it has actually spent: the458 /// Re-plans the REST OF THE RUN from what it has actually spent: the
452 /// level model says how the budget SPLITS, and nothing but a measurement459 /// level model says how the budget SPLITS, and nothing but a measurement