ticket-id: #6541 when use hls fmp4 muxer, the extention name is not .m4s, this code can fix it.
Signed-off-by: Steven Liu <l...@onvideo.cn> --- libavformat/hlsenc.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 8a233270b5..65650e03a4 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1286,14 +1286,19 @@ fail: return err; } -static const char * get_default_pattern_localtime_fmt(void) +static const char * get_default_pattern_localtime_fmt(AVFormatContext *s) { char b[21]; time_t t = time(NULL); struct tm *p, tmbuf; + HLSContext *hls = s->priv_data; + p = localtime_r(&t, &tmbuf); // no %s support when strftime returned error or left format string unchanged // also no %s support on MSVC, which invokes the invalid parameter handler on unsupported format strings, instead of returning an error + if (hls->segment_type == SEGMENT_TYPE_FMP4) { + return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.m4s" : "-%s.m4s"; + } return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts"; } @@ -1303,16 +1308,19 @@ static int hls_write_header(AVFormatContext *s) int ret, i; char *p; const char *pattern = "%d.ts"; - const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(); + const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s); const char *vtt_pattern = "%d.vtt"; AVDictionary *options = NULL; int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size > 0); int basename_size; int vtt_basename_size; - if (hls->segment_type == SEGMENT_TYPE_FMP4 && byterange_mode) { - av_log(s, AV_LOG_WARNING, "Have not support fmp4 byterange mode yet now\n"); - return AVERROR_PATCHWELCOME; + if (hls->segment_type == SEGMENT_TYPE_FMP4) { + if (byterange_mode) { + av_log(s, AV_LOG_WARNING, "Have not support fmp4 byterange mode yet now\n"); + return AVERROR_PATCHWELCOME; + } + 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_FORMATTED_DATETIME)) { @@ -1391,6 +1399,9 @@ static int hls_write_header(AVFormatContext *s) if (hls->flags & HLS_SINGLE_FILE) pattern = ".ts"; + if (hls->segment_type == SEGMENT_TYPE_FMP4) + pattern = "m4s"; + if (hls->use_localtime) { basename_size = strlen(s->filename) + strlen(pattern_localtime_fmt) + 1; } else { -- 2.11.0 (Apple Git-81) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel