FFmpeg recipe
FFmpeg: Compress an MP4 with H.264 + CRF
CRF compression keeps quality consistent across the clip. Lower CRF = better quality + larger file. CRF 23 is the visually-lossless default.
Command
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -c:a copy -y output.mp4Prefer no terminal?
Use the Video Compressor in your browser
What each flag does
| -i | Input file. Can be a video, audio, or image. Repeat for multiple inputs. |
|---|---|
| -c:v | Video codec for output. e.g. libx264, libx265, libvpx-vp9. |
| -crf | Constant Rate Factor — quality target (lower = better, larger file). 23 is visually lossless for libx264. |
| -c:a | Audio codec for output. e.g. aac, libmp3lame, copy. |
| -preset slow | Slower preset → smaller file at the same CRF. Use ultrafast for live, slow for archival. |
Notes & gotchas
- Common CRF values: 18 (near-lossless), 23 (default), 28 (web/email), 32 (chat apps).
- Stream-copy the audio (-c:a copy) when you only need video compression.
Check it worked
ffprobe -v error -show_entries format=size,duration -of csv=p=0 output.mp4A smaller size than the source at the same duration. Identical duration confirms nothing was truncated.
What to change
| CRF is the only size control you want | Pick a quality and let the size follow. 23 is the default, 26-28 for a chat app, 18-20 to keep it close to the source. |
|---|---|
| -preset costs time, not quality | slow at CRF 23 is smaller than veryfast at CRF 23 and looks the same. Use it when you can wait. |
| Resolution beats CRF | Adding -vf scale=-2:720 saves more than any CRF change and usually looks better than a heavily compressed 1080p. |
If it fails
The file barely shrank.
Why: The source was already efficiently encoded, so re-encoding at a similar quality has little left to remove.
Fix: Raise the CRF number, which lowers quality and size, or reduce the resolution, which usually saves more than any CRF change.
The output looks noticeably softer or blocky.
Why: The CRF value is too high for this content. Grain, confetti and fast motion need more bitrate than a static talking head.
Fix: Lower the CRF by two or three and compare a still frame from each. Around 23 is the usual visually-lossless point.