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.
Related recipes
Compress (HEVC) · MP4
Compress an MP4 with FFmpeg using H.265 (HEVC). ~50% smaller at equivalent quality vs H.264.
Compress to target size · MP4
Compress an MP4 to a specific target file size with FFmpeg two-pass encoding. Useful for upload limits.
Trim · MP4
Trim an MP4 with FFmpeg using stream-copy for lossless, instant output. Copy-paste command with explanations.
Trim (frame-accurate) · MP4
Frame-accurate MP4 trim with FFmpeg. Re-encodes for exact-frame precision — use when -c copy keyframe snapping is not OK.