ffmpeg常用檔案轉換命令集錦
儲存我常用的ffmpeg命令.
都是從各處收集來的.除了常規操作,還有一些特殊的優化.
教程
Gif轉mp4
ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4
解釋:
movflags – This option optimizes the structure of the MP4 file so the browser can load it as quickly as possible.
pix_fmt – MP4 videos store pixels in different formats. We include this option to specify a specific format which has maximum compatibility across all browsers.
vf – MP4 videos using H.264 need to have a dimensions that are divisible by 2. This option ensures that’s the case.
flv轉mp4
# 重新編碼式 ffmpeg -i input.flv -c:v libx264 -crf 19 -strict experimental output.mp4 # 直接輸出式 ffmpeg -i input.flv -codec copy output.mp4
解釋:
You must specify the video codec used. In your command you don't specify -vcodec or -c:v so ffmpeg uses the default codec for MP4 (mpeg4) which doesn't have very good compression efficiency. Try using libx264 instead and setting the CRF, which is the quality level (lower is better, default is 23, and sane values are between 18 and 28).
Encoding with libx264 is kind of complex, so you should look up the H.264 encoding guide.
You also need to specify -strict experimental otherwise you might get : " The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it