diff mbox series

[FFmpeg-devel,v3] avformat/hlsenc: Respect `append_list` flag in subtitle

Message ID 20240930194020.80185-1-jonbae77@gmail.com
State New
Headers show
Series [FFmpeg-devel,v3] avformat/hlsenc: Respect `append_list` flag in subtitle | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Jonathan Baecker Sept. 30, 2024, 7:40 p.m. UTC
Apply Stevens suggestion.

Original description:
Ensure that when the `-hls_flags append_list` option is set,
that *.vtt files in stream_vtt.m3u8 are correctly updated.
This fixes https://trac.ffmpeg.org/ticket/11208
---
 libavformat/hlsenc.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

--
2.46.2

Comments

Steven Liu Oct. 4, 2024, 10:06 a.m. UTC | #1
Jonathan Baecker <jonbae77@gmail.com> 于2024年10月1日周二 03:51写道:
>
> Apply Stevens suggestion.
>
> Original description:
> Ensure that when the `-hls_flags append_list` option is set,
> that *.vtt files in stream_vtt.m3u8 are correctly updated.
> This fixes https://trac.ffmpeg.org/ticket/11208
> ---
>  libavformat/hlsenc.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 571d6b2752..8d4322796d 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1202,6 +1202,22 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
>      return 0;
>  }
>
> +static int extract_segment_number(const char *filename) {
> +    const char *dot = strrchr(filename, '.');
> +    const char *num_start = dot - 1;
> +
> +    while (num_start > filename && *num_start >= '0' && *num_start <= '9') {
> +        num_start--;
> +    }
> +
> +    num_start++;
> +
> +    if (num_start == dot)
> +        return -1;
> +
> +    return atoi(num_start);
> +}
> +
>  static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs)
>  {
>      HLSContext *hls = s->priv_data;
> @@ -1295,6 +1311,20 @@ static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs
>                      goto fail;
>                  }
>                  ff_format_set_url(vs->avf, new_file);
> +
> +                if (vs->has_subtitle) {
> +                    int vtt_index = extract_segment_number(line);
> +                    const char *vtt_basename = av_basename(vs->vtt_basename);
> +                    int len = strlen(vtt_basename) + 11;
> +                    char *vtt_file = av_mallocz(len);
> +                    if (!vtt_file) {
> +                        ret = AVERROR(ENOMEM);
> +                        goto fail;
> +                    }
> +                    snprintf(vtt_file, len, vtt_basename, vtt_index);
> +                    ff_format_set_url(vs->vtt_avf, vtt_file);
> +                }
> +
>                  is_segment = 0;
>                  new_start_pos = avio_tell(vs->avf->pb);
>                  vs->size = new_start_pos - vs->start_pos;
> --
> 2.46.2
>
> _______________________________________________
> 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".

LGTM
Will apply after 48 hours if no more comments.


Thanks
Steven
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 571d6b2752..8d4322796d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1202,6 +1202,22 @@  static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
     return 0;
 }

+static int extract_segment_number(const char *filename) {
+    const char *dot = strrchr(filename, '.');
+    const char *num_start = dot - 1;
+
+    while (num_start > filename && *num_start >= '0' && *num_start <= '9') {
+        num_start--;
+    }
+
+    num_start++;
+
+    if (num_start == dot)
+        return -1;
+
+    return atoi(num_start);
+}
+
 static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs)
 {
     HLSContext *hls = s->priv_data;
@@ -1295,6 +1311,20 @@  static int parse_playlist(AVFormatContext *s, const char *url, VariantStream *vs
                     goto fail;
                 }
                 ff_format_set_url(vs->avf, new_file);
+
+                if (vs->has_subtitle) {
+                    int vtt_index = extract_segment_number(line);
+                    const char *vtt_basename = av_basename(vs->vtt_basename);
+                    int len = strlen(vtt_basename) + 11;
+                    char *vtt_file = av_mallocz(len);
+                    if (!vtt_file) {
+                        ret = AVERROR(ENOMEM);
+                        goto fail;
+                    }
+                    snprintf(vtt_file, len, vtt_basename, vtt_index);
+                    ff_format_set_url(vs->vtt_avf, vtt_file);
+                }
+
                 is_segment = 0;
                 new_start_pos = avio_tell(vs->avf->pb);
                 vs->size = new_start_pos - vs->start_pos;