簡介:
之前用到過FFmpeg截取過音頻和視頻發現,截取的視頻文件時間不是很准確,今天便系統的學習了一下FFmpeg截取視頻的知識 參考:
https://zhuanlan.zhihu.com/p/27366331 感謝!
http://blog.csdn.net/matrix_laboratory/article/details/53157383
1.首先明確為什么FFmpeg截取的視頻時間點不精確?
造成這些問題的原因是ffmpeg無法seek到非關鍵幀上。
2.剪切方法:(非重新編碼)
1 ffmpeg -ss [start] -t [duration] -accurate_seek -i [in].mp4 -codec copy [out].mp4
參數分析:
--[start]起始時間
--[duration]需要截取的時長
--[in]輸入文件名
--[out]輸出文件名
親測:時間並不精確(我是在Linux下使用ffmpeg),另外這種方式會導致:如果視頻結尾不是關鍵幀,那么視頻最后就會出現一段空白。
解決方法是: 加入[-avoid_negative_ts 1]
ffmpeg -ss [start] -t [duration] -accurate_seek -i [in].mp4 -codec copy -avoid_negative_ts 1 [out].mp4
3.重新編碼進行剪切
1 ffmpeg -ss [start] -t [duration] -i [in].mp4 -c:v libx264 -c:a aac -strict experimental -b:a 98k [out].mp4
相對來說比較精確,可是還是不是特別精確,,什么原因呢?望有人解答