Bitrate mode coded the first frame four times with a fixed gain. Now the
first pass still gets the old correction (30 quantizer steps per halving
of the size, which fits the starting range), and from the second
correction on the next quantizer is placed in the log domain of the
quantizer step, where the frame size is close to a line: false position
between the nearest passes that enclose the target, otherwise a secant
step with the measured slope. The search stops as soon as the size is
within 3 % of the target, when no untried quantizer is left between the
enclosing passes, or when it would repeat a quantizer (a target the
content cannot reach, where the old code coded the same frame at the
lowest quantizer up to four times). At most four passes remain.
The first frame is within 3 % of the target on the same cells as before
and nearer to it on most of the others; two cells where the size jumps
by a factor of 4 or more between neighbouring quantizers (noisy content)
land further away than with the old search. Total passes over the 28
test cells: 112 -> 70.
Part of #2390
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Bitrate mode gave key frames keyint-dependent extra bits (about 6.8 frame
budgets at the 60 frame default) but left the inter frames at the full
frame budget, so every group of frames overshot by (boost - 1) / keyint,
9.6 % at keyint 60 (up to +187 % at keyint 5 on some content). The
accumulated deviation was tracked against the boosted budget, so the
feedback never saw it.
Now a group of keyint frames adds up to keyint * frame budget: inter
frames get (keyint - boost) / (keyint - 1) of it. Further changes to the
frame level control:
- The quantizer follows the size error with a measured slope (quantizer
steps per halving of the size, taken from consecutive inter frames)
instead of a fixed 12 steps per doubling. On noisy content the curve is
several times steeper than that and the old gain oscillated between
1 kB and 42 kB frames.
- Key frames have their own quantizer offset, adapted from key frame
sizes only, instead of feeding the key frame error into the inter
quantizer. A key frame after the first that misses its budget by more
than 19 % is coded again (at most twice more), with a corrected
quantizer found in the log domain of the quantizer step.
- A deviation from the budget is paid back over 16 frames, bounded to
0.35x..2x of the budget.
Constant quantizer mode is untouched (byte identical output). The
encoded stream in bitrate mode changes.
Adds a test that the rate stays within 5 % of the target over 180
frames for three 8 bit and one 10 bit setting.
Part of #2391
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>