[Ffmpeg-devel] lavc crash & qprd plus bframes = low quality
Michael Niedermayer
michaelni
Mon Dec 11 12:22:00 CET 2006
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
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- next part --------------
Index: libavcodec/mpegvideo.c
===================================================================
--- libavcodec/mpegvideo.c (revision 7266)
+++ libavcodec/mpegvideo.c (working copy)
@@ -4764,6 +4764,13 @@
memcpy(s->dest, dest_backup, sizeof(s->dest));
}
+ if(s->dquant>0 && (s->flags & CODEC_FLAG_QP_RD)){
+ int i, cod=0;
+ for(i=0; i<6; i++)
+ cod |= s->block_last_index[i] + 1;
+ if(!cod)
+ return;
+ }
if(score<*dmin){
*dmin= score;
*next_block^=1;
-------------- next part --------------
Index: libavcodec/mpegvideo.c
===================================================================
--- libavcodec/mpegvideo.c (revision 7266)
+++ libavcodec/mpegvideo.c (working copy)
@@ -5261,6 +5261,8 @@
qp= last_qp + dquant;
if(qp < s->avctx->qmin || qp > s->avctx->qmax)
continue;
+ if(dquant>0 && (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7) < qp - 2)
+ continue;
backup_s.dquant= dquant;
if(s->mb_intra && s->dc_val[0]){
for(i=0; i<6; i++){
More information about the ffmpeg-devel
mailing list