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

Michael Niedermayer michaelni at gmx.at
Fri Nov 16 14:59:58 CET 2012


On Fri, Nov 16, 2012 at 12:01:11PM +0000, Joseph Artsimovich wrote:
> 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.
[...]
> @@ -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));
>      }

dts_delta is only set in some cases and only based
on the first frames.
The durations of later frames can be entirely different from the
first frames.

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121116/7b0bd9f4/attachment.asc>


More information about the ffmpeg-devel mailing list