[Ffmpeg-devel] lavc crash & qprd plus bframes = low quality

Corey Hickey bugfood-ml
Mon Dec 11 21:43:57 CET 2006

Michael Niedermayer wrote:
> Hi
> On Fri, Dec 08, 2006 at 11:06:53PM -0800, Corey Hickey wrote:
> [...]
>>> I also tried, again using unmodified mencoder, these options:
>>> mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=7000:mbd=2 -o test.avi crash_in_mvsearch.avi
>>> with qprd, or vmax_b_frames=2, or vmax_b_frames=2:qprd
>> I can't really give you a solution, but I may be able to give you a
>> better understanding of what is happening.
>> I encoded your clip with several different options. Since we're
>> comparing different options of the same codec, and the options don't
>> have a "psychovisual" effect, PSNR should be a reasonable representation
>> or relative quality.
>> All of these encodes were two pass, like this:
>> $ for i in 1 2 ; do mencoder -ovc lavc -lavcopts
>> vcodec=mpeg4:vbitrate=7000:mbd=2:psnr:vpass=$i -o lavc_neither.avi
>> crash_in_mvsearch.avi ; done
>> The options listed are additions to the above lavcopts. The bitrate and
>> PSNR reported is for the second pass.
>> (no other options)
>> Video stream: 7007.917 kbit/s  (875989 B/s)  size: 20204444 bytes
>> PSNR: Y:44.54, Cb:49.85, Cr:50.15, All:45.73
>> qprd
>> Video stream: 7002.222 kbit/s  (875277 B/s)  size: 20188026 bytes
>> PSNR: Y:44.77, Cb:49.91, Cr:50.16, All:45.93
>> qprd seems to help.
>> vmax_b_frames=2
>> Video stream: 6462.474 kbit/s  (807809 B/s)  size: 18631883 bytes
>> PSNR: Y:43.71, Cb:49.28, Cr:49.55, All:44.92
>> With B-frames, the PSNR is about the same, but note that the bitrate is
>> much lower. lavc printed a notice about that: "Using all of requested
>> bitrate is not necessary for this video with these parameters." The
>> reason, here, is that lavc uses higher quantizers to encode B-frames,
>> and, hence, a lower bitrate. With this clip, 7000 kbits/sec is so high
>> that lavc can't reallocate the saved bitrate by lowering the quantizers
>> of enough non B-frames--once all the I- and P-frames have a quantizer of
>> 2, the minimum allowed, the rest of the bitrate cannot be used.
>> vmax_b_frames=2:qprd
>> Video stream: 5961.748 kbit/s  (745218 B/s)  size: 17188246 bytes
>> PSNR: Y:43.52, Cb:49.10, Cr:49.36, All:44.73
>> With both B-frames and qprd, the PSNR is somewhat lower, and the bitrate
>> is even lower than with B-frames alone. Unfortunately, I can't give you
>> any explanation for why this is. The results do reveal, however, that
>> the combination isn't simply lowering quality--it's lowering bitrate
>> usage as well. Just like in the last test, if there weren't already so
>> many low quantizers, the bitrate could be put to better use elsewhere
>> for a net quality gain.
>> So, what should you do? It's probably possible to mess around with lmin,
>> mblmin, vmax_b_frames, vb_qfactor, vb_qoffset, and vb_strategy to make
>> B-frames work well in this situation. Once they do, qprd would probably
>> help as well. I'll leave it to you to decide whether you want to do that
>> or just avoid B-frames here. Personally, I always encode at bitrates
>> that are low enough to benefit from B-frames without any extra work.
> maybe ...
> anyway, qprd could get stuck at high quantizers (ive not checked if this does
> or does not happen here), if so one of the 2 attached patches might help,
> testresults with them would be welcome

I'm testing with the same clip, so the results below can be compared to 
the ones above. To save you having to scroll back and forth, though, 
I've noted the changes below each result.

Neither patch affected the results when qprd was not in use, so I'm not 
re-reporting those results.

Video stream: 7002.042 kbit/s  (875255 B/s)  size: 20187506 bytes
PSNR: Y:44.73, Cb:49.90, Cr:50.16, All:45.89

bitrate is nearly identical; PSNR is lower by 0.04

Video stream: 6032.944 kbit/s  (754118 B/s)  size: 17393512 bytes
PSNR: Y:43.55, Cb:49.12, Cr:49.38, All:44.76

bitrate is higher by 71; PSNR is higher by 0.03

Video stream: 7001.157 kbit/s  (875144 B/s)  size: 20184955 bytes
PSNR: Y:44.76, Cb:49.90, Cr:50.16, All:45.92

bitrate is lower by 1; PSNR is lower by 0.01 (negligible change)

Video stream: 5980.696 kbit/s  (747586 B/s)  size: 17242876 bytes
PSNR: Y:43.54, Cb:49.13, Cr:49.39, All:44.75

bitrate is higher by 19; PSNR is higher by 0.02

---------both patches--------
Video stream: 7001.201 kbit/s  (875150 B/s)  size: 20185083 bytes 
23.065 secs  553 frames
PSNR: Y:44.72, Cb:49.89, Cr:50.16, All:45.89

bitrate is lower by 1; PSNR is lower by 0.04

Video stream: 6053.592 kbit/s  (756699 B/s)  size: 17453042 bytes
PSNR: Y:43.57, Cb:49.15, Cr:49.41, All:44.78

bitrate is higher by 92; PSNR is higher by 0.05

I don't know if these results are useful for you. I don't know what to 
make of them, myself. I also ran some similar tests a different clip, 
with vbitrate low enough that lavc isn't getting constrained by the 
quantizer minimum.

(neither qprd nor B-frames)
Video stream:  796.537 kbit/s  (99567 B/s)  size: 5980003 bytes
PSNR: Y:39.59, Cb:42.75, Cr:43.63, All:40.49

Video stream:  793.936 kbit/s  (99242 B/s)  size: 5960477 bytes
PSNR: Y:39.64, Cb:42.66, Cr:43.53, All:40.51

Video stream:  800.749 kbit/s  (100093 B/s)  size: 6011626 bytes
PSNR: Y:39.94, Cb:43.32, Cr:44.23, All:40.88

Video stream:  800.035 kbit/s  (100004 B/s)  size: 6006262 bytes
PSNR: Y:39.99, Cb:43.26, Cr:44.16, All:40.91

Video stream:  793.783 kbit/s  (99222 B/s)  size: 5959328 bytes
PSNR: Y:39.67, Cb:42.69, Cr:43.56, All:40.54

Video stream:  799.889 kbit/s  (99986 B/s)  size: 6005164 bytes
PSNR: Y:39.98, Cb:43.23, Cr:44.13, All:40.90

Video stream:  794.105 kbit/s  (99263 B/s)  size: 5961741 bytes
PSNR: Y:39.66, Cb:42.68, Cr:43.55, All:40.53

Video stream:  799.108 kbit/s  (99888 B/s)  size: 5999305 bytes
PSNR: Y:40.00, Cb:43.27, Cr:44.17, All:40.92

--------both patches------
Video stream:  794.134 kbit/s  (99266 B/s)  size: 5961958 bytes
PSNR: Y:39.67, Cb:42.69, Cr:43.57, All:40.54

Video stream:  799.643 kbit/s  (99955 B/s)  size: 6003323 bytes
PSNR: Y:39.99, Cb:43.23, Cr:44.13, All:40.90

Based on testing those two sources, patch2 seems to be the best overall. 
My tests weren't exhaustive, though, so I wouldn't recommend it 


More information about the ffmpeg-devel mailing list