M3U8在FFmpeg中的Muxer
查看HLS文件的Muxer信息
ffmpeg -h muxer=hls
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration:
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
Muxer hls [Apple HTTP Live Streaming]:
Common extensions: m3u8.
Default video codec: h264.
Default audio codec: aac.
Default subtitle codec: webvtt.
hls muxer AVOptions:
-start_number <int64> E........ set first number in the sequence (from 0 to I64_MAX) (default 0)
-hls_time <float> E........ set segment length in seconds (from 0 to FLT_MAX) (default 2)
-hls_init_time <float> E........ set segment length in seconds at init list (from 0 to FLT_MAX) (default 0)
-hls_list_size <int> E........ set maximum number of playlist entries (from 0 to INT_MAX) (default 5)
-hls_delete_threshold <int> E........ set number of unreferenced segments to keep before deleting (from 1 to INT_MAX) (default 1)
-hls_ts_options <string> E........ set hls mpegts list of options for the container format used for hls
-hls_vtt_options <string> E........ set hls vtt list of options for the container format used for hls
-hls_wrap <int> E........ set number after which the index wraps (will be deprecated) (from 0 to INT_MAX) (default 0)
-hls_allow_cache <int> E........ explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments (from INT_MIN to INT_MAX) (default -1)
-hls_base_url <string> E........ url to prepend to each playlist entry
-hls_segment_filename <string> E........ filename template for segment files
-hls_segment_size <int> E........ maximum size per segment file, (in bytes) (from 0 to INT_MAX) (default 0)
-hls_key_info_file <string> E........ file with key URI and key file path
-hls_enc <boolean> E........ enable AES128 encryption support (default false)
-hls_enc_key <string> E........ hex-coded 16 byte key to encrypt the segments
-hls_enc_key_url <string> E........ url to access the key to decrypt the segments
-hls_enc_iv <string> E........ hex-coded 16 byte initialization vector
-hls_subtitle_path <string> E........ set path of hls subtitles
-hls_segment_type <int> E........ set hls segment files type (from 0 to 1) (default mpegts)
mpegts E........ make segment file to mpegts files in m3u8
fmp4 E........ make segment file to fragment mp4 files in m3u8
-hls_fmp4_init_filename <string> E........ set fragment mp4 file init filename (default "init.mp4")
-hls_flags <flags> E........ set flags affecting HLS playlist and media file generation (default 0)
single_file E........ generate a single media file indexed with byte ranges
temp_file E........ write segment to temporary file and rename when complete
delete_segments E........ delete segment files that are no longer part of the playlist
round_durations E........ round durations in m3u8 to whole numbers
discont_start E........ start the playlist with a discontinuity tag
omit_endlist E........ Do not append an endlist when ending stream
split_by_time E........ split the hls segment by time which user set by hls_time
append_list E........ append the new segments into old hls segment list
program_date_time E........ add EXT-X-PROGRAM-DATE-TIME
second_level_segment_index E........ include segment index in segment filenames when use_localtime
second_level_segment_duration E........ include segment duration in segment filenames when use_localtime
second_level_segment_size E........ include segment size in segment filenames when use_localtime
periodic_rekey E........ reload keyinfo file periodically for re-keying
independent_segments E........ add EXT-X-INDEPENDENT-SEGMENTS, whenever applicable
-use_localtime <boolean> E........ set filename expansion with strftime at segment creation(will be deprecated ) (default false)
-strftime <boolean> E........ set filename expansion with strftime at segment creation (default false)
-use_localtime_mkdir <boolean> E........ create last directory component in strftime-generated filename(will be deprecated) (default false)
-strftime_mkdir <boolean> E........ create last directory component in strftime-generated filename (default false)
-hls_playlist_type <int> E........ set the HLS playlist type (from 0 to 2) (default 0)
event E........ EVENT playlist
vod E........ VOD playlist
-method <string> E........ set the HTTP method(default: PUT)
-hls_start_number_source <int> E........ set source of first number in sequence (from 0 to 2) (default generic)
generic E........ start_number value (default)
epoch E........ seconds since epoch
datetime E........ current datetime as YYYYMMDDhhmmss
-http_user_agent <string> E........ override User-Agent field in HTTP header
-var_stream_map <string> E........ Variant stream map string
-cc_stream_map <string> E........ Closed captions stream map string
-master_pl_name <string> E........ Create HLS master playlist with this name
-master_pl_publish_rate <int> E........ Publish master play list every after this many segment intervals (from 0 to UINT32_MAX) (default 0)
-http_persistent <boolean> E........ Use persistent HTTP connections (default false)
-timeout <duration> E........ set timeout for socket I/O operations (default -0.000001)
转HLS
ffmpeg -re -i 111.mp4 -c copy -f hls -bsf:v h264_mp4toannexb 444.m3u8
"-bsf:v h264_mp4toannexb"参数的作用是将MP4中的H.264数据转换为常见于实时传输流的H.264 AnnexB标准的编码。
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration:
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '111.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: mp41avc1qt
creation_time : 2017-02-04T01:33:49.000000Z
playback_requirements: QuickTime 6.0 or greater
playback_requirements-eng: QuickTime 6.0 or greater
encoder : vlc 2.1.5 stream output
encoder-eng : vlc 2.1.5 stream output
Duration: 00:01:21.89, start: 0.000000, bitrate: 2037 kb/s
Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 23 kb/s (default)
Metadata:
creation_time : 2017-02-04T01:33:49.000000Z
handler_name : SoundHandler
Stream #0:1(eng): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, 2009 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
Metadata:
creation_time : 2017-02-04T01:33:49.000000Z
handler_name : VideoHandler
[hls @ 0x7fb872005000] Opening '4440.ts' for writing
Output #0, hls, to '444.m3u8':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: mp41avc1qt
encoder : Lavf58.20.100
playback_requirements: QuickTime 6.0 or greater
playback_requirements-eng: QuickTime 6.0 or greater
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, q=2-31, 2009 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc (default)
Metadata:
creation_time : 2017-02-04T01:33:49.000000Z
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 23 kb/s (default)
Metadata:
creation_time : 2017-02-04T01:33:49.000000Z
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[hls @ 0x7fb872005000] Opening '4441.ts' for writing bitrate=N/A speed=1.03x
[hls @ 0x7fb872005000] Cannot use rename on non file protocol, this may lead to races and temporary partial files
[hls @ 0x7fb872005000] Opening '4442.ts' for writing bitrate=N/A speed=1.02x
[hls @ 0x7fb872005000] Opening '4443.ts' for writing bitrate=N/A speed=1.01x
[hls @ 0x7fb872005000] Opening '4444.ts' for writing bitrate=N/A speed=1.01x
[hls @ 0x7fb872005000] Opening '4445.ts' for writing bitrate=N/A speed=1.01x
[hls @ 0x7fb872005000] Opening '4446.ts' for writing bitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '4447.ts' for writing bitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '4448.ts' for writing bitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '4449.ts' for writing bitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44410.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44411.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44412.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44413.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44414.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44415.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44416.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44417.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44418.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44419.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44420.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44421.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44422.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44423.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44424.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44425.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44426.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44427.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44428.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44429.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44430.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44431.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44432.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44433.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44434.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44435.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44436.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44437.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44438.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44439.ts' for writingbitrate=N/A speed= 1x
[hls @ 0x7fb872005000] Opening '44440.ts' for writingbitrate=N/A speed= 1x
frame= 2048 fps= 25 q=-1.0 Lsize=N/A time=00:01:21.92 bitrate=N/A speed= 1x
video:20085kB audio:231kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
start_number参数
ffmpeg -re -i 111.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -start_number 300 444.m3u8
如图,切片的第一片的编号是300已生效。
hls_time参数
ffmpeg -re -i 111.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -hls_time 10 444.m3u8
如图,此参数的作用是设置转码切片的duration为10秒左右一片(从关键帧处开始切片)。
hls_list_size参数
ffmpeg -re -i 111.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -hls_list_size 3 444.m3u8
如图,在M3U8文件中最多只有3个TS分片。
hls_wrap参数
ffmpeg -re -i 111.mp4 -c copy -f hls -bsf:v h264_mp4toannexb -hls_wrap 3 444.m3u8
如图,参数的作用是设置刷新回滚参数,当TS分片序号等于3时回滚。
hls_base_url参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_base_url http://172.18.31.34/live/ -bsf:v h264_mp4toannexb 444.m3u8
如图,参数设置了每个TS文件的前置基本路径。
hls_segment_filename参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_segment_filename test_output-%d.ts -bsf:v h264_mp4toannexb 444.m3u8
如图,此参数的作用是设置HLS的TS分片前缀名。
hls_flags参数
- delete_segments子参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_flags delete_segments -hls_list_size 4 -bsf:v h264_mp4toannexb 444.m3u8
如图,参数作用是只保留设置的切片个数,删除其他早期的切片。
- round_durations子参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_flags round_durations -bsf:v h264_mp4toannexb 444.m3u8
如图,round_durations参数可以实现切片信息的duration时长为整形。
- discont_start子参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_flags discont_start -bsf:v h264_mp4toannexb 444.m3u8
如图,该参数在生成M3U8的时候在切片信息的前面插入discontinuity标签,常用于在切片不连续时作特别声明。
- omit_endlist子参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_flags omit_endlist -bsf:v h264_mp4toannexb 444.m3u8
如图,该参数在生成M3U8结束的时候不写入endlist标签。
上图为不使用omit_endlist参数生成的M3U8文件。
- split_by_time子参数
ffmpeg -re -i 111.mp4 -c copy -f hls -hls_time 2 -hls_flags split_by_time -bsf:v h264_mp4toannexb 444.m3u8
该参数的作用为当生成的切片在没有遇到关键帧时依然可以与hls_time设置的切片时长相差不多,所以此参数必须要与hls_time配合使用。
use_localtime参数
ffmpeg -re -i 111.mp4 -c copy -f hls -use_localtime 1 -bsf:v h264_mp4toannexb 444.m3u8
如图,使用use_localtime参数可以以本地系统时间为切片文件名。
网友评论