Large video files eat up storage and slow down uploads. FFmpeg makes it easy to compress videos from the command line. This guide covers the most practical techniques. For an in-depth look at compression strategies, also check out our video compression best practices.
Quick Compress with CRF
The simplest way to compress a video is using CRF (Constant Rate Factor). Lower values mean higher quality, higher values mean smaller files.
ffmpeg -i input.mp4 -crf 23 output.mp4| CRF Value | Quality | Use Case |
|---|---|---|
| 18 | Near lossless | Archiving |
| 23 | Good (default) | General use |
| 28 | Medium | Web sharing |
| 32+ | Low | Small file priority |
If you also need to change the container format (e.g., MKV to MP4), see our format conversion guide.
Choose the Right Codec
H.264 — Best Compatibility
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium output.mp4H.265 (HEVC) — 50% Smaller Files
H.265 produces significantly smaller files at the same quality, but encoding is slower.
ffmpeg -i input.mp4 -c:v libx265 -crf 28 output.mp4Use Presets to Control Speed vs Size
Presets balance encoding speed and compression efficiency.
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow output.mp4| Preset | Speed | File Size |
|---|---|---|
| ultrafast | Fastest | Largest |
| fast | Fast | Larger |
| medium | Balanced | Balanced |
| slow | Slow | Smaller |
| veryslow | Slowest | Smallest |
Scale Down Resolution
Reducing resolution is one of the most effective ways to shrink file size.
# Scale to 720p
ffmpeg -i input.mp4 -vf "scale=-2:720" -crf 23 output.mp4
# Scale to 480p
ffmpeg -i input.mp4 -vf "scale=-2:480" -crf 23 output.mp4The -2 keeps the aspect ratio and ensures the width is divisible by 2.
Limit Bitrate
For streaming or strict file size requirements, set a maximum bitrate:
ffmpeg -i input.mp4 -c:v libx264 -b:v 1M -maxrate 1M -bufsize 2M output.mp4Compress Audio Too
Don't forget the audio track. Reducing audio bitrate helps:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k output.mp4One-Command Recipe
Here's a balanced command that works well for most cases:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4This produces a good quality MP4 with significantly reduced file size, compatible with virtually all devices and platforms.
Try It Online
Don't want to install FFmpeg? Use FFHub to compress your videos directly in the browser — no command line needed.
Related Articles
- FFmpeg Video Compression Best Practices - Advanced strategies for optimal compression quality and file size
- How to Convert Video Format with FFmpeg - Convert between MP4, WebM, MKV, MOV with full codec control
- How to Trim and Merge Videos with FFmpeg - Cut clips and concatenate videos with simple commands

