[Libav-user] how will AVCodecContext.rc_max_rate be respected

YIRAN LI mrfun.china at gmail.com
Mon Sep 2 04:06:30 CEST 2013

Hi friend,

I met a problem when converting video stream into mpeg 2 format with
specified max bitrate.

The input file has a high bitrate of about 40Mbps (resolution is 720P),

when converting with "ffmpeg -i input.mp4 -target pal-dvd dvd.mpg" then
everything is OK, resulting mpeg has a bitrate of 7620kbps.

As we know, specifying "-taget pal-dvd" in fact supply a bunch of arguments
into the command line,
in fact they are
        opt_video_codec(o, "c:v", "mpeg2video");
        opt_audio_codec(o, "c:a", "ac3");
        parse_option(o, "f", "dvd", options);

        parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
        parse_option(o, "r", frame_rates[norm], options);
        parse_option(o, "pix_fmt", "yuv420p", options);
        av_dict_set(&o->g->codec_opts, "g", norm == PAL ? "15" : "18", 0);

        av_dict_set(&o->g->codec_opts, "b:v", "6000000", 0);
        av_dict_set(&o->g->codec_opts, "maxrate", "9000000", 0);
        av_dict_set(&o->g->codec_opts, "minrate", "0", 0); // 1500000;
        av_dict_set(&o->g->codec_opts, "bufsize", "1835008", 0); //

        av_dict_set(&o->g->format_opts, "packetsize", "2048", 0);  // from
www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the
size of one pack.
        av_dict_set(&o->g->format_opts, "muxrate", "10080000", 0); // from
mplex project: data_rate = 1260000. mux_rate = data_rate * 8

        av_dict_set(&o->g->codec_opts, "b:a", "448000", 0);
        parse_option(o, "ar", "48000", options);

So when I supply this argument one by one instead of using "-target
pal-dvd", generated video is still OK.

But once I removed "-f dvd -s 720x576", there come out lots warnings of
"buffer underflow", and the generated file has an overall bitrate of
29.7Mbps although 9000k is specified to be max.
I think that means "-target paldvd" succeeds because down scale is done,
and if without resizing (in case input bitrate is high), only specifying
maxrate doesn't guarantee the bitrate of the
output file.

So I want to know, if there is any option available, so that no matter what
the input bitrate is, output can always stay below a specified bitrate?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130902/e28cc069/attachment.html>

More information about the Libav-user mailing list