[Ffmpeg-devel] ratecontrol advice

Loren Merritt lorenm
Tue May 10 09:55:44 CEST 2005


On Tue, 10 May 2005, Matthew Hodgson wrote:

> I'm trying to use libavcodec to 1-pass encode an h.263 stream which has 
> limits on both the maximum size-per-picture and total datarate.  I can't work 
> out what the right way is to respect both limitations using the ratecontrol 
> settings, whilst maintaining the best possible QP for any given frame (so 
> long as it doesn't end up larger than X bytes - or push the total datarate 
> for over Y kbits/s).
>
> I assume I can do this with a custom rc_eq formula and/or adjusting qcompress 
> - but I can't see an obvious formula for capping the picture-size. 
> Alternatively, is there another way to force ffmpeg to adjust the qp so that 
> pictures are never larger than a given size?
>
> Any suggestions would be very much appreciated indeed :)

You can't cap per-frame bits using rceq, because rceq is unitless. lavc 
will multiply the output of rceq by whatever factor it takes to fill up 
your desired average bitrate.
But if you don't mind modifying a few lines of code, look in 
modify_qscale() line 435 or so. Currently that limits per-frame bits based 
on the number of bits left in the VBV buffer; you could put in your own 
cap similarly.
(Warning: anything done by a 1pass encode will be an approximate/soft 
limit, since you don't know in advance excatly how many bits a given QP 
will take. So you'll need to fudge the limit a little if you care about 
strict compliance.)

--Loren Merritt





More information about the ffmpeg-devel mailing list