FFmpeg Cheatsheet

2020-03-21
 

Basic #

Get help from command line #

ffmpeg -h
bash
Some useful help here
Global options (affect whole program instead of just one file:
-loglevel loglevel  set logging level
-v loglevel         set logging level
-y                  overwrite output files
-n                  never overwrite output files

Video options:
-r rate             set frame rate (Hz value, fraction or abbreviation)
-s size             set frame size (WxH or abbreviation)
-aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-vn                 disable video
-vcodec codec       force video codec ('copy' to copy stream)
-vf filter_graph    set video filters
-ab bitrate         audio bitrate (please use -b:a)
-b bitrate          video bitrate (please use -b:v)

Audio options:
-aq quality         set audio quality (codec-specific)
-ar rate            set audio sampling rate (in Hz)
-ac channels        set number of audio channels
-an                 disable audio
-acodec codec       force audio codec ('copy' to copy stream)
-vol volume         change audio volume (256=normal)
-af filter_graph    set audio filters
text

Examples #

去除和取出声音 #

ffmpeg -i example.mkv -c copy -an nosound.mkv
ffmpeg -i input.avi -vn -acodec copy output.aac
shell

裁剪 #

ffmpeg -i input.m4a -ss 0 -t 18 cut.m4a
shell

拼接 #

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
shell

list.txt 内容为:

file 1.mp4
file 2.mp4
text

生成静音的音频 #

ffmpeg -f lavfi -i anullsrc -t 5 -c:a libvorbis output.ogg
shell

把视频和音频合起来 #

ffmpeg -i all.mp4 -i all.m4a -c:v copy -c:a aac -strict experimental output.mp4
shell

合理转成 GIF #

The standard way to use ffmpeg for GIFs is

Generate a palette from the video

ffmpeg -y -i file.mp4 -vf palettegen palette.png
bash

Then,

ffmpeg -y -i file.mp4 -i palette.png -filter_complex paletteuse -r 10 -s 320x480 file.gif
bash

More options documented here.

所以使用我的 ffmpegroup脚本,第二步就是

ffmpegroup mp4/gif -z"-i palette.png -filter_complex paletteuse -r 10 -s 200x200 -y"
bash

直接倍速 #

ffmpeg -i input.mkv -filter:v "setpts=PTS/60" output.mkv
bash

或者更快的,但是会有音频问题,而且转出来帧率吓死人,并没有多少压缩作用,请慎用:

ffmpeg -itsscale 0.01666 -i input.mkv -c copy output.mkv
bash
Leave your comments and reactions on GitHub