切片產生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