diff mbox

[FFmpeg-devel,2/2] avformat/dashenc: Added an option to ignore io errors

Message ID 20181126102551.57188-2-kjeyapal@akamai.com
State Accepted
Headers show

Commit Message

Jeyapal, Karthick Nov. 26, 2018, 10:25 a.m. UTC
When dashenc has to run for long duration(say 24x7 live stream), one can enable this option to ignore the io failure of few segment's upload due to an intermittent network issues.
When the network connection recovers dashenc will continue with the upload of the current segments, leading to the recovery of the stream.
---
 doc/muxers.texi       |  3 +++
 libavformat/dashenc.c | 26 ++++++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

Comments

Carl Eugen Hoyos Nov. 27, 2018, 4:22 p.m. UTC | #1
2018-11-26 11:25 GMT+01:00, Karthick J <kjeyapal@akamai.com>:
> When dashenc has to run for long duration(say 24x7 live stream), one can
> enable this option to ignore the io failure of few segment's upload due to
> an intermittent network issues.
> When the network connection recovers dashenc will continue with the upload
> of the current segments, leading to the recovery of the stream.

> -        return ret;
> +        if (c->ignore_io_errors)
> +            return 0;
> +        else
> +            return ret;

Maybe: return c->ignore_io_errors ? 0 : ret;
but it's your code...

Carl Eugen
Jeyapal, Karthick Nov. 28, 2018, 5:11 p.m. UTC | #2
On 11/27/18 9:52 PM, Carl Eugen Hoyos wrote:
> 2018-11-26 11:25 GMT+01:00, Karthick J <kjeyapal@akamai.com>:

> > When dashenc has to run for long duration(say 24x7 live stream), one can

> > enable this option to ignore the io failure of few segment's upload due to

> > an intermittent network issues.

> > When the network connection recovers dashenc will continue with the upload

> > of the current segments, leading to the recovery of the stream.

>

> > -        return ret;

> > +        if (c->ignore_io_errors)

> > +            return 0;

> > +        else

> > +            return ret;

>

> Maybe: return c->ignore_io_errors ? 0 : ret;

> but it's your code...

I appreciate your comment. Always happy to accept suggestions that will make this code better. Have sent PATCH v2 with these changes.
And it is everybody's code. I am just a maintainer (

Regards,
Karthick
>

> Carl Eugen

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a02ac01b55..f1cc6f5fee 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -300,6 +300,9 @@  If this flag is set, the dash segment files will be in in ISOBMFF format.
 @item webm
 If this flag is set, the dash segment files will be in in WebM format.
 
+@item -ignore_io_errors @var{ignore_io_errors}
+Ignore IO errors during open and write. Useful for long-duration runs with network output.
+
 @end table
 
 @anchor{framecrc}
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 2f403257c0..92b09417df 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -138,6 +138,7 @@  typedef struct DASHContext {
     int index_correction;
     char *format_options_str;
     SegmentType segment_type_option;  /* segment type as specified in options */
+    int ignore_io_errors;
 } DASHContext;
 
 static struct codec_string {
@@ -846,7 +847,10 @@  static int write_manifest(AVFormatContext *s, int final)
     av_dict_free(&opts);
     if (ret < 0) {
         av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
-        return ret;
+        if (c->ignore_io_errors)
+            return 0;
+        else
+            return ret;
     }
     out = c->mpd_out;
     avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
@@ -937,7 +941,10 @@  static int write_manifest(AVFormatContext *s, int final)
         av_dict_free(&opts);
         if (ret < 0) {
             av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
-            return ret;
+            if (c->ignore_io_errors)
+                return 0;
+            else
+                return ret;
         }
 
         ff_hls_write_playlist_version(c->m3u8_out, 7);
@@ -1565,8 +1572,12 @@  static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
         set_http_options(&opts, c);
         ret = dashenc_io_open(s, &os->out, os->temp_path, &opts);
         av_dict_free(&opts);
-        if (ret < 0)
-            return ret;
+        if (ret < 0) {
+            if (c->ignore_io_errors)
+                return 0;
+            else
+                return ret;
+        }
     }
 
     //write out the data immediately in streaming mode
@@ -1577,9 +1588,11 @@  static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
             write_styp(os->ctx->pb);
         avio_flush(os->ctx->pb);
         len = avio_get_dyn_buf (os->ctx->pb, &buf);
-        avio_write(os->out, buf + os->written_len, len - os->written_len);
+        if (os->out) {
+            avio_write(os->out, buf + os->written_len, len - os->written_len);
+            avio_flush(os->out);
+        }
         os->written_len = len;
-        avio_flush(os->out);
     }
 
     return ret;
@@ -1670,6 +1683,7 @@  static const AVOption options[] = {
     { "auto", "select segment file format based on codec", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_AUTO }, 0, UINT_MAX,   E, "segment_type"},
     { "mp4", "make segment file in ISOBMFF format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_MP4 }, 0, UINT_MAX,   E, "segment_type"},
     { "webm", "make segment file in WebM format", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_TYPE_WEBM }, 0, UINT_MAX,   E, "segment_type"},
+    { "ignore_io_errors", "Ignore IO errors during open and write. Useful for long-duration runs with network output", OFFSET(ignore_io_errors), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
     { NULL },
 };