Compress video with CRF quality control

compression

// what it does

Re-encodes video with a Constant Rate Factor, which targets a perceptual quality level and lets the bitrate float scene by scene. -crf 23 is libx264's default (0=lossless, 51=worst; sane range 18-28); libx265 defaults to -crf 28, intended to look roughly comparable to x264's 23 while producing a smaller file. Audio is re-encoded to AAC with -c:a aac. Reach for this as the default compression recipe when you want a good-looking file and don't need an exact size.

// shell

$ ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac output.mp4
$ ffmpeg -i input.mp4 -c:v libx265 -crf 28 -c:a aac output.mp4

// gotcha

CRF numbers are not comparable across encoders — crf 23 on libx265 is higher quality (and larger) than crf 23 on libx264. Also pair CRF with -preset (default medium); slower presets shrink the file at the same CRF but cost encode time.