Index: ratecontrol.c =================================================================== --- ratecontrol.c (revision 161806) +++ ratecontrol.c (working copy) @@ -43,7 +43,7 @@ int i_tex_bits; int p_tex_bits; int misc_bits; - uint64_t expected_bits; + uint64_t expected_bits; /*total expected bits up to the current frame (current one excluded)*/ double expected_vbv; float new_qscale; int new_qp; @@ -93,7 +93,7 @@ int last_satd; double last_rceq; double cplxr_sum; /* sum of bits*qscale/rceq */ - double expected_bits_sum; /* sum of qscale2bits after rceq, ratefactor, and overflow */ + double expected_bits_sum; /* sum of qscale2bits after rceq, ratefactor, and overflow, only includes finished frames */ double wanted_bits_window; /* target bitrate * window */ double cbr_decay; double short_term_cplxsum; @@ -1439,21 +1439,6 @@ + h->stat.i_slice_size[SLICE_TYPE_P] + h->stat.i_slice_size[SLICE_TYPE_B]); - if( h->param.i_threads > 1 ) - { - int j = h->rc - h->thread[0]->rc; - int i; - for( i=1; iparam.i_threads; i++ ) - { - x264_t *t = h->thread[ (j+i)%h->param.i_threads ]; - double bits = t->rc->frame_size_planned; - if( !t->b_thread_active ) - continue; - bits = X264_MAX(bits, x264_frame_size_estimated_get(t)); - total_bits += (int64_t)bits; - } - } - if( rcc->b_2pass ) { rce = *rcc->rce; @@ -1506,10 +1491,11 @@ if( rcc->b_2pass ) { //FIXME adjust abr_buffer based on distance to the end of the video - int64_t diff = total_bits - (int64_t)rce.expected_bits; + int64_t diff = total_bits - (int64_t)rcc->expected_bits_sum; q = rce.new_qscale; q /= x264_clip3f((double)(abr_buffer - diff) / abr_buffer, .5, 2); - if( h->fenc->i_frame > 30 ) + if( ((h->fenc->i_frame + 1 - h->param.i_threads) >= rcc->fps) && + (rcc->expected_bits_sum > 0)) { /* Adjust quant based on the difference between * achieved and expected bitrate so far */