The default value of this option should be high enough for most uses, so only
touch this option if you are sure that you need it.
+@item -muxing_queue_data_threshold @var{bytes} (@emph{output,per-stream})
+This is a minimum threshold until which the muxing queue size is not taken into
+account. Defaults to 50 megabytes per stream, and is based on the overall size
+of packets passed to the muxer.
+
@item -auto_conversion_filters (@emph{global})
Enable automatically inserting format conversion filters in all filter
graphs, including those defined by @option{-vf}, @option{-af},
AVPacket tmp_pkt = {0};
/* the muxer is not initialized yet, buffer the packet */
if (!av_fifo_space(ost->muxing_queue)) {
- int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue),
- ost->max_muxing_queue_size);
+ unsigned int are_we_over_size =
+ (ost->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold;
+ int new_size = are_we_over_size ?
+ FFMIN(2 * av_fifo_size(ost->muxing_queue),
+ ost->max_muxing_queue_size) :
+ 2 * av_fifo_size(ost->muxing_queue);
+
if (new_size <= av_fifo_size(ost->muxing_queue)) {
av_log(NULL, AV_LOG_ERROR,
"Too many packets buffered for output stream %d:%d.\n",
if (ret < 0)
exit_program(1);
av_packet_move_ref(&tmp_pkt, pkt);
+ ost->muxing_queue_data_size += tmp_pkt.size;
av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL);
return;
}
while (av_fifo_size(ost->muxing_queue)) {
AVPacket pkt;
av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
+ ost->muxing_queue_data_size -= pkt.size;
write_packet(of, &pkt, ost, 1);
}
}
int nb_passlogfiles;
SpecifierOpt *max_muxing_queue_size;
int nb_max_muxing_queue_size;
+ SpecifierOpt *muxing_queue_data_threshold;
+ int nb_muxing_queue_data_threshold;
SpecifierOpt *guess_layout_max;
int nb_guess_layout_max;
SpecifierOpt *apad;
/* the packets are buffered here until the muxer is ready to be initialized */
AVFifoBuffer *muxing_queue;
+ /*
+ * The size of the AVPackets' buffers in queue.
+ * Updated when a packet is either pushed or pulled from the queue.
+ */
+ size_t muxing_queue_data_size;
+
+ /* Threshold after which max_muxing_queue_size will be in effect */
+ size_t muxing_queue_data_threshold;
+
/* packet picture type */
int pict_type;
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};
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;
{ "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 },