forge
Explore
Log in

Don't you dare go Hollow

ec-av1 rate loop: steer on the geometric mean of the last two size ratios per slot. Evidence (c-round3-full.log sizes 4176,2073,4776,2183,3861,...): a 0.77 q step cannot move a frame 4176->2073, so the swing is inter-frame coupling (a big frame leaves a good reference, the next is small), not q slope; per-frame steering chases it as a decaying period-2 cycle that biases the mean low. Averaging log-ratios over two frames cancels the alternating component. BytesPerFrame repay=false kept; Bitrate +7.4% not separately root-caused (no census run permitted); replan still repays. cargo check -p ec-av1 --all-targets clean; tests left to orchestrator

Browse files at this commit

d6f79ca28233001e125ebd153e3efb0704530258Ahmet Kaan GümüşParent: 5c168bf
crates/ec-av1/src/encoder/mod.rsmodified+11 -2
@@ -243,6 +243,7 @@ struct RateLoop {
243 /// FIRST update of a slot is the seeding one and takes the model's whole243 /// FIRST update of a slot is the seeding one and takes the model's whole
244 /// step ([`RateLoop::update`]); every later one is clamped.244 /// step ([`RateLoop::update`]); every later one is clamped.
245 seeded: [bool; 3],245 seeded: [bool; 3],
246+ prev_ratio: [f64; 3],
246 /// The leaf's own q offset: the zero of the level weight247 /// The leaf's own q offset: the zero of the level weight
247 /// ([`WEIGHT_LEVEL_GAIN`]), so slot 1's target can be read in248 /// ([`WEIGHT_LEVEL_GAIN`]), so slot 1's target can be read in
248 /// LEAF-EQUIVALENT bytes and scaled per frame by that frame's offset.249 /// LEAF-EQUIVALENT bytes and scaled per frame by that frame's offset.
@@ -355,6 +356,7 @@ impl RateLoop {
355 plans,356 plans,
356 scale0: scale,357 scale0: scale,
357 repay: true,358 repay: true,
359+ prev_ratio: [1.0; 3],
358 census: census_on(),360 census: census_on(),
359 coded: 0,361 coded: 0,
360 }362 }
@@ -422,8 +424,15 @@ impl RateLoop {
422 // step and seeds `q` where the log-linear slope says it belongs; from424 // step and seeds `q` where the log-linear slope says it belongs; from
423 // the second frame on the clamp is back, and nothing is accumulated425 // the second frame on the clamp is back, and nothing is accumulated
424 // between frames, so [[vorbis-rate-loop-windup]]'s bound still holds.426 // between frames, so [[vorbis-rate-loop-windup]]'s bound still holds.
425- let raw = ratio.ln() * Self::GAIN;427+ let seeded = std::mem::replace(&mut self.seeded[slot], true);
426- let step = if std::mem::replace(&mut self.seeded[slot], true) {428+ let smoothed = if seeded {
429+ (ratio * self.prev_ratio[slot]).sqrt()
430+ } else {
431+ ratio
432+ };
433+ self.prev_ratio[slot] = ratio;
434+ let raw = smoothed.ln() * Self::GAIN;
435+ let step = if seeded {
427 raw.clamp(-Self::STEP_CLAMP, Self::STEP_CLAMP)436 raw.clamp(-Self::STEP_CLAMP, Self::STEP_CLAMP)
428 } else {437 } else {
429 raw438 raw