# [Ffmpeg-devel] ratecontrol experimentation

Corey Hickey bugfood-ml
Tue Feb 14 07:20:24 CET 2006

```On Mon, February 13, 2006 20:48, Loren Merritt wrote:
>> I've been messing around with ratecontrol and analysis thereof. The
>> results don't really fit well in an email, so I put together a small web
>> page.
>>
>> http://fatooh.org/ratecontrol/
>>
>> I'd appreciate any feedback. I'm starting to have good results, and some
>> suggestions might point me in the right direction for even better results.
>
> Can pTex serve the same purpose as mcVar?

I don't know, so if you think it can you'll have to explain it to me. :)

The "tex" in the ratecontrol equation appears to be the combination of iTex
and pTex.

(rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale

> In 2pass.log I see mc-var on the same order of magnitude as *tex
> (depending on quantizer). The value of mcVar seen by the vrc_eq is
> (mc-var / mb_num) where mb_num=880 at your resolution.

Yeah; that caught me up initially; it turned out that even after multiplying
mcVar by 10^3, there was very little change. So, I tried successively higher
powers of 10 until I got what I wanted. I was rather surprised by how high I

> 10^8 should still by 10^5 times bigger than tex, and make the equation
> equivalent to vrc_eq="mcVar^qComp". Which is a valid choice, but is it
> what you meant?

I suppose having tex in there is nearly irrelevant at this point, but it
does seem to make a slight difference. I just tested the following on a
small test file:

(1) mcVar^qComp
(2) (10^8*mcVar)^qComp
(3) (tex+10^8*mcVar)^qComp

(1) and (2) are identical, but (3) is different. I had to go all the way up
to (10^10*mcVar)^qComp to get an identical file. This correlates with real
differences I was seeing; 10^8 looked very slightly better than 10^7,
overall, and 10^9 looked substantially worse.

At this point, I'm rather murky in my understanding of how the ratecontrol
equation works. I hadn't expected (1) to be the same as (2). Can you give me
a rough explanation? At this point, writing down my own speculation wouldn't
be very helpful, since it doesn't match the observed behavior.

>> for i in 1:turbo:vb_strategy=2 2 ; do
>>   mencoder matrix.vob -aid 128 -oac copy -vf \
>>   crop=718:356:0:60,scale=640:272 -sws 9 -ovc lavc -lavcopts \
>>   vcodec=mpeg4:vbitrate=581:psnr:vpass=\$i:mbd=2:mv0:trell:cbp:\
>>   precmp=2:cmp=2:subcmp=2:predia=2:dia=2:preme=2:vme=5:v4mv:\
>>   last_pred=2:vqcomp=0.6:qpel:sc_factor=6 -ofps 24000/1001 -o
>>   lavc-default.avi
>> done
>
> Is that the exact command you ran? My copy of bash retains the spaces at
> the beginning of the line when collapsing \'s, thus treating last 2 lines
> of the lavcopts as input filenames (which obviously won't exist).

Yeah, that was just a transcription error.

> Also, I see vb_strategy but no vmax_b_frames.

Oops. I copied that from a place in my notes where vmax_b_frames was the
experimental factor.

I fixed both of those in the page.

Thanks,
Corey

```