Message ID | 20191031170458.22515-2-nicolas.gaullier@arkena.com |
---|---|
State | New |
Headers | show |
On Thu, Oct 31, 2019 at 06:04:58PM +0100, Nicolas Gaullier wrote: > Allow the user to set or override the vbv size > --- > libavformat/mpegenc.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c > index f6980231a2..1613c8afa1 100644 > --- a/libavformat/mpegenc.c > +++ b/libavformat/mpegenc.c > @@ -67,6 +67,7 @@ typedef struct MpegMuxContext { > int system_header_freq; > int system_header_size; > int user_mux_rate; /* bitrate in units of bits/s */ > + int user_vbv_size; /* vbv buffer size in units of bits/s */ > int mux_rate; /* bitrate in units of 50 bytes/s */ > /* stream info */ > int audio_bound; > @@ -433,7 +434,9 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) > stream->id = mpv_id++; > > props = (AVCPBProperties*)av_stream_get_side_data(st, AV_PKT_DATA_CPB_PROPERTIES, NULL); > - if (props && props->buffer_size) > + if (s->user_vbv_size) > + stream->max_buffer_size = 6 * 1024 + s->user_vbv_size / 8; > + else if (props && props->buffer_size) > stream->max_buffer_size = 6 * 1024 + props->buffer_size / 8; > else { > av_log(ctx, AV_LOG_WARNING, > @@ -1268,6 +1271,7 @@ static void mpeg_mux_deinit(AVFormatContext *ctx) > #define E AV_OPT_FLAG_ENCODING_PARAM > static const AVOption options[] = { > { "muxrate", NULL, OFFSET(user_mux_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, ((1<<22) - 1) * (8 * 50), E }, > + { "vbvsize", "set vbv buffer size (in bits)", OFFSET(user_vbv_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, (1LL<<32) - 1, E}, > { "preload", "Initial demux-decode delay in microseconds.", OFFSET(preload), AV_OPT_TYPE_INT, { .i64 = 500000 }, 0, INT_MAX, E }, > { NULL }, > }; This is not the "correct" way to handle this, because one mpeg container can contain many streams and this is just one parameter for the container. while the vbvsize is a parameter per stream. [...]
diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index f6980231a2..1613c8afa1 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -67,6 +67,7 @@ typedef struct MpegMuxContext { int system_header_freq; int system_header_size; int user_mux_rate; /* bitrate in units of bits/s */ + int user_vbv_size; /* vbv buffer size in units of bits/s */ int mux_rate; /* bitrate in units of 50 bytes/s */ /* stream info */ int audio_bound; @@ -433,7 +434,9 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) stream->id = mpv_id++; props = (AVCPBProperties*)av_stream_get_side_data(st, AV_PKT_DATA_CPB_PROPERTIES, NULL); - if (props && props->buffer_size) + if (s->user_vbv_size) + stream->max_buffer_size = 6 * 1024 + s->user_vbv_size / 8; + else if (props && props->buffer_size) stream->max_buffer_size = 6 * 1024 + props->buffer_size / 8; else { av_log(ctx, AV_LOG_WARNING, @@ -1268,6 +1271,7 @@ static void mpeg_mux_deinit(AVFormatContext *ctx) #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { { "muxrate", NULL, OFFSET(user_mux_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, ((1<<22) - 1) * (8 * 50), E }, + { "vbvsize", "set vbv buffer size (in bits)", OFFSET(user_vbv_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, (1LL<<32) - 1, E}, { "preload", "Initial demux-decode delay in microseconds.", OFFSET(preload), AV_OPT_TYPE_INT, { .i64 = 500000 }, 0, INT_MAX, E }, { NULL }, };