Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls
@ 2022-10-10 12:08 gnattu
  2022-10-11  2:55 ` Steven Liu
  0 siblings, 1 reply; 5+ messages in thread
From: gnattu @ 2022-10-10 12:08 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: gnattu

Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream
recording.
Add an option to retry a failed segment to ensure the output file is
a complete stream.

Signed-off-by: gnattu <gnattuoc@me.com>
---
Fixed commit message wrap
 libavformat/hls.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
     int http_persistent;
     int http_multiple;
     int http_seekable;
+    int seg_max_retry;
     AVIOContext *playlist_pb;
     HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
     int ret;
     int just_opened = 0;
     int reload_count = 0;
+    int segment_retries = 0;
     struct segment *seg;
 
 restart:
@@ -1563,9 +1565,18 @@ reload:
             av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" of playlist %d\n",
                    v->cur_seq_no,
                    v->index);
-            v->cur_seq_no += 1;
+            if (segment_retries >= c->seg_max_retry) {
+                av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of playlist %d failed too many times, skipping\n",
+                       v->cur_seq_no,
+                       v->index);
+                v->cur_seq_no += 1;
+                segment_retries = 0;
+            } else {
+                segment_retries += 1;
+            }
             goto reload;
         }
+        segment_retries = 0;
         just_opened = 1;
     }
 
@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
         OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
     {"seg_format_options", "Set options for segment demuxer",
         OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+    {"seg_max_retry", "Maximum number of times to reload a segment on error.",
+     OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
     {NULL}
 };
 
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls
  2022-10-10 12:08 [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls gnattu
@ 2022-10-11  2:55 ` Steven Liu
  2022-10-11  6:19   ` Steven Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Liu @ 2022-10-11  2:55 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: gnattu

gnattu <gnattuoc@me.com> 于2022年10月10日周一 20:09写道:
>
> Current HLS implementation simply skip a failed segment to catch up
> the stream, but this is not optimal for some use cases like livestream
> recording.
> Add an option to retry a failed segment to ensure the output file is
> a complete stream.
>
> Signed-off-by: gnattu <gnattuoc@me.com>
> ---
> Fixed commit message wrap
>  libavformat/hls.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index e622425e80..2b977f9132 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -225,6 +225,7 @@ typedef struct HLSContext {
>      int http_persistent;
>      int http_multiple;
>      int http_seekable;
> +    int seg_max_retry;
>      AVIOContext *playlist_pb;
>      HLSCryptoContext  crypto_ctx;
>  } HLSContext;
> @@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
>      int ret;
>      int just_opened = 0;
>      int reload_count = 0;
> +    int segment_retries = 0;
>      struct segment *seg;
>
>  restart:
> @@ -1563,9 +1565,18 @@ reload:
>              av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" of playlist %d\n",
>                     v->cur_seq_no,
>                     v->index);
> -            v->cur_seq_no += 1;
> +            if (segment_retries >= c->seg_max_retry) {
> +                av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of playlist %d failed too many times, skipping\n",
> +                       v->cur_seq_no,
> +                       v->index);
> +                v->cur_seq_no += 1;
> +                segment_retries = 0;
> +            } else {
> +                segment_retries += 1;
> +            }
>              goto reload;
>          }
> +        segment_retries = 0;
>          just_opened = 1;
>      }
>
> @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
>          OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
>      {"seg_format_options", "Set options for segment demuxer",
>          OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
> +    {"seg_max_retry", "Maximum number of times to reload a segment on error.",
> +     OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
>      {NULL}
>  };
>
> --
> 2.37.0 (Apple Git-136)
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Not sure this functions is usefull. because there have a option named
"max_reload" for  playlist reload,
but this can be used for segment reload.

Perhaps there have some sence need reload segment, so this lookd ok to me.



Thanks
Steven
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls
  2022-10-11  2:55 ` Steven Liu
@ 2022-10-11  6:19   ` Steven Liu
  2022-10-11 12:14     ` ChenLiucheng
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Liu @ 2022-10-11  6:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: gnattu

Steven Liu <lingjiujianke@gmail.com> 于2022年10月11日周二 10:55写道:
>
> gnattu <gnattuoc@me.com> 于2022年10月10日周一 20:09写道:
> >
> > Current HLS implementation simply skip a failed segment to catch up
> > the stream, but this is not optimal for some use cases like livestream
> > recording.
> > Add an option to retry a failed segment to ensure the output file is
> > a complete stream.
> >
> > Signed-off-by: gnattu <gnattuoc@me.com>
> > ---
> > Fixed commit message wrap
> >  libavformat/hls.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/hls.c b/libavformat/hls.c
> > index e622425e80..2b977f9132 100644
> > --- a/libavformat/hls.c
> > +++ b/libavformat/hls.c
> > @@ -225,6 +225,7 @@ typedef struct HLSContext {
> >      int http_persistent;
> >      int http_multiple;
> >      int http_seekable;
> > +    int seg_max_retry;
> >      AVIOContext *playlist_pb;
> >      HLSCryptoContext  crypto_ctx;
> >  } HLSContext;
> > @@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
> >      int ret;
> >      int just_opened = 0;
> >      int reload_count = 0;
> > +    int segment_retries = 0;
> >      struct segment *seg;
> >
> >  restart:
> > @@ -1563,9 +1565,18 @@ reload:
> >              av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" of playlist %d\n",
> >                     v->cur_seq_no,
> >                     v->index);
> > -            v->cur_seq_no += 1;
> > +            if (segment_retries >= c->seg_max_retry) {
> > +                av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of playlist %d failed too many times, skipping\n",
> > +                       v->cur_seq_no,
> > +                       v->index);
> > +                v->cur_seq_no += 1;
> > +                segment_retries = 0;
> > +            } else {
> > +                segment_retries += 1;
> > +            }
> >              goto reload;
> >          }
> > +        segment_retries = 0;
> >          just_opened = 1;
> >      }
> >
> > @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
> >          OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
> >      {"seg_format_options", "Set options for segment demuxer",
> >          OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
> > +    {"seg_max_retry", "Maximum number of times to reload a segment on error.",
> > +     OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
BTW, Document should add describe about the option.
> >      {NULL}
> >  };
> >
> > --
> > 2.37.0 (Apple Git-136)
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
> Not sure this functions is usefull. because there have a option named
> "max_reload" for  playlist reload,
> but this can be used for segment reload.
>
> Perhaps there have some sence need reload segment, so this lookd ok to me.

>
>
>
> Thanks
> Steven
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls
  2022-10-11  6:19   ` Steven Liu
@ 2022-10-11 12:14     ` ChenLiucheng
  2022-10-11 13:17       ` Steven Liu
  0 siblings, 1 reply; 5+ messages in thread
From: ChenLiucheng @ 2022-10-11 12:14 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Liu Steven



> On Oct 11, 2022, at 14:19, Steven Liu <lingjiujianke@gmail.com <mailto:lingjiujianke@gmail.com>> wrote:
> 
> Steven Liu <lingjiujianke@gmail.com <mailto:lingjiujianke@gmail.com>> 于2022年10月11日周二 10:55写道:
>> 
>> gnattu <gnattuoc@me.com <mailto:gnattuoc@me.com>> 于2022年10月10日周一 20:09写道:
>>> 
>>> Current HLS implementation simply skip a failed segment to catch up
>>> the stream, but this is not optimal for some use cases like livestream
>>> recording.
>>> Add an option to retry a failed segment to ensure the output file is
>>> a complete stream.
>>> 
>>> Signed-off-by: gnattu <gnattuoc@me.com <mailto:gnattuoc@me.com>>
>>> ---
>>> Fixed commit message wrap
>>> libavformat/hls.c | 15 ++++++++++++++-
>>> 1 file changed, 14 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/libavformat/hls.c b/libavformat/hls.c
>>> index e622425e80..2b977f9132 100644
>>> --- a/libavformat/hls.c
>>> +++ b/libavformat/hls.c
>>> @@ -225,6 +225,7 @@ typedef struct HLSContext {
>>>     int http_persistent;
>>>     int http_multiple;
>>>     int http_seekable;
>>> +    int seg_max_retry;
>>>     AVIOContext *playlist_pb;
>>>     HLSCryptoContext  crypto_ctx;
>>> } HLSContext;
>>> @@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
>>>     int ret;
>>>     int just_opened = 0;
>>>     int reload_count = 0;
>>> +    int segment_retries = 0;
>>>     struct segment *seg;
>>> 
>>> restart:
>>> @@ -1563,9 +1565,18 @@ reload:
>>>             av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" of playlist %d\n",
>>>                    v->cur_seq_no,
>>>                    v->index);
>>> -            v->cur_seq_no += 1;
>>> +            if (segment_retries >= c->seg_max_retry) {
>>> +                av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of playlist %d failed too many times, skipping\n",
>>> +                       v->cur_seq_no,
>>> +                       v->index);
>>> +                v->cur_seq_no += 1;
>>> +                segment_retries = 0;
>>> +            } else {
>>> +                segment_retries += 1;
>>> +            }
>>>             goto reload;
>>>         }
>>> +        segment_retries = 0;
>>>         just_opened = 1;
>>>     }
>>> 
>>> @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
>>>         OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
>>>     {"seg_format_options", "Set options for segment demuxer",
>>>         OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
>>> +    {"seg_max_retry", "Maximum number of times to reload a segment on error.",
>>> +     OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
> BTW, Document should add describe about the option.
>>>     {NULL}
>>> };
>>> 
>>> --
>>> 2.37.0 (Apple Git-136)
>>> 
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>> 
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> 
>> Not sure this functions is usefull. because there have a option named
>> "max_reload" for  playlist reload,
>> but this can be used for segment reload.
>> 
>> Perhaps there have some sence need reload segment, so this lookd ok to me.
> 
>> 
>> 
>> 
>> Thanks
>> Steven


May I have more clarification on this? Like on which aspect it need to have more details to better describe this option? I tried to keep the help text as concise as possible and I probably missed something here. 
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls
  2022-10-11 12:14     ` ChenLiucheng
@ 2022-10-11 13:17       ` Steven Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Liu @ 2022-10-11 13:17 UTC (permalink / raw)
  To: ChenLiucheng; +Cc: ffmpeg-devel

ChenLiucheng <gnattuoc@me.com> 于2022年10月11日周二 20:14写道:
>
>
>
> On Oct 11, 2022, at 14:19, Steven Liu <lingjiujianke@gmail.com> wrote:
>
> Steven Liu <lingjiujianke@gmail.com> 于2022年10月11日周二 10:55写道:
>
>
> gnattu <gnattuoc@me.com> 于2022年10月10日周一 20:09写道:
>
>
> Current HLS implementation simply skip a failed segment to catch up
> the stream, but this is not optimal for some use cases like livestream
> recording.
> Add an option to retry a failed segment to ensure the output file is
> a complete stream.
>
> Signed-off-by: gnattu <gnattuoc@me.com>
> ---
> Fixed commit message wrap
> libavformat/hls.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index e622425e80..2b977f9132 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -225,6 +225,7 @@ typedef struct HLSContext {
>     int http_persistent;
>     int http_multiple;
>     int http_seekable;
> +    int seg_max_retry;
>     AVIOContext *playlist_pb;
>     HLSCryptoContext  crypto_ctx;
> } HLSContext;
> @@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
>     int ret;
>     int just_opened = 0;
>     int reload_count = 0;
> +    int segment_retries = 0;
>     struct segment *seg;
>
> restart:
> @@ -1563,9 +1565,18 @@ reload:
>             av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" of playlist %d\n",
>                    v->cur_seq_no,
>                    v->index);
> -            v->cur_seq_no += 1;
> +            if (segment_retries >= c->seg_max_retry) {
> +                av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of playlist %d failed too many times, skipping\n",
> +                       v->cur_seq_no,
> +                       v->index);
> +                v->cur_seq_no += 1;
> +                segment_retries = 0;
> +            } else {
> +                segment_retries += 1;
> +            }
>             goto reload;
>         }
> +        segment_retries = 0;
>         just_opened = 1;
>     }
>
> @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
>         OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
>     {"seg_format_options", "Set options for segment demuxer",
>         OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
> +    {"seg_max_retry", "Maximum number of times to reload a segment on error.",
> +     OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
>
> BTW, Document should add describe about the option.
>
>     {NULL}
> };
>
> --
> 2.37.0 (Apple Git-136)
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
>
> Not sure this functions is usefull. because there have a option named
> "max_reload" for  playlist reload,
> but this can be used for segment reload.
>
> Perhaps there have some sence need reload segment, so this lookd ok to me.
>
>
>
>
>
> Thanks
> Steven
>
>
>
> May I have more clarification on this? Like on which aspect it need to have more details to better describe this option? I tried to keep the help text as concise as possible and I probably missed something here.
Do you mean documents? If yes, you need modify the file
./doc/demuxers.texi and add the option description, you can reference
the "max_reload" option.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-11 13:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 12:08 [FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls gnattu
2022-10-11  2:55 ` Steven Liu
2022-10-11  6:19   ` Steven Liu
2022-10-11 12:14     ` ChenLiucheng
2022-10-11 13:17       ` Steven Liu

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git