]> git.sesse.net Git - x264/commitdiff
Fix one bug, one corner case in VBV
authorFiona Glaser <fiona@x264.com>
Wed, 24 Feb 2010 11:49:32 +0000 (03:49 -0800)
committerFiona Glaser <fiona@x264.com>
Thu, 25 Feb 2010 00:49:49 +0000 (16:49 -0800)
qp_novbv wasn't set correctly for B-frames.
Disable ABR code for frames with zero complexity.
Disable ABR code for CBR mode; it is completely unnecessary and can have negative consequences.

encoder/ratecontrol.c

index 3103879998e92176464639b19cb68497b144d3ff..bf27936e9517523580e78a6419d135148958f9db 100644 (file)
@@ -1808,6 +1808,7 @@ static float rate_estimate_qscale( x264_t *h )
         /* For row SATDs */
         if( rcc->b_vbv )
             rcc->last_satd = x264_rc_analyse_slice( h );
+        rcc->qp_novbv = q;
         return qp2qscale(q);
     }
     else
@@ -1921,13 +1922,18 @@ static float rate_estimate_qscale( x264_t *h )
 
                 q = get_qscale( h, &rce, rcc->wanted_bits_window / rcc->cplxr_sum, h->fenc->i_frame );
 
-                // FIXME is it simpler to keep track of wanted_bits in ratecontrol_end?
-                wanted_bits = i_frame_done * rcc->bitrate / rcc->fps;
-                if( wanted_bits > 0 )
+                /* ABR code can potentially be counterproductive in CBR, so just don't bother.
+                 * Don't run it if the frame complexity is zero either. */
+                if( !rcc->b_vbv_min_rate && rcc->last_satd )
                 {
-                    abr_buffer *= X264_MAX( 1, sqrt(i_frame_done/25) );
-                    overflow = x264_clip3f( 1.0 + (total_bits - wanted_bits) / abr_buffer, .5, 2 );
-                    q *= overflow;
+                    // FIXME is it simpler to keep track of wanted_bits in ratecontrol_end?
+                    wanted_bits = i_frame_done * rcc->bitrate / rcc->fps;
+                    if( wanted_bits > 0 )
+                    {
+                        abr_buffer *= X264_MAX( 1, sqrt(i_frame_done/25) );
+                        overflow = x264_clip3f( 1.0 + (total_bits - wanted_bits) / abr_buffer, .5, 2 );
+                        q *= overflow;
+                    }
                 }
             }