11/19/2025
Reduce video file size with FFmpeg using CRF, presets, H.264, H.265, and audio settings. Includes copyable commands, quality guidance, and common mistakes.
How to Compress Video with FFmpeg
The most reliable way to reduce a video file size with FFmpeg is to re-encode the video with a quality target instead of guessing a fixed bitrate. For most MP4 files, that means using H.264 (libx264) with a CRF value.
If you want a form-based command builder, use the FFmpeg video compressor. If you just need the command, start here.
Recommended Command
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart output.mp4
This command creates a broadly compatible MP4 file, keeps quality reasonable, and usually makes the file much smaller than the original.
Use it when:
- You want to upload a smaller video to a website or social platform.
- You need an MP4 that plays in browsers, phones, and common video players.
- You care more about visual quality than hitting an exact file size.
What the Options Mean
| Option | Meaning |
|---|---|
-i input.mp4 |
Sets the source video. |
-c:v libx264 |
Encodes the video as H.264, the safest default for compatibility. |
-crf 23 |
Sets the quality target. Lower values mean better quality and larger files. |
-preset medium |
Controls encoding speed versus compression efficiency. |
-c:a aac |
Encodes audio as AAC, which is widely supported in MP4. |
-b:a 128k |
Uses a practical audio bitrate for speech and general video. |
-movflags +faststart |
Moves MP4 metadata to the front so web playback can start sooner. |
Choosing the Right CRF Value
CRF is the setting you will adjust most often.
| CRF | Result | Best for |
|---|---|---|
18 |
Very high quality, larger file | Archiving, editing, premium output |
20-23 |
Good balance | Most web videos and uploads |
24-28 |
Smaller file, visible loss possible | Previews, messaging, storage savings |
Start with 23. If the file is still too large, try 25 or 28. If the quality drops too much, try 20.
Faster Compression
The preset changes how hard the encoder works. A slower preset can make a smaller file at the same CRF, but it takes longer.
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset veryfast -c:a aac -b:a 128k output.mp4
Useful presets:
veryfast: good when you want quick results.medium: balanced default.slow: better compression if you can wait.
Avoid ultrafast unless speed matters more than file size. It often produces larger files.
Smaller Files with H.265
H.265/HEVC can produce smaller files than H.264 at similar visual quality, but compatibility is not as universal.
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -c:a aac -b:a 128k output.mp4
Use H.265 when:
- Your audience uses modern devices.
- You are storing video for yourself.
- Smaller file size matters more than old-device compatibility.
For public websites and broad sharing, H.264 is still the safer default.
Compress to a Target Size
If you must hit a specific file size, use bitrate-based encoding. For example, this uses about 2 Mbps for video:
ffmpeg -i input.mp4 -c:v libx264 -b:v 2M -preset medium -c:a aac -b:a 128k output.mp4
CRF usually gives better quality for normal compression work. Target bitrate is useful when a platform has a strict upload limit.
Downscale While Compressing
Resolution has a huge effect on file size. If a 4K video does not need to stay 4K, downscale it:
ffmpeg -i input.mp4 -vf "scale=1920:-2" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k output.mp4
The -2 keeps the height proportional and makes sure the final dimension is valid for common encoders.
Common Mistakes
The output file is larger than the input.
The original may already be heavily compressed. Try a higher CRF, a slower preset, or downscale the resolution.
The video plays locally but not on a website.
Use H.264, AAC audio, .mp4, and -movflags +faststart.
The command says Unknown encoder 'libx264'.
Your FFmpeg build does not include x264. Install a full FFmpeg build or use an available encoder such as h264_videotoolbox on macOS. You can also check the FFmpeg error explainer.
Related FFmpeg Pages
- Build a custom command with the Compress Video tool.
- See the short recipe: Compress MP4 with FFmpeg.
- Learn how to change video resolution with FFmpeg.
Related tool
Compress Video with FFmpeg
Generate FFmpeg commands to reduce video file size with CRF, codec, preset, and resolution controls.
Open the command generator