diff mbox

[FFmpeg-devel,2/3] avformat/options: disable flush_packets as default

Message ID 20170604133507.20614-2-cus@passwd.hu
State New
Headers show

Commit Message

Marton Balint June 4, 2017, 1:35 p.m. UTC
It is a huge performance improvement for encoding files with small packets
(e.g. wav) over SMB/CIFS.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mux.c           | 4 ++--
 libavformat/options_table.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Marton Balint June 16, 2017, 10:18 p.m. UTC | #1
On Sun, 4 Jun 2017, Marton Balint wrote:

> It is a huge performance improvement for encoding files with small packets
> (e.g. wav) over SMB/CIFS.
>

Ping? Maybe enabling this unconditionally is also problematic for 
protocols other than file? If that so, then how about making flush_packet 
a tri state with -1 (auto) as default, and then similar to how 
max_packet_size is handled define something in URLContext to be able to 
set the flush preference on a protocol basis?

Thanks,
Marton

> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavformat/mux.c           | 4 ++--
> libavformat/options_table.h | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index e1e49a81be..540ac56c3f 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -479,7 +479,7 @@ static int write_header_internal(AVFormatContext *s)
>         s->internal->write_header_ret = ret;
>         if (ret < 0)
>             return ret;
> -        if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
> +        if ((s->flush_packets || s->flags & AVFMT_FLAG_FLUSH_PACKETS) && s->pb && s->pb->error >= 0)
>             avio_flush(s->pb);
>     }
>     s->internal->header_written = 1;
> @@ -772,7 +772,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>     }
>
>     if (s->pb && ret >= 0) {
> -        if (s->flush_packets && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
> +        if (s->flush_packets || s->flags & AVFMT_FLAG_FLUSH_PACKETS)
>             avio_flush(s->pb);
>         if (s->pb->error < 0)
>             ret = s->pb->error;
> diff --git a/libavformat/options_table.h b/libavformat/options_table.h
> index 0c1915d6d4..b72f72b845 100644
> --- a/libavformat/options_table.h
> +++ b/libavformat/options_table.h
> @@ -39,7 +39,7 @@ static const AVOption avformat_options[] = {
> {"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT64, {.i64 = 5000000 }, 32, INT64_MAX, D},
> {"formatprobesize", "number of bytes to probe file format", OFFSET(format_probesize), AV_OPT_TYPE_INT, {.i64 = PROBE_BUF_MAX}, 0, INT_MAX-1, D},
> {"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, E},
> -{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_FLUSH_PACKETS | AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"},
> +{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"},
> {"flush_packets", "reduce the latency by flushing out packets immediately", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, E, "fflags"},
> {"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
> {"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
> @@ -85,7 +85,7 @@ static const AVOption avformat_options[] = {
> {"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D},
> {"skip_initial_bytes", "set number of bytes to skip before reading header and frames", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX-1, D},
> {"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, D},
> -{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E},
> +{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E},
> {"metadata_header_padding", "set number of bytes to be written as padding in a metadata header", OFFSET(metadata_header_padding), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, E},
> {"output_ts_offset", "set output timestamp offset", OFFSET(output_ts_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E},
> {"max_interleave_delta", "maximum buffering duration for interleaving", OFFSET(max_interleave_delta), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT64_MAX, E },
> -- 
> 2.12.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Michael Niedermayer June 17, 2017, 11:20 a.m. UTC | #2
On Sat, Jun 17, 2017 at 12:18:27AM +0200, Marton Balint wrote:
> 
> On Sun, 4 Jun 2017, Marton Balint wrote:
> 
> >It is a huge performance improvement for encoding files with small packets
> >(e.g. wav) over SMB/CIFS.
> >
> 
> Ping? Maybe enabling this unconditionally is also problematic for
> protocols other than file? If that so, then how about making
> flush_packet a tri state with -1 (auto) as default, and then similar
> to how max_packet_size is handled define something in URLContext to
> be able to set the flush preference on a protocol basis?

i think auto is a good idea.

maybe there also could be a min_flush_bytes/duration that would cause
flush to be ommited if the last automatic flush was too short ago
byte or timestamp wise

[...]
diff mbox

Patch

diff --git a/libavformat/mux.c b/libavformat/mux.c
index e1e49a81be..540ac56c3f 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -479,7 +479,7 @@  static int write_header_internal(AVFormatContext *s)
         s->internal->write_header_ret = ret;
         if (ret < 0)
             return ret;
-        if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
+        if ((s->flush_packets || s->flags & AVFMT_FLAG_FLUSH_PACKETS) && s->pb && s->pb->error >= 0)
             avio_flush(s->pb);
     }
     s->internal->header_written = 1;
@@ -772,7 +772,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
     }
 
     if (s->pb && ret >= 0) {
-        if (s->flush_packets && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
+        if (s->flush_packets || s->flags & AVFMT_FLAG_FLUSH_PACKETS)
             avio_flush(s->pb);
         if (s->pb->error < 0)
             ret = s->pb->error;
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 0c1915d6d4..b72f72b845 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -39,7 +39,7 @@  static const AVOption avformat_options[] = {
 {"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT64, {.i64 = 5000000 }, 32, INT64_MAX, D},
 {"formatprobesize", "number of bytes to probe file format", OFFSET(format_probesize), AV_OPT_TYPE_INT, {.i64 = PROBE_BUF_MAX}, 0, INT_MAX-1, D},
 {"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, E},
-{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_FLUSH_PACKETS | AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"},
+{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"},
 {"flush_packets", "reduce the latency by flushing out packets immediately", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, E, "fflags"},
 {"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
 {"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
@@ -85,7 +85,7 @@  static const AVOption avformat_options[] = {
 {"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D},
 {"skip_initial_bytes", "set number of bytes to skip before reading header and frames", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX-1, D},
 {"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, D},
-{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E},
+{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E},
 {"metadata_header_padding", "set number of bytes to be written as padding in a metadata header", OFFSET(metadata_header_padding), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, E},
 {"output_ts_offset", "set output timestamp offset", OFFSET(output_ts_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E},
 {"max_interleave_delta", "maximum buffering duration for interleaving", OFFSET(max_interleave_delta), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT64_MAX, E },