[FFmpeg-devel] [PATCH] add option hls_init_time to set init hls window segment duration
Steven Liu
lingjiujianke at gmail.com
Fri Aug 26 15:19:36 EEST 2016
Ignore this thread please. i have send new patch
2016-08-26 17:12 GMT+08:00 Steven Liu <lingjiujianke at gmail.com>:
>
>
> 2016-08-26 17:11 GMT+08:00 Steven Liu <lingjiujianke at gmail.com>:
>
>> recover segments duration time by hls_time after init hls window.
>> This is reuqested by Ibrahim Tachijian
>>
>> Signed-off-by: LiuQi <liuqi at 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)
>>
>> localhost:ffmpeg liuqi$ ./ffmpeg -v verbose -re -i
> ~/Movies/objectC/facebook.mp4 -c copy -f hls -hls_init_time 1 -hls_time 5
> -hls_flags split_by_time output_test.m3u8
> ffmpeg version N-81462-gbcd1153 Copyright (c) 2000-2016 the FFmpeg
> developers
> built with Apple LLVM version 7.3.0 (clang-703.0.31)
> configuration: --enable-fontconfig --enable-gpl --enable-libass
> --enable-libbluray --enable-libfreetype --enable-libmp3lame
> --enable-libspeex --enable-libx264 --enable-libx265 --enable-version3
> libavutil 55. 29.100 / 55. 29.100
> libavcodec 57. 54.100 / 57. 54.100
> libavformat 57. 48.100 / 57. 48.100
> libavdevice 57. 0.102 / 57. 0.102
> libavfilter 6. 55.100 / 6. 55.100
> libswscale 4. 1.100 / 4. 1.100
> libswresample 2. 1.100 / 2. 1.100
> libpostproc 54. 0.100 / 54. 0.100
> [h264 @ 0x7fedf4017600] Reinit context to 1280x720, pix_fmt: yuv420p
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/liuqi/Movies/objectC/f
> acebook.mp4':
> Metadata:
> major_brand : isom
> minor_version : 1
> compatible_brands: isomavc1
> creation_time : 2015-02-02 18:19:19
> Duration: 00:45:02.06, start: 0.000000, bitrate: 2708 kb/s
> Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 /
> 0x31637661), yuv420p, 1280x714 (1280x720) [SAR 1:1 DAR 640:357], 2576 kb/s,
> 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
> Metadata:
> creation_time : 2015-02-02 18:19:19
> handler_name : GPAC ISO Video Handler
> Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
> stereo, fltp, 127 kb/s (default)
> Metadata:
> creation_time : 2015-02-02 18:19:23
> handler_name : GPAC ISO Audio Handler
> [hls @ 0x7fedf4000600] Using AVStream.codec to pass codec parameters to
> muxers is deprecated, use AVStream.codecpar instead.
> Last message repeated 1 times
> [mpegts @ 0x7fedf3008a00] muxrate VBR, pcr every 5 pkts, sdt every
> 2147483647, pat/pmt every 2147483647 pkts
> Output #0, hls, to 'output_test.m3u8':
> Metadata:
> major_brand : isom
> minor_version : 1
> compatible_brands: isomavc1
> encoder : Lavf57.48.100
> Stream #0:0(und): Video: h264 (High), 1 reference frame (avc1 /
> 0x31637661), yuv420p, 1280x714 (0x0) [SAR 1:1 DAR 640:357], q=2-31, 2576
> kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
> Metadata:
> creation_time : 2015-02-02 18:19:19
> handler_name : GPAC ISO Video Handler
> Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz,
> stereo, 127 kb/s (default)
> Metadata:
> creation_time : 2015-02-02 18:19:23
> handler_name : GPAC ISO Audio Handler
> Stream mapping:
> Stream #0:0 -> #0:0 (copy)
> Stream #0:1 -> #0:1 (copy)
> Press [q] to stop, [?] for help
> Automatically inserted bitstream filter 'h264_mp4toannexb'; args=''
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:00:00.52 bitrate=N/A
> speed=1.02x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:00:01.56 bitrate=N/A
> speed=1.03x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:00:03.08 bitrate=N/A
> speed=1.01x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:00:03.56 bitrate=N/A speed=
> 1x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:00:05.12 bitrate=N/A
> speed=1.01x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:10:06.12 bitrate=N/A speed=
> 1x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:20:09.70 bitrate=N/A speed=
> 1x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:30:14.80 bitrate=N/A speed=
> 1x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:40:19.88 bitrate=N/A speed=
> 1x
> [hls @ 0x7fedf4000600] EXT-X-MEDIA-SEQUENCE:50:20.90 bitrate=N/A speed=
> 1x
> frame= 529 fps= 25 q=-1.0 Lsize=N/A time=00:00:21.35 bitrate=N/A speed=
> 1x
> video:6506kB audio:324kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: unknown
> Input file #0 (/Users/liuqi/Movies/objectC/facebook.mp4):
> Input stream #0:0 (video): 529 packets read (6661710 bytes);
> Input stream #0:1 (audio): 1001 packets read (332091 bytes);
> Total: 1530 packets (6993801 bytes) demuxed
> Output file #0 (output_test.m3u8):
> Output stream #0:0 (video): 529 packets muxed (6661710 bytes);
> Output stream #0:1 (audio): 1001 packets muxed (332091 bytes);
> Total: 1530 packets (6993801 bytes) muxed
> localhost:ffmpeg liuqi$
>
More information about the ffmpeg-devel
mailing list