diff options
author | Jan Ekström <jeebjp@gmail.com> | 2020-10-15 21:21:05 +0300 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2020-10-29 16:59:48 +0200 |
commit | 453b2f3c154f6b83221940ad411599ded91f7413 (patch) | |
tree | 5b718860b89a427fa1ad5680bf9c273f577672d6 /fftools/ffmpeg_opt.c | |
parent | 9b45c6d74b6bcc21c3246580db3392d15a6988b8 (diff) |
ffmpeg: add a data size threshold for muxing queue size
This way the old max queue size limit based behavior for streams
where each individual packet is large is kept, while for smaller
streams more packets can be buffered (current default is at 50
megabytes per stream).
For some explanation, by default ffmpeg copies packets from before
the appointed seek point/start time and puts them into the local
muxing queue. Before, it getting utilized was much less likely
since as soon as the filter chain was initialized, the encoder
(and thus output stream) was also initialized.
Now, since we will be pushing the encoder initialization to when the
first AVFrame is decoded and filtered - which only happens after
the exact seek point is hit as packets are ignored until then -
this queue will be seeing much more usage.
In more layman's terms, this attempts to fix cases such as where:
- seek point ends up being 5 seconds before requested time.
- audio is set to copy, and thus immediately begins filling the
muxing queue.
- video is being encoded, and thus all received packets are skipped
until the requested time is hit.
Diffstat (limited to 'fftools/ffmpeg_opt.c')
-rw-r--r-- | fftools/ffmpeg_opt.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index d58462b6ae..7ee034c9c9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -87,6 +87,7 @@ static const char *opt_name_canvas_sizes[] = {"canvas_size", NULL}; static const char *opt_name_pass[] = {"pass", NULL}; static const char *opt_name_passlogfiles[] = {"passlogfile", NULL}; static const char *opt_name_max_muxing_queue_size[] = {"max_muxing_queue_size", NULL}; +static const char *opt_name_muxing_queue_data_threshold[] = {"muxing_queue_data_threshold", NULL}; static const char *opt_name_guess_layout_max[] = {"guess_layout_max", NULL}; static const char *opt_name_apad[] = {"apad", NULL}; static const char *opt_name_discard[] = {"discard", NULL}; @@ -1564,6 +1565,11 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st); ost->max_muxing_queue_size *= sizeof(AVPacket); + ost->muxing_queue_data_size = 0; + + ost->muxing_queue_data_threshold = 50*1024*1024; + MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ost->muxing_queue_data_threshold, oc, st); + if (oc->oformat->flags & AVFMT_GLOBALHEADER) ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; @@ -3761,6 +3767,8 @@ const OptionDef options[] = { { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) }, "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" }, + { "muxing_queue_data_threshold", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(muxing_queue_data_threshold) }, + "set the threshold after which max_muxing_queue_size is taken into account", "bytes" }, /* data codec support */ { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec }, |