[FFmpeg-devel] [PATCH] lavf/mux: add the flush_packets option.
Nicolas George
nicolas.george at normalesup.org
Tue Mar 12 17:07:45 CET 2013
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
doc/ffmpeg-formats.texi | 5 +++++
libavformat/avformat.h | 7 +++++++
libavformat/mux.c | 2 ++
libavformat/options_table.h | 1 +
4 files changed, 15 insertions(+)
Reimar Döffinger wrote:
> I see we are doing this in a lot of encoders, but this seems just bad to
> me.
> While it reduces latency, it also reduces performance in some use-cases.
I believe the cases where the performance hit would be non-negligible are
very particular; enough to make flushing the default behaviour.
> In addition, it is just silly code duplication to have this inside
> (almost) every single muxer.
> Extracting it in some way and possibly making it configurable seems
> like it would be a good thing to do long-term.
I believe you are right. New patch attached.
Regards,
--
Nicolas George
diff --git a/doc/ffmpeg-formats.texi b/doc/ffmpeg-formats.texi
index 30cf415..ea61725 100644
--- a/doc/ffmpeg-formats.texi
+++ b/doc/ffmpeg-formats.texi
@@ -142,6 +142,11 @@ Use wallclock as timestamps.
@item avoid_negative_ts @var{integer} (@emph{output})
Shift timestamps to make them positive. 1 enables, 0 disables, default
of -1 enables when required by target format.
+
+ at item flush_packets @var{integer} (@emph{output})
+Flush the underlying I/O stream after each packet. Default 1 enables it, and
+has the effect of reducing the latency; 0 disables it and may slightly
+increase performance in some cases.
@end table
@c man end FORMAT OPTIONS
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 0fc71aa..ce4b8af 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1217,6 +1217,13 @@ typedef struct AVFormatContext {
*/
int seek2any;
+ /**
+ * Flush the I/O context after each packet.
+ * - encoding: Set by user via AVOPtions (NO direct access)
+ * - decoding: unused
+ */
+ int flush_packets;
+
/*****************************************************************
* All fields below this line are not part of the public API. They
* may not be used outside of libavformat and can be changed and
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 0d74d96..46684cc 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -494,6 +494,8 @@ static inline int split_write_packet(AVFormatContext *s, AVPacket *pkt)
did_split = av_packet_split_side_data(pkt);
ret = s->oformat->write_packet(s, pkt);
+ if (s->flush_packets && s->pb && s->pb->error >= 0)
+ avio_flush(s->pb);
if (did_split)
av_packet_merge_side_data(pkt);
return ret;
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 6750050..9f86137 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -75,6 +75,7 @@ static const AVOption options[]={
{"avoid_negative_ts", "shift timestamps to make them positive. 1 enables, 0 disables, default of -1 enables when required by target format.", OFFSET(avoid_negative_ts), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, E},
{"skip_initial_bytes", "skip initial bytes", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX-1, D},
{"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, D},
+{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E},
{NULL},
};
--
1.7.10.4
More information about the ffmpeg-devel
mailing list