[MEncoder-users] Experiences of video encoding

Corey Hickey bugfood-ml at fatooh.org
Tue Mar 27 03:20:17 CEST 2007


Nicolas George wrote:
> Hi.
> 
> Over the last weeks, I have led an experiment of video encoding, encoding a
> lot of times the same samples with various parameters and measuring the
> resulting quality and bitrate. The results of the first phase of this
> experiment are there:
> 
> http://www.eleves.ens.fr/home/george/info/video_quality/
> 
> As I am planning the second phase, I would like to get comments and advice.

Discussing favorite lavc encoding options usually leads to a bit of 
disagreement, but I have some comments based on my own testing; most of 
them are about B-frames. If anybody wants to disagree, please do so. :) 
Especially if I've been careless and said something wrong.

Quotes below are from your page.

 > For lavc:
 >
 >    * vmax_b_frames=4

This is problematic with regard to constant-quantizer encoding.

The benefit of using B-frames, as I understand it, is that you can use 
slightly higher quantizers with them, which lets other frames have 
slightly lower quantizers. If you specify a fixed quantizer, the three 
codecs you tested behave differently.

I specified a fixed quantizer of 4 for each of the following. I know the 
h.264 quantizers aren't equivalent; I just wanted to demonstrate how the 
codecs vary them differently:


        I  P  B
lavc   4  4  4
XviD   4  4  7
x264   1  4  6

Lavc uses the same quantizer for all three frame types, completely 
negating the benefit of using B-frames. As I recall, constant-quantizer 
encoding with B-frames in lavc is actually harmful. A quick test 
supports that.

$ mencoder /tmp/serenity_m420p.mov -nosound -ovc lavc \
-lavcopts vqscale=4:vmax_b_frames=0:psnr -o test.avi

vmax_b_frames=0
Video stream: 1424.632 kbit/s
PSNR: Y:43.48, Cb:47.07, Cr:47.26, All:44.40

vmax_b_frames=2
Video stream: 1547.001 kbit/s
PSNR: Y:43.41, Cb:47.04, Cr:47.19, All:44.33

vmax_b_frames=4
Video stream: 1715.613 kbit/s
PSNR: Y:43.31, Cb:46.94, Cr:47.05, All:44.23

As you can see, bitrate goes up and PSNR goes down. I didn't test the 
other codecs in this regard, but lavc should be the worst of them 
because it completely obeys you when you tell it to use a constant 
quantizer.

I haven't tried this, but you should be able to make lavc use a 
different quantizer for b-frames:
http://lists.mplayerhq.hu/pipermail/mplayer-advusers/2003-December/000740.html


If you end up making "constant" quantizers and B-frames to work out 
sanely and fairly, then the rest of this applies:

I've never seen a significant improvement above 2 b-frames in lavc; if 
you have found otherwise, feel free to use 4.

You're almost certain to get better-looking results if you use a good 
vb_strategy. Here's what I would expect:

vb_strategy=2
- much better-looking in high-motion scenes
- very slightly higher PSNR
- much longer encoding time

vb_strategy=1:b_sensitivity=10 (or so)
- almost as good-looking as vb_strategy=2
- slightly lower PSNR
- slightly shorter encoding time

This is probably a decent example of the shortcomings of numerical 
analysis of video quality: both options look better, but that isn't 
reflected in PSNR.

...although, now that I think about it, I never tested either of those 
with constant-quantizer encoding, in which there might be less of an 
effect. The purpose of vb_strategy is to avoid using B-frames when they 
hurt quality, which is mostly during high-motion scenes. B-frame 
quantizers are selected based on the quantizer of the surrounding 
P-frames (read the man page descriptions of vb_qoffset, vb_qfactor, and 
vi_qfactor). With normal target-bitrate encoding, the surrounding 
P-frames' quantizers are already high, which makes the B-frame 
quantizers unreasonably high. In constant-quantizer encoding, the 
P-frame quantizers will always be the same, so the B-frame quantizers 
might not be unreasonably high. Still, you way want to consider using a 
vb_strategy for lavc, especially since the other two codecs do something 
similar by default.

 >    * mbd=2
 >    * v4mv

Good...

 >    * qpel

This might be slightly detrimental unless your clips include scrolling 
credits or something similar, in which case it will be slightly beneficial.

 >     * dia=6

I haven't diamond size much; you might get a tiny bit more PSNR if you 
use predia as well.

 >    * trell
 >    * cbp
 >    * mv0

Good...

 >    * qprd

Probably good. I can never remember when qprd is bad.

 >    * umv

Does this have an effect? The man page says it's only for H.263+ and a 
quick test showed no difference right now.

 >    * mpeg_quant or not
 >    * vqscale=value

I strongly suggest you use cmp=2 and subcmp=2; precmp=2 may help as 
well, and it's not likely to hurt.

last_pred=2 or last_pred=3 should help; I've lost my notes on that, if I 
ever took them, but I can't remember ever seeing last_pred=2 be a problem.

You can probably take or leave these ones; in my testing they help PSNR 
very very slightly.
aic
preme=2
mv0_threshold=0


I want to reiterate that I know how much work this involves; don't get 
discouraged!

-Corey



More information about the MEncoder-users mailing list