FFmpeg生成DASH流
1、DASH参数说明
ffmpeg -h muxer=dash
Muxer dash [DASH Muxer]:
Common extensions: mpd.
Default video codec: h264.
Default audio codec: aac.
dash muxer AVOptions:
-adaptation_sets <string> E........ Adaptation sets. Syntax: id=0,streams=0,1,2 id=1,streams=3,4 and so on
-window_size <int> E........ number of segments kept in the manifest (from 0 to INT_MAX) (default 0)
-extra_window_size <int> E........ number of segments kept outside of the manifest before removing from disk (from 0 to INT_MAX) (default 5)
-min_seg_duration <int> E........ minimum segment duration (in microseconds) (will be deprecated) (from 0 to INT_MAX) (default 5e+06)
-seg_duration <duration> E........ segment duration (in seconds, fractional value can be set) (default 5)
-remove_at_exit <boolean> E........ remove all segments when finished (default false)
-use_template <boolean> E........ Use SegmentTemplate instead of SegmentList (default true)
-use_timeline <boolean> E........ Use SegmentTimeline in SegmentTemplate (default true)
-single_file <boolean> E........ Store all segments in one file, accessed using byte ranges (default false)
-single_file_name <string> E........ DASH-templated name to be used for baseURL. Implies storing all segments in one file, accessed using byte ranges
-init_seg_name <string> E........ DASH-templated name to used for the initialization segment (default "init-stream$RepresentationID$.m4s")
-media_seg_name <string> E........ DASH-templated name to used for the media segments (default "chunk-stream$RepresentationID$-$Number%05d$.m4s")
-utc_timing_url <string> E........ URL of the page that will return the UTC timestamp in ISO format
-method <string> E........ set the HTTP method
-http_user_agent <string> E........ override User-Agent field in HTTP header
-http_persistent <boolean> E........ Use persistent HTTP connections (default false)
-hls_playlist <boolean> E........ Generate HLS playlist files(master.m3u8, media_%d.m3u8) (default false)
-streaming <boolean> E........ Enable/Disable streaming mode of output. Each frame will be moof fragment (default false)
-timeout <duration> E........ set timeout for socket I/O operations (default -0.000001)
-index_correction <boolean> E........ Enable/Disable segment index correction logic (default false)
-format_options <string> E........ set list of options for the container format (mp4/webm) used for dash
-dash_segment_type <int> E........ set dash segment files type (from 0 to 1) (default mp4)
mp4 E........ make segment file in ISOBMFF format
webm E........ make segment file in WebM format
2、window_size与extra_window_size参数说明
与HDS设置类似,DASH参数设置同样支持window_size与extra_window_size,设置列表中的切片个数与列表外切片的保留个数,设置如下:
ffmpeg -re -i 111.mp4 -c:v copy -acodec copy -f dash -window_size 4 -extra_window_size 3 index.mpd
执行完毕后会生成文件索引列表index.mpd,文件列表长度为4个切片长度,切片之外保留3个切片,在DASH直播格式中,音视频是分开切片的,即视频分为一路切片,音频分为一路切片,各有7个。另外还有2个初始化信息切片,1个索引切片。
3、single_file参数说明
FFmpeg支持生成DASH时将切片列表中的文件写入到一个文件中,使用single_file参数即可,命令如下:
ffmpeg -re -i 111.mp4 -c:v copy -acodec copy -f dash -window_size 4 -extra_window_size 3 -single_file 1 index.mpd
命令执行完成后,目录中会生成3个文件:1个索引文件、1个音频文件、1个视频文件。