ffmpeg將mp4分解爲ts

切片生成m3u8列表命令:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict -2 -f hls output.m3u8

此轉換命令默認的每片(即一個ts文件)時長是2s,m3u8列表文件中默認只保存最後的5條片信息,也就是播放器在拉流時只能播最後的那5條ts視頻文件。

這肯定不是你想要的,那麼幸運的是ffmpeg提供了更改這些相關設置的參數,如下:

相關設置參數:

‘hls_time seconds’

Set the segment length in seconds. Default value is 2.(設置每片的長度,默認值爲2。單位爲秒)

‘hls_list_size size’

Set the maximum number of playlist entries. If set to 0 the list file will contain all the segments. Default value is 5.(設置播放列表保存的最多條目,設置爲0會保存有所片信息,默認值爲5)

‘hls_wrap wrap’

Set the number after which the segment filename number (the number specified in each segment file) wraps. If set to 0 the number will be never wrapped. Default value is 0.

This option is useful to avoid to fill the disk with many segment files, and limits the maximum number of segment files written to disk towrap.(設置多少片之後開始覆蓋,如果設置爲0則不會覆蓋,默認值爲0.這個選項能夠避免在磁盤上存儲過多的片,而且能夠限制寫入磁盤的最多的片的數量)

‘start_number number’

Start the playlist sequence number from number. Default value is 0.(設置播放列表中sequence number的值爲number,默認值爲0)

Note that the playlist sequence number must be unique for each segment and it is not to be confused with the segment filename sequence number which can be cyclic, for example if the ‘wrap’ option is specified.(提示:播放列表的sequence number 對每個segment來說都必須是唯一的,而且它不能和片的文件名混淆,因爲在,如果指定了“wrap”選項文件名會出現重複使用。)

使用示例:

ffmpeg -i 1.mp4 -c:v libx264 -c:a copy -f hls -threads 8 -hls_time 5 -hls_list_size 12 index.m3u8
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章