recover segments duration time by hls_time after init hls window. This is reuqested by Ibrahim Tachijian
Signed-off-by: LiuQi <li...@gosun.com> --- libavformat/hlsenc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index e65f002..f5ceb60 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -85,6 +85,7 @@ typedef struct HLSContext { AVFormatContext *vtt_avf; float time; // Set by a private option. + float init_time; // Set by a private option. int max_nb_segments; // Set by a private option. int wrap; // Set by a private option. uint32_t flags; // enum HLSFlags @@ -706,7 +707,7 @@ static int hls_write_header(AVFormatContext *s) int vtt_basename_size; hls->sequence = hls->start_sequence; - hls->recording_time = hls->time * AV_TIME_BASE; + hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE; hls->start_pts = AV_NOPTS_VALUE; if (hls->format_options_str) { @@ -860,9 +861,19 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = s->streams[pkt->stream_index]; int64_t end_pts = hls->recording_time * hls->number; int is_ref_pkt = 1; + int init_list_dur = 0; + int after_init_list_dur = 0; int ret, can_split = 1; int stream_index = 0; + if (hls->sequence - hls->nb_entries > hls->start_sequence && hls->init_time > 0) { + /* reset end_pts, hls->recording_time at end of the init hls list */ + init_list_dur = hls->init_time * hls->nb_entries * AV_TIME_BASE; + after_init_list_dur = (hls->sequence - hls->nb_entries ) * hls->time * AV_TIME_BASE; + hls->recording_time = hls->time * AV_TIME_BASE; + end_pts = init_list_dur + after_init_list_dur ; + } + if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) { oc = hls->vtt_avf; stream_index = 0; @@ -972,6 +983,7 @@ static int hls_write_trailer(struct AVFormatContext *s) static const AVOption options[] = { {"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E}, {"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E}, + {"hls_init_time", "set segment length in seconds at init list", OFFSET(init_time), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, FLT_MAX, E}, {"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E}, {"hls_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, {"hls_vtt_options","set hls vtt list of options for the container format used for hls", OFFSET(vtt_format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E}, -- 2.7.4 (Apple Git-66) Test : /root/ffmpeg_patched -analyzeduration 1000000 -i udp://MCAST_ADDR:3301 -map 0:0 -map 0:1 -c:v libx264 -preset superfast -g 25 -b:v 900k -maxrate 900k -bufsize 2000k -filter:v yadif -c:a libfdk_aac -b:a 64k -hls_time 5 *-hls_init_time 1* -hls_list_size 10 -hls_allow_cache 0 -hls_flags delete_segments -f hls /tmp/playlist.m3u8 The output M3U8 of patched ffmpeg: #EXTM3U #EXT-X-VERSION:3 #EXT-X-ALLOW-CACHE:NO #EXT-X-TARGETDURATION:5 #EXT-X-MEDIA-SEQUENCE:3 #EXTINF:1.000000, playlist3.ts #EXTINF:1.000000, playlist4.ts #EXTINF:1.000000, playlist5.ts #EXTINF:1.000000, playlist6.ts #EXTINF:1.000000, playlist7.ts #EXTINF:1.000000, playlist8.ts #EXTINF:1.600000, playlist9.ts #EXTINF:1.000000, playlist10.ts #EXTINF:4.000000, playlist11.ts #EXTINF:5.000000, playlist12.ts
0001-add-option-hls_init_time-to-set-init-hls-window-segm.patch
Description: Binary data
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel