[FFmpeg-devel] [PATCH] Fix ratecontrol bug when time_base.num > 1

Joseph Artsimovich joseph at mirriad.com
Fri Nov 16 13:01:11 CET 2012


When encoding long-GOP MPEG2 with time_base of 24/600 (with reduces to 
1/25, but I need it for compatibility with some proprietary software) I 
noticed blow up of encoded frame size and "rc buffer underflow" errors. 
I traced it back to the following line in ratecontrol.c:

wanted_bits = (uint64_t)(s->bit_rate*(double)dts_pic->f.pts / fps);

which doesn't take pts units into account.
A patch is attached.

-- 
Joseph Artsimovich
Senior C++ Applications Developer
MirriAd Ltd

-------------- next part --------------
>From c60f3c9070132c4329c1bcd404f46122cd1a28ca Mon Sep 17 00:00:00 2001
From: Joseph Artsimovich <joseph at mirriad.com>
Date: Fri, 16 Nov 2012 11:37:09 +0000
Subject: [PATCH] Fix ratecontrol bug when time_base.num > 1

The reason I divide on s->dts_delta instead of s->avctx->time_base.num
is that time_base in avctx gets common factors removed from it.
For compatibility with a proprietary piece of software I need time_base
to be 24/600, even though it reduces to 1/25.
---
 libavcodec/ratecontrol.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 8f8647c..02ca311 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -708,7 +708,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run)
         if (!dts_pic || dts_pic->f.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->f.pts / fps);
+            wanted_bits = (uint64_t)(s->bit_rate*(double)dts_pic->f.pts / (fps*(double)s->dts_delta));
     }
 
     diff= s->total_bits - wanted_bits;
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list