diff mbox series

[FFmpeg-devel] avformat/hls: add supporting EXT-X-DISCONTINUITY tag

Message ID SL2P216MB0377978D5761EE38123941DFE17C0@SL2P216MB0377.KORP216.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel] avformat/hls: add supporting EXT-X-DISCONTINUITY tag
Related show

Checks

Context Check Description
andriy/default pending
andriy/configure warning Failed to apply patch

Commit Message

김동원님(Dongwon Kim) July 17, 2020, 12:43 a.m. UTC
Signed-off-by: Dongwon Kim <dongwon.kim@sk.com>
---
 libavformat/hls.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--
2.25.1

Comments

Dongwon Kim July 17, 2020, 1 a.m. UTC | #1
I modified setting AVFMT_TS_DISCONT flag on HLS input format depending on
whether "EXT-X-DISCONTINUITY" existed or not in M3U8.
previous, commits is set AVFMT_TS_DISCONT flag unconditionally, whether
"EXT-X-DISCONTINUITY" existed or not, as below
https://github.com/FFmpeg/FFmpeg/commit/d6ac6650b911f0957e69545d7fc25be6b7728705#diff-0e876d29bdcae30d9d256f04bc8795db

So, I added checking and parsing "EXT-X-DISCONTINUITY" syntax, and if it
exists then set AVFMT_TS_DISCONT flag.


2020년 7월 17일 (금) 오전 9:43, 김동원님(Dongwon Kim) <dongwon.kim@sk.com>님이 작성:

> Signed-off-by: Dongwon Kim <dongwon.kim@sk.com>
> ---
>  libavformat/hls.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c index
> ba17c4ed96..5e331ab68f 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -810,6 +810,8 @@ static int parse_playlist(HLSContext *c, const char
> *url,
>              ff_parse_key_value(ptr, (ff_parse_key_val_cb)
> handle_rendition_args,
>                                 &info);
>              new_rendition(c, &info, url);
> +        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
> +            c->ctx->iformat->flags |= AVFMT_TS_DISCONT;
>          } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
>              ret = ensure_playlist(c, &pls, url);
>              if (ret < 0)
> @@ -2406,7 +2408,7 @@ AVInputFormat ff_hls_demuxer = {
>      .long_name      = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
>      .priv_class     = &hls_class,
>      .priv_data_size = sizeof(HLSContext),
> -    .flags          = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT,
> +    .flags          = AVFMT_NOGENSEARCH,
>      .read_probe     = hls_probe,
>      .read_header    = hls_read_header,
>      .read_packet    = hls_read_packet,
> --
> 2.25.1
>
> _______________________________________________
> 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".
Dongwon Kim July 17, 2020, 1:09 a.m. UTC | #2
I modified setting AVFMT_TS_DISCONT flag on HLS input format depending on whether "EXT-X-DISCONTINUITY" existed or not in M3U8.
previous, commits are set "AVFMT_TS_DISCONT" flag unconditionally, whether "EXT-X-DISCONTINUITY" existed or not, as below
https://github.com/FFmpeg/FFmpeg/commit/d6ac6650b911f0957e69545d7fc25be6b7728705#diff-0e876d29bdcae30d9d256f04bc8795db

So, I added checking and parsing "EXT-X-DISCONTINUITY" syntax, and if only it exists then set AVFMT_TS_DISCONT flag.


On Fri, Jul 17, 2020 at 12:43:05AM +0000, Dongwon Kim wrote:
> Signed-off-by: Dongwon Kim <dongwon.kim@sk.com>
> ---
>  libavformat/hls.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c index ba17c4ed96..5e331ab68f 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -810,6 +810,8 @@ static int parse_playlist(HLSContext *c, const char *url,
>              ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,
>                                 &info);
>              new_rendition(c, &info, url);
> +        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
> +            c->ctx->iformat->flags |= AVFMT_TS_DISCONT;
>          } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
>              ret = ensure_playlist(c, &pls, url);
>              if (ret < 0)
> @@ -2406,7 +2408,7 @@ AVInputFormat ff_hls_demuxer = {
>      .long_name      = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
>      .priv_class     = &hls_class,
>      .priv_data_size = sizeof(HLSContext),
> -    .flags          = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT,
> +    .flags          = AVFMT_NOGENSEARCH,
>      .read_probe     = hls_probe,
>      .read_header    = hls_read_header,
>      .read_packet    = hls_read_packet,
> --
> 2.25.1
> 
> _______________________________________________
> 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".
Andreas Rheinhardt July 17, 2020, 1:39 a.m. UTC | #3
김동원님(Dongwon Kim):
> Signed-off-by: Dongwon Kim <dongwon.kim@sk.com>
> ---
>  libavformat/hls.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c index ba17c4ed96..5e331ab68f 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -810,6 +810,8 @@ static int parse_playlist(HLSContext *c, const char *url,
>              ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,
>                                 &info);
>              new_rendition(c, &info, url);
> +        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
> +            c->ctx->iformat->flags |= AVFMT_TS_DISCONT;
>          } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
>              ret = ensure_playlist(c, &pls, url);
>              if (ret < 0)
> @@ -2406,7 +2408,7 @@ AVInputFormat ff_hls_demuxer = {
>      .long_name      = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
>      .priv_class     = &hls_class,
>      .priv_data_size = sizeof(HLSContext),
> -    .flags          = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT,
> +    .flags          = AVFMT_NOGENSEARCH,
>      .read_probe     = hls_probe,
>      .read_header    = hls_read_header,
>      .read_packet    = hls_read_packet,
> --
> 2.25.1
> 
You are modifying the AVInputFormat, not the AVFormatContext. The former
is shared among all AVFormatContexts for hls demuxing and it is actually
meant to be const (and may become const at the next major bump).

- Andreas
Aleksey Skripka July 18, 2020, 5:29 p.m. UTC | #4
Greetings!

unconditional AVFMT_TS_DISCONT also helps to survive when pts rollover in mpegts occurs.
seems like this patch will break again reading long-lasting hls.
Steven Liu July 20, 2020, 2:19 a.m. UTC | #5
김동원님(Dongwon Kim) <dongwon.kim@sk.com> 于2020年7月17日周五 上午8:43写道:
>
> Signed-off-by: Dongwon Kim <dongwon.kim@sk.com>
> ---
>  libavformat/hls.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hls.c b/libavformat/hls.c index ba17c4ed96..5e331ab68f 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -810,6 +810,8 @@ static int parse_playlist(HLSContext *c, const char *url,
>              ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,
>                                 &info);
>              new_rendition(c, &info, url);
> +        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
> +            c->ctx->iformat->flags |= AVFMT_TS_DISCONT;
>          } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
>              ret = ensure_playlist(c, &pls, url);
>              if (ret < 0)
> @@ -2406,7 +2408,7 @@ AVInputFormat ff_hls_demuxer = {
>      .long_name      = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
>      .priv_class     = &hls_class,
>      .priv_data_size = sizeof(HLSContext),
> -    .flags          = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT,
What will happen if keep AVFMT_TS_DISCONT flag?
> +    .flags          = AVFMT_NOGENSEARCH,
>      .read_probe     = hls_probe,
>      .read_header    = hls_read_header,
>      .read_packet    = hls_read_packet,
> --
> 2.25.1
>
> _______________________________________________
> 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".
Philip Langdale July 20, 2020, 4:58 p.m. UTC | #6
On Sat, 18 Jul 2020 20:29:01 +0300
Aleksey Skripka <caspy@undev.ru> wrote:

> Greetings!
> 
> unconditional AVFMT_TS_DISCONT also helps to survive when pts
> rollover in mpegts occurs. seems like this patch will break again
> reading long-lasting hls.
> 

Right.

The flag on the InputFormat says the format _might_ have
discontinuities. The EXT-X-DISCONTINUITY tag shows up in the hls m3u8
each time there actually is a discontinuity.

And this is the part where I complain about how hard the hls demuxer
makes it to propagate discontinuities correctly. It concatenates the
fragments and then passes them on to the mpegts demuxer. This means you
lose the discontinuity information and you can't easily translate it
into an mpegts marker because we don't work at the packet level. *sigh*


--phil
diff mbox series

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c index ba17c4ed96..5e331ab68f 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -810,6 +810,8 @@  static int parse_playlist(HLSContext *c, const char *url,
             ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,
                                &info);
             new_rendition(c, &info, url);
+        } else if (av_strstart(line, "#EXT-X-DISCONTINUITY", &ptr)) {
+            c->ctx->iformat->flags |= AVFMT_TS_DISCONT;
         } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
             ret = ensure_playlist(c, &pls, url);
             if (ret < 0)
@@ -2406,7 +2408,7 @@  AVInputFormat ff_hls_demuxer = {
     .long_name      = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
     .priv_class     = &hls_class,
     .priv_data_size = sizeof(HLSContext),
-    .flags          = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT,
+    .flags          = AVFMT_NOGENSEARCH,
     .read_probe     = hls_probe,
     .read_header    = hls_read_header,
     .read_packet    = hls_read_packet,