]> git.sesse.net Git - ffmpeg/commitdiff
add split_by_time flag for support splite mpegts segment at non-keyframe
authorSteven Liu <lingjiujianke@gmail.com>
Wed, 6 Jul 2016 22:51:20 +0000 (06:51 +0800)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 11 Jul 2016 10:20:40 +0000 (12:20 +0200)
support split hls segment at duration set by hls_time

Signed-off-by: LiuQi <liuqi@gosun.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
doc/muxers.texi
libavformat/hlsenc.c

index c2ca0ba92d5c92a4e1179b1d6890d1b2039aec03..d416c420e668489b778fcd447c3a69d2155f5dd0 100644 (file)
@@ -495,6 +495,12 @@ Will produce the playlist, @file{out.m3u8}, and a single segment file,
 Segment files removed from the playlist are deleted after a period of time
 equal to the duration of the segment plus the duration of the playlist.
 
+@item hls_flags split_by_time
+If this flags is set, allow segments to start on frames other than keyframes.
+Thisimproves behavior on some players when the time between keyframes is
+inconsistent, but may make things worse on others, and can cause some oddities
+during seeking. This flag should be used with hls_time option.
+
 @item hls_playlist_type event
 Emit @code{#EXT-X-PLAYLIST-TYPE:EVENT} in the m3u8 header. Forces
 @option{hls_list_size} to 0; the playlist can only be appended to.
index a9fa5d8aef164c5168aa4c28705f4070ac24b690..5dc518d9ada91cfecc59c480981082d6c5527234 100644 (file)
@@ -62,6 +62,7 @@ typedef enum HLSFlags {
     HLS_ROUND_DURATIONS = (1 << 2),
     HLS_DISCONT_START = (1 << 3),
     HLS_OMIT_ENDLIST = (1 << 4),
+    HLS_SPLIT_BY_TIME = (1 << 5),
 } HLSFlags;
 
 typedef enum {
@@ -813,7 +814,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (hls->has_video) {
         can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
-                    pkt->flags & AV_PKT_FLAG_KEY;
+                    ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME));
         is_ref_pkt = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO;
     }
     if (pkt->pts == AV_NOPTS_VALUE)
@@ -923,6 +924,7 @@ static const AVOption options[] = {
     {"round_durations", "round durations in m3u8 to whole numbers", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_ROUND_DURATIONS }, 0, UINT_MAX,   E, "flags"},
     {"discont_start", "start the playlist with a discontinuity tag", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_DISCONT_START }, 0, UINT_MAX,   E, "flags"},
     {"omit_endlist", "Do not append an endlist when ending stream", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_OMIT_ENDLIST }, 0, UINT_MAX,   E, "flags"},
+    {"split_by_time", "split the hls segment by time which user set by hls_time", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SPLIT_BY_TIME }, 0, UINT_MAX,   E, "flags"},
     {"use_localtime", "set filename expansion with strftime at segment creation", OFFSET(use_localtime), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
     {"use_localtime_mkdir", "create last directory component in strftime-generated filename", OFFSET(use_localtime_mkdir), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E },
     {"hls_playlist_type", "set the HLS playlist type", OFFSET(pl_type), AV_OPT_TYPE_INT, {.i64 = PLAYLIST_TYPE_NONE }, 0, PLAYLIST_TYPE_NB-1, E, "pl_type" },