最近再作m3u8切片合併下載的小功能,由於要合併成mp4,因此考慮用ffmpeg來搞,mp4格式忒複雜了。this
查了下文檔ffmpeg支持concat demux和concat protocol.spa
用法以下:code
ffmpeg -i "concat:input1.mpg|input2.mpg|input3.mpg" -c copy output.mpg //這個是concat protocal,這個命令只支持一部分視頻格式 如mpeg1,2 mpegts,不支持flv,mp4
mylist.txt:
# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
ffmpeg -f concat -i mylist.txt -c copy output //這個是運用concat demux,和前面的命令有些不一樣,這個會把demux文件而後re-encode切片文件,因此只要ffmpeg支持的格式,這個命令都管用。
開始以爲這倆個命令功能是同樣的。實驗了第一個命令 flv無論用,只輸出了第一片的flv。查了下官方文檔找到這一段:
The flv container format doesn't support file-level concatenation; only a few container file types do. So the concat protocol won't work on them. The concat demuxer, as its name suggests, demuxes the input streams from their container and then concatenates them, so it doesn't care about what the input container is (and if the codecs are all the same w/ similar characteristics, you can actually concatenate files of different container formats).
參考:How to concatenate (join, merge) media files
ffmpeg wiki