[XviD-devel] 2nd-pass ratecontrol (connects to VBV)

Christoph Lampert chl at math.uni-bonn.de
Mon May 10 13:59:41 CEST 2004


On Mon, 10 May 2004, Edouard Gomez wrote:

> Quoting Christoph Lampert <chl at math.uni-bonn.de>:
> > who wrote the 2nd pass ratecontrol stuff (the part keeping track of
> > overflow and correcting quantizers)? I'd like to modify some stuff for VBV
> > compliancy and it might be easier when in direct contact with the
> > original author (I hope it wasn't me, at least I don't remember &-> )
> 
> For the plugin code, you can ask either pete or me (he ported it to core
> and then i did some deep changes).

Okay, so: Current corrections are good for filesize, but for VBV compliance, 
there must a another level of correction, which keeps track of buffer fill 
and scales the frames if the buffer comes close to running empty (can only 
happen if actual framesizes are larger than in scaled curve). 
In 2pass, the curve is scaled to never empty the buffer to less than 10% 
of total, which unfortunately typically is only 38kB. So for high quality 
encodings, the step from 10% to 0% isn't much, possibly only a few frames 
with too large size. So, there's kind of a dilemma: Either we follow the 
scaled curve, and only react if the buffer runs below e.g. 10%, but then 
we have to act fast. Or we start correcting above that value but that 
lowers quality although we don't even know yet if it's needed. 
An alternative would be to keep track of how much actual framesizes 
differs from predicted/scaled one, and react later if that is a good match 
(or too small), and earlier if they tend to be larger than expected. 
Or, best would be to save the "intended buffer fill" into the 2pass file 
and correct based on that. 

But for a start, I would suggest to just do #1 and see what happens: 
Keep track of buffer fill, if that runs below 10%, correct the next frame 
quant by some factor. Now, it's important that the quant to be corrected 
is derived only from scaled curve, and previous overflow/underflow of 
total filesize is ignored, because we really have to stay close to the 
scaled track in order to avoid VBV underflows. 
My suggestion for that would be to simply switch off all totalsize 
overflow corrections if VBV buffer runs below 50% or so. This doesn't 
happen very often, maybe in a few hundred frames per movie, so it 
shouldn't influence total size. It would however be bad if there is a 
systematic error in framesize prediction, e.g. everything 10% too large 
during some scenes, because then there could be a quality drop. 

Do you have any numbers on how much 2nd-pass corrections usually modifies 
framesizes/quants?

> NB: i noticed you commited to dev-api-4 branch. Please use CVS head to add
>     new features, dev-api-4 has been declared "dead branch" 

Did I? I didn't intend to.  I guess my old CVS config was somehow garbled,
sorry.  Should I recommit? Or wait till RC works better.

chl


More information about the XviD-devel mailing list