[FFmpeg-devel] [PATCH 4/6] avformat/hlsenc: Simplify setting subtitle basename with av_asprintf
Steven Liu
lq at chinaffmpeg.org
Sun May 10 06:03:37 EEST 2020
> 2020年5月10日 上午3:15,Andreas Rheinhardt <andreas.rheinhardt at gmail.com> 写道:
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at 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 at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
LGTM
Thanks
Steven Liu
More information about the ffmpeg-devel
mailing list