diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-04-08 22:57:50 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-05-10 21:41:22 +0200 |
commit | 6b44f6839d90df344597eba385d2a589334e04a6 (patch) | |
tree | 9cece1d15971f099d7c311af19b9afa33988dfb4 /libavformat | |
parent | 940601616e4f39d7aa9da20a5e0b5e943b9ac2ca (diff) | |
download | ffmpeg-6b44f6839d90df344597eba385d2a589334e04a6.tar.gz |
avformat/hlsenc: Simplify setting subtitle basename with av_asprintf
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/hlsenc.c | 20 |
1 files 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) { |