diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-04-08 23:41:17 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-05-10 22:23:28 +0200 |
commit | 21553d2082a8b5997c25b7b13a9b3426ac43e116 (patch) | |
tree | 374c5965bef0a8ab540ca10cf84d166bed25dbba /libavformat/hlsenc.c | |
parent | 6b44f6839d90df344597eba385d2a589334e04a6 (diff) | |
download | ffmpeg-21553d2082a8b5997c25b7b13a9b3426ac43e116.tar.gz |
avformat/hlsenc: Simplify setting basename with av_asprintf()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/hlsenc.c')
-rw-r--r-- | libavformat/hlsenc.c | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 5517cb4354..d80852739e 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2739,15 +2739,21 @@ static int hls_init(AVFormatContext *s) int i = 0; int j = 0; HLSContext *hls = s->priv_data; - const char *pattern = "%d.ts"; + const char *pattern; VariantStream *vs = NULL; - int basename_size = 0; - const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s); const char *vtt_pattern = hls->flags & HLS_SINGLE_FILE ? ".vtt" : "%d.vtt"; char *p = NULL; int http_base_proto = ff_is_http_proto(s->url); int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1; + if (hls->use_localtime) { + pattern = get_default_pattern_localtime_fmt(s); + } else { + pattern = hls->segment_type == SEGMENT_TYPE_FMP4 ? "%d.m4s" : "%d.ts"; + if (hls->flags & HLS_SINGLE_FILE) + pattern += 2; + } + hls->has_default_key = 0; hls->has_video_m3u8 = 0; ret = update_variant_stream_info(s); @@ -2792,9 +2798,6 @@ static int hls_init(AVFormatContext *s) } } - if (hls->segment_type == SEGMENT_TYPE_FMP4) { - pattern = "%d.m4s"; - } if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) || (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_MICROSECONDS_SINCE_EPOCH) || (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) { @@ -2868,34 +2871,16 @@ static int hls_init(AVFormatContext *s) if (ret < 0) return ret; } else { - if (hls->flags & HLS_SINGLE_FILE) { - if (hls->segment_type == SEGMENT_TYPE_FMP4) { - pattern = ".m4s"; - } else { - pattern = ".ts"; - } - } - - if (hls->use_localtime) { - basename_size = strlen(vs->m3u8_name) + strlen(pattern_localtime_fmt) + 1; - } else { - basename_size = strlen(vs->m3u8_name) + strlen(pattern) + 1; - } + p = strrchr(vs->m3u8_name, '.'); + if (p) + *p = '\0'; - vs->basename = av_malloc(basename_size); + vs->basename = av_asprintf("%s%s", vs->m3u8_name, pattern); if (!vs->basename) return AVERROR(ENOMEM); - av_strlcpy(vs->basename, vs->m3u8_name, basename_size); - - p = strrchr(vs->basename, '.'); if (p) - *p = '\0'; - if (hls->use_localtime) { - av_strlcat(vs->basename, pattern_localtime_fmt, basename_size); - } else { - av_strlcat(vs->basename, pattern, basename_size); - } + *p = '.'; } if (hls->segment_type == SEGMENT_TYPE_FMP4) { |