# HG changeset patch # User michael # Date 1189550801 0 # Node ID ce58a38cd3910442e929703262f25d5686111ebb # Parent 7dfd69f9af6095af0f7a69af634748be082671c5 fix timestamps used for ratecontrol these were wrong (in pts vs dts sense) when b frames were in use they were also wrong if the average framerate was smaller than 1/timebase resulting in totally wrong final bitrate diff -r 7dfd69f9af60 -r ce58a38cd391 ratecontrol.c --- a/ratecontrol.c Mon Sep 10 00:31:27 2007 +0000 +++ b/ratecontrol.c Tue Sep 11 22:46:41 2007 +0000 @@ -699,8 +699,23 @@ rce= &rcc->entry[picture_number]; wanted_bits= rce->expected_bits; }else{ + Picture *dts_pic; rce= &local_rce; - wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); + + //FIXME add a dts field to AVFrame and ensure its set and use it here instead of reordering + //but the reordering is simpler for now until h.264 b pyramid must be handeld + if(s->pict_type == B_TYPE || s->low_delay) + dts_pic= s->current_picture_ptr; + else + dts_pic= s->last_picture_ptr; + +//if(dts_pic) +// av_log(NULL, AV_LOG_ERROR, "%Ld %Ld %Ld %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number); + + if(!dts_pic || dts_pic->pts == AV_NOPTS_VALUE) + wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); + else + wanted_bits= (uint64_t)(s->bit_rate*(double)dts_pic->pts/fps); } diff= s->total_bits - wanted_bits;