[FFmpeg-devel] [PATCH] avformat/hlsenc: fix hls fmp4 extention name bug

Steven Liu lq at chinaffmpeg.org
Thu Jul 20 12:52:57 EEST 2017


ticket-id: #6541
when use hls fmp4 muxer, the extention name is not .m4s, this
code can fix it.

Signed-off-by: Steven Liu <lq at onvideo.cn>
---
 libavformat/hlsenc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 8a233270b5..911f6068c2 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)) {
-- 
2.11.0 (Apple Git-81)





More information about the ffmpeg-devel mailing list