summaryrefslogtreecommitdiff
path: root/libavcodec/ratecontrol.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2007-09-11 22:46:41 +0000
committerMichael Niedermayer <michaelni@gmx.at>2007-09-11 22:46:41 +0000
commitf612801465b3def67d0190d70f407a9663e4b1f0 (patch)
treead9717b2b8d16200b474ad681b09f2e552a41330 /libavcodec/ratecontrol.c
parent70fd3975f97ea5d783cf0d83880c07dab3c147a9 (diff)
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 Originally committed as revision 10477 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ratecontrol.c')
-rw-r--r--libavcodec/ratecontrol.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 961f83570a..6cd5a4f30b 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -699,8 +699,23 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
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;