]> git.sesse.net Git - x264/commitdiff
Fix 2pass ratecontrol with --nal-hrd cbr
authorAnton Mitrofanov <BugMaster@narod.ru>
Fri, 8 Oct 2010 14:08:23 +0000 (18:08 +0400)
committerFiona Glaser <fiona@x264.com>
Sun, 10 Oct 2010 21:43:44 +0000 (14:43 -0700)
encoder/ratecontrol.c

index fdf87e9bd6e9ee60d2098bef19b6fbfc91da0758..e0e6761148693490d719f3ccba6fe67c217851fe 100644 (file)
@@ -107,6 +107,7 @@ struct x264_ratecontrol_t
     double last_rceq;
     double cplxr_sum;           /* sum of bits*qscale/rceq */
     double expected_bits_sum;   /* sum of qscale2bits after rceq, ratefactor, and overflow, only includes finished frames */
+    int64_t filler_bits_sum;    /* sum in bits of finished frames' filler data */
     double wanted_bits_window;  /* target bitrate * window */
     double cbr_decay;
     double short_term_cplxsum;
@@ -1602,6 +1603,7 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
     }
 
     *filler = update_vbv( h, bits );
+    rc->filler_bits_sum += *filler * 8;
 
     if( h->sps->vui.b_nal_hrd_parameters_present )
     {
@@ -2006,7 +2008,8 @@ static float rate_estimate_qscale( x264_t *h )
     int pict_type = h->sh.i_type;
     int64_t total_bits = 8*(h->stat.i_frame_size[SLICE_TYPE_I]
                           + h->stat.i_frame_size[SLICE_TYPE_P]
-                          + h->stat.i_frame_size[SLICE_TYPE_B]);
+                          + h->stat.i_frame_size[SLICE_TYPE_B])
+                       - rcc->filler_bits_sum;
 
     if( rcc->b_2pass )
     {
@@ -2367,6 +2370,7 @@ void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next )
          * to the context that's about to end (next) */
         COPY(cplxr_sum);
         COPY(expected_bits_sum);
+        COPY(filler_bits_sum);
         COPY(wanted_bits_window);
         COPY(bframe_bits);
         COPY(initial_cpb_removal_delay);