[FFmpeg-devel] [PATCH 07/12] ratecontrol: fix stuffing bits for 30000/1001 fps one frame vbv

Michael Niedermayer michael at niedermayer.cc
Thu Jul 5 13:43:56 EEST 2018


On Wed, Jul 04, 2018 at 11:35:09AM -0700, Baptiste Coudurier wrote:
> ---
>  libavcodec/ratecontrol.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
> index 49d169ba25..28bdddbad1 100644
> --- a/libavcodec/ratecontrol.c
> +++ b/libavcodec/ratecontrol.c
> @@ -705,16 +705,16 @@ int ff_vbv_update(MpegEncContext *s, int frame_size)
>          rcc->buffer_index += av_clip(left, min_rate, max_rate);
>  
>          if (rcc->buffer_index > buffer_size) {
> -            int stuffing = ceil((rcc->buffer_index - buffer_size) / 8);
> +            int stuffing = rcc->buffer_index - buffer_size;
>  
> -            if (stuffing < 4 && s->codec_id == AV_CODEC_ID_MPEG4)
> -                stuffing = 4;
> -            rcc->buffer_index -= 8 * stuffing;
> +            if (stuffing < 32 && s->codec_id == AV_CODEC_ID_MPEG4)
> +                stuffing = 32;
> +            rcc->buffer_index -= stuffing;
>  
>              if (s->avctx->debug & FF_DEBUG_RC)
> -                av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing);
> +                av_log(s->avctx, AV_LOG_DEBUG, "stuffing %d bytes\n", stuffing>>3);
>  
> -            return stuffing;
> +            return stuffing>>3;
>          }

This would break VBV for most codecs
buffer_index is a double, the if() condition is triggered if the current frame
is too small. All the rounding has to be up as in the ceil() that was there.
The stuffing that is added, is minimal, so a decrease would be expected to
break cases occasionally

Can you explain how this code fails, in what exact case 
(max/min rate/ buffer_size/fps) ?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180705/ccf514dc/attachment.sig>


More information about the ffmpeg-devel mailing list