diff mbox series

[FFmpeg-devel,4/6] avformat/hlsenc: Simplify setting subtitle basename with av_asprintf

Message ID 20200509191509.9812-4-andreas.rheinhardt@gmail.com
State Accepted
Commit 6b44f6839d90df344597eba385d2a589334e04a6
Headers show
Series [FFmpeg-devel,1/6] avformat/hlsenc: Don't reset AVIOContext pointer manually a second time
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt May 9, 2020, 7:15 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
This patch is designed not to change the output at all. Yet I wonder if
instead of p = strrchr(vs->m3u8_name, '.') it should not better be p =
strrchr(av_basename(vs->m3u8_name), '.'). Otherwise in a path like
"./hlsstream/master" everything after '.' will be treated as extension
which does not seem to be intended. The same remark also applies to e.g.
the next patch.

 libavformat/hlsenc.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Steven Liu May 10, 2020, 3:03 a.m. UTC | #1
> 2020年5月10日 上午3:15,Andreas Rheinhardt <andreas.rheinhardt@gmail.com> 写道:
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> This patch is designed not to change the output at all. Yet I wonder if
> instead of p = strrchr(vs->m3u8_name, '.') it should not better be p =
> strrchr(av_basename(vs->m3u8_name), '.'). Otherwise in a path like
> "./hlsstream/master" everything after '.' will be treated as extension
> which does not seem to be intended. The same remark also applies to e.g.
> the next patch.
> 
> libavformat/hlsenc.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 2a0d17baea..5517cb4354 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2743,9 +2743,8 @@ static int hls_init(AVFormatContext *s)
>     VariantStream *vs = NULL;
>     int basename_size = 0;
>     const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s);
> -    const char *vtt_pattern = "%d.vtt";
> +    const char *vtt_pattern = hls->flags & HLS_SINGLE_FILE ? ".vtt" : "%d.vtt";
>     char *p = NULL;
> -    int vtt_basename_size = 0;
>     int http_base_proto = ff_is_http_proto(s->url);
>     int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
> 
> @@ -2954,28 +2953,25 @@ static int hls_init(AVFormatContext *s)
>             if (!vs->vtt_oformat)
>                 return AVERROR_MUXER_NOT_FOUND;
> 
> -            if (hls->flags & HLS_SINGLE_FILE)
> -                vtt_pattern = ".vtt";
> -            vtt_basename_size = strlen(vs->m3u8_name) + strlen(vtt_pattern) + 1;
> +            p = strrchr(vs->m3u8_name, '.');
> +            if (p)
> +                *p = '\0';
> 
> -            vs->vtt_basename = av_malloc(vtt_basename_size);
> +            vs->vtt_basename = av_asprintf("%s%s", vs->m3u8_name, vtt_pattern);
>             if (!vs->vtt_basename)
>                 return AVERROR(ENOMEM);
> -            av_strlcpy(vs->vtt_basename, vs->m3u8_name, vtt_basename_size);
> -            p = strrchr(vs->vtt_basename, '.');
> -            if (p)
> -                *p = '\0';
> 
>             if (hls->subtitle_filename) {
>                 ret = format_name(hls->subtitle_filename, &vs->vtt_m3u8_name, i, vs->varname);
>                 if (ret < 0)
>                     return ret;
>             } else {
> -                vs->vtt_m3u8_name = av_asprintf("%s_vtt.m3u8", vs->vtt_basename);
> +                vs->vtt_m3u8_name = av_asprintf("%s_vtt.m3u8", vs->m3u8_name);
>                 if (!vs->vtt_m3u8_name)
>                     return AVERROR(ENOMEM);
>             }
> -            av_strlcat(vs->vtt_basename, vtt_pattern, vtt_basename_size);
> +            if (p)
> +                *p = '.';
>         }
> 
>         if (hls->baseurl) {
> -- 
> 2.20.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".

LGTM

Thanks

Steven Liu
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 2a0d17baea..5517cb4354 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2743,9 +2743,8 @@  static int hls_init(AVFormatContext *s)
     VariantStream *vs = NULL;
     int basename_size = 0;
     const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s);
-    const char *vtt_pattern = "%d.vtt";
+    const char *vtt_pattern = hls->flags & HLS_SINGLE_FILE ? ".vtt" : "%d.vtt";
     char *p = NULL;
-    int vtt_basename_size = 0;
     int http_base_proto = ff_is_http_proto(s->url);
     int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1;
 
@@ -2954,28 +2953,25 @@  static int hls_init(AVFormatContext *s)
             if (!vs->vtt_oformat)
                 return AVERROR_MUXER_NOT_FOUND;
 
-            if (hls->flags & HLS_SINGLE_FILE)
-                vtt_pattern = ".vtt";
-            vtt_basename_size = strlen(vs->m3u8_name) + strlen(vtt_pattern) + 1;
+            p = strrchr(vs->m3u8_name, '.');
+            if (p)
+                *p = '\0';
 
-            vs->vtt_basename = av_malloc(vtt_basename_size);
+            vs->vtt_basename = av_asprintf("%s%s", vs->m3u8_name, vtt_pattern);
             if (!vs->vtt_basename)
                 return AVERROR(ENOMEM);
-            av_strlcpy(vs->vtt_basename, vs->m3u8_name, vtt_basename_size);
-            p = strrchr(vs->vtt_basename, '.');
-            if (p)
-                *p = '\0';
 
             if (hls->subtitle_filename) {
                 ret = format_name(hls->subtitle_filename, &vs->vtt_m3u8_name, i, vs->varname);
                 if (ret < 0)
                     return ret;
             } else {
-                vs->vtt_m3u8_name = av_asprintf("%s_vtt.m3u8", vs->vtt_basename);
+                vs->vtt_m3u8_name = av_asprintf("%s_vtt.m3u8", vs->m3u8_name);
                 if (!vs->vtt_m3u8_name)
                     return AVERROR(ENOMEM);
             }
-            av_strlcat(vs->vtt_basename, vtt_pattern, vtt_basename_size);
+            if (p)
+                *p = '.';
         }
 
         if (hls->baseurl) {