FFMPEG Cheat Sheet
ffmpeg -version
ffmpeg version 5.0-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers built with gcc 11.2.0 (Rev5, Built by MSYS2 project)
Conversions
Get audio from a video file:
ffmpeg -i video.mp4 -vn -c:a copy song.mp3
ffmpeg -i video.mp4 -vn -c:a mp3 -b:a 128k -ar 44100 -ac 2 song.mp3
size=2456kB time=00:02:37.12 bitrate=128.0kbits/s speed=59.6x video:0kB audio:2456kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.013761%
ffmpeg -i song.m4a -af loudnorm -c:a mp3 -b:a 320k -ar 48000 song.mp3
size=12213kB time=00:05:12.60 bitrate=320.1kbits/s speed=16.8x video:0kB audio:12212kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.008781%
Strip audio from a video file:
ffmpeg -i video.mp4 -an -c:v copy video_only.mp4
ffmpeg -i video.mp4 -an video_only.h265
frame= 4707 fps=466 q=35.8 Lsize=659kB time=00:02:36.99 bitrate=34.4kbits/s speed=15.6x
video:659kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000% encoded 4707 frames in 10.08s (467.10 fps), 31.01 kb/s, Avg QP:34.70
ffmpeg -i https://my-domain.com/movie.mkv -t 00:02:30 -c:v h264 -b:v 2500k -c:a mp3 -b:a 128k -ar 44100 -ac 2 movie.mp4
video:398897kB audio:16473kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.321552% [libx264 @ 0000028f21bb09c0] kb/s:2477.36
Convert ALL streams included in your input file using the MAP flag:
ffmpeg -i video.mp4 -map 0 -c:a aac -c:v hevc output.mkv
h.264 (AVC)
Encoding Presets
- ultrafast
- superfast
- veryfast
- faster
- fast
- medium
- slow
- slower
- veryslow
- placebo
Tuning Presets
- psnr
- ssim
- grain
- zerolatency
- fastdecode
- animation
Costant Rate Factor
0
–51
(lossless - low quality), default23
, usable range17
–28
Profiles
- -profile:v baseline
- -profile:v high
- -profile:v high
leave out to let FFMPEG decide based on input (recommended)
ffmpeg -i video.mkv -c:v hevc -crf 23 -preset slower -tune zerolatency output.mp4
video:1422kB audio:2350kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 4.637553% x265 [info]: frame I: 19, Avg QP:10.82 kb/s: 5285.69 x265 [info]: frame P: 4689, Avg QP:15.41 kb/s: 52.07 x265 [info]: Weighted P-Frames: Y:1.9% UV:1.8% x265 [info]: consecutive B-frames: 100.0% encoded 4708 frames in 307.38s (15.32 fps), 73.19 kb/s, Avg QP:15.39 [aac @ 0000021ab0643d00] Qavg: 4054.659
Move flags to start (make file playable before fully downloaded):
ffmpeg -i video.mkv -c:v h264 -crf 23 -maxrate 1M -bufsize 2M -movflags +faststart output.mp4
[mp4 @ 000001f50ef56140] Starting second pass: moving the moov atom to the beginning of the file frame= 4708 fps=716 q=-1.0 Lsize= 3418kB time=00:02:37.12 bitrate= 178.2kbits/s dup=1 drop=0 speed=23.9x
h.265 (HEVC)
Encoding Presets
- ultrafast
- superfast
- veryfast
- faster
- fast
- medium
- slow
- slower
- veryslow
- placebo
Tuning Presets
- psnr
- ssim
- grain
- zerolatency
- fastdecode
Costant Rate Factor
0
–51
(lossless - low quality), default28
, usable range17
–28
Profiles
- -profile:v baseline
- -profile:v high
- -profile:v high
ffmpeg -i video.mp4 -c:v libx265 -crf 28 -c:a aac -b:a 128k output.mp4
Stream #0:0(und): Video: hevc (hev1 / 0x31766568), yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 29.97 fps, 30k tbn (default) Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
h.266 (VVC)
not available yet
VP8 & webM
ffmpeg -i video.mp4 -c:v libvpx -b:v 1M -c:a libvorbis output.webm
Stream #0:0(und): Video: vp8, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 1000 kb/s, 29.97 fps, 1k tbn (default) Stream #0:1(und): Audio: vorbis, 44100 Hz, stereo, fltp (default)
Costant Rate Factor
4
–63
(high - low quality), default 10
ffmpeg -i video.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webm
VP9 & webM
1-pass encoding with an average video bitrate of 1M:
ffmpeg -i video.mp4 -c:v libvpx-vp9 -b:v 1M -c:a libvorbis output.webm
Stream #0:0(und): Video: vp9, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 1000 kb/s, 29.97 fps, 1k tbn (default) Stream #0:1(und): Audio: vorbis, 44100 Hz, stereo, fltp (default)
2-pass encoding:
ffmpeg -i video.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f webm /dev/null&&ffmpeg -i video.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus output.webm
Constant Rate Factor
0
–63
(high - low quality), default31
, usable range15
–35
Constant Quality 1-pass encoding:
ffmpeg -i video.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 output.webm
Stream #0:0(und): Video: vp9, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 29.97 fps, 1k tbn (default) Stream #0:1(und): Audio: opus, 48000 Hz, stereo, flt, 96 kb/s (default)
Constrained Quality 1-pass encoding when b:v
> 0
.
ffmpeg -i video.mp4 -c:v libvpx-vp9 -crf 31 -b:v 2500k output.webm
Stream #0:0(und): Video: vp9, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 2500 kb/s, 29.97 fps, 1k tbn (default) Stream #0:1(und): Audio: opus, 48000 Hz, stereo, flt, 96 kb/s (default)