billypom

ffmpeg cheat sheet

2026-04-04

I'm not an expert in video encoding. Just wanted to create an accessible reference resource for some typical tasks I do using ffmpeg.


Simple usage

ffmpeg -i input.mp4 output.webm

FFMPEG will figure out what to do - but this is not ideal, as the default behavior is subject to change over time. If you want reproduceability, specify codecs and bitrates.

CRF (Constant Rate Factor)

  • Available on x264, x265, libvpx
  • Higher value = more compression
  • Can set values between 0-51
  • Default =23
  • 18-28 is the sweet spot Good writeup about CRF by Werner Robitza H264 CRF guide from ffmpeg docs

Compression

CPU Encoding

~25% of original filesize | 2.8GB file turned into 736MB

# mp4
ffmpeg -i input.mp4 -vcodec libx264 -acodec copy -crf 20 output.mp4

# webm
ffmpeg -i input.webm -c:v libvpx-vp9 -b:v 1M -c:a libvorbis output.webm

GPU Encoding

~35% of original filesize | 1.5GB file turned into 526MB

# mp4
ffmpeg -i input.mp4 -c:v hevc_nvenc -preset fast -crf 24 output.mp4

Was incredibly fast compared to CPU encoding, but the quality suffered. Output file had some weird artifacts and banding... My test was done on an NVIDIA GTX 1060 Mobile, so ymmv.

Compressing video with odd-numbered aspect ratio

Include this flag:

-vf "crop=trunc(iw/2)*2:trunc(ih/2)*2"

Transcode MP4 to WEBM

ffmpeg -i input.mp4 -speed 2 -c:v libvpx-vp9 -crf 36 -b:v 750k -b:a 128k -c:a libopus output.webm

Cut / Crop

ffmpeg -i input.mp4 -ss 00:01:00.000 -to 00:02:00.000 -c copy output.mp4
#linux
#ffmpeg
#video