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 commit5c168bf7d7aadb5fdf0131de93f0f74601a6148cParent: 96338e51 changed file +10 -3
crates/ec-av1/src/encoder/mod.rsmodified+10 -3
| @@ -125,6 +125,7 @@ impl RateTarget { | ||
| 125 | 125 | /// (`None` for the two open-loop variants). `mini_gop` is `Some` in |
| 126 | 126 | /// pyramid mode, which is what makes the loop keep a quantizer per level. |
| 127 | 127 | fn into_loop(self, config: &mut EncoderConfig, pyramid: Option<Pyramid>) -> Option<RateLoop> { |
| 128 | + let repay = matches!(self, RateTarget::Bitrate { .. }); | |
| 128 | 129 | let target_bytes = match self { |
| 129 | 130 | RateTarget::QIndex(q) => { |
| 130 | 131 | config.base_q_idx = q; |
| @@ -140,12 +141,14 @@ impl RateTarget { | ||
| 140 | 141 | frames_per_second, |
| 141 | 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 | 145 | target_bytes, |
| 145 | 146 | f64::from(config.base_q_idx), |
| 146 | 147 | pyramid, |
| 147 | 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 | 271 | /// a level held at its bound hands its unspent bytes to the others, but |
| 269 | 272 | /// no level's target may exceed this many times its own opening share. |
| 270 | 273 | scale0: f64, |
| 274 | + repay: bool, | |
| 271 | 275 | /// `EC_AV1_RL_CENSUS=1`: one line per coded frame on stderr. |
| 272 | 276 | census: bool, |
| 273 | 277 | coded: usize, |
| @@ -350,6 +354,7 @@ impl RateLoop { | ||
| 350 | 354 | left_bytes: target_bytes * gop.max(1) as f64, |
| 351 | 355 | plans, |
| 352 | 356 | scale0: scale, |
| 357 | + repay: true, | |
| 353 | 358 | census: census_on(), |
| 354 | 359 | coded: 0, |
| 355 | 360 | } |
| @@ -445,7 +450,9 @@ impl RateLoop { | ||
| 445 | 450 | ); |
| 446 | 451 | self.coded += 1; |
| 447 | 452 | } |
| 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 | + } | |
| 449 | 456 | } |
| 450 | 457 | |
| 451 | 458 | /// Re-plans the REST OF THE RUN from what it has actually spent: the |