Mercurial > libavcodec.hg
comparison ratecontrol.c @ 5672:ce58a38cd391 libavcodec
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
author | michael |
---|---|
date | Tue, 11 Sep 2007 22:46:41 +0000 |
parents | 0e593c7d0ebc |
children | ed05a3d964fa |
comparison
equal
deleted
inserted
replaced
5671:7dfd69f9af60 | 5672:ce58a38cd391 |
---|---|
697 assert(picture_number>=0); | 697 assert(picture_number>=0); |
698 assert(picture_number<rcc->num_entries); | 698 assert(picture_number<rcc->num_entries); |
699 rce= &rcc->entry[picture_number]; | 699 rce= &rcc->entry[picture_number]; |
700 wanted_bits= rce->expected_bits; | 700 wanted_bits= rce->expected_bits; |
701 }else{ | 701 }else{ |
702 Picture *dts_pic; | |
702 rce= &local_rce; | 703 rce= &local_rce; |
703 wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); | 704 |
705 //FIXME add a dts field to AVFrame and ensure its set and use it here instead of reordering | |
706 //but the reordering is simpler for now until h.264 b pyramid must be handeld | |
707 if(s->pict_type == B_TYPE || s->low_delay) | |
708 dts_pic= s->current_picture_ptr; | |
709 else | |
710 dts_pic= s->last_picture_ptr; | |
711 | |
712 //if(dts_pic) | |
713 // 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); | |
714 | |
715 if(!dts_pic || dts_pic->pts == AV_NOPTS_VALUE) | |
716 wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); | |
717 else | |
718 wanted_bits= (uint64_t)(s->bit_rate*(double)dts_pic->pts/fps); | |
704 } | 719 } |
705 | 720 |
706 diff= s->total_bits - wanted_bits; | 721 diff= s->total_bits - wanted_bits; |
707 br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance; | 722 br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance; |
708 if(br_compensation<=0.0) br_compensation=0.001; | 723 if(br_compensation<=0.0) br_compensation=0.001; |