11/19/2025
Drastically reduce your video file size without losing visible quality. Learn to use FFmpeg's CRF setting to achieve the perfect balance of size and quality.
How to Compress or Reduce Video File Size with FFmpeg? (The Perfect Balance)
Have you ever faced this problem: you've recorded a high-quality video, but the file size is enormous, making it impossible to send via email or messaging apps? Or maybe you want to embed a video on your website but worry that the huge file will slow down page load times. The truth is, you can significantly reduce video size without a major sacrifice in quality. FFmpeg offers a nearly perfect solution that allows you to precisely control the compression level, striking the best balance between quality and size.
🚀 Quick Access: The FFmpeg Command
Want to significantly compress a video named input.mp4 while maintaining great visual quality? Copy and run the following command:
ffmpeg -i input.mp4 -vcodec libx264 -crf 23 output.mp4
This command uses the H.264 encoder to intelligently compress the video using a parameter called CRF (Constant Rate Factor).
🧠The Breakdown: Understanding Each Parameter
Let's dive deep into each component of this command.
| Parameter | Explanation |
|---|---|
ffmpeg |
Calls the FFmpeg program. |
-i input.mp4 |
Specifies your input file—the original, oversized video. |
-vcodec libx264 |
-vcodec is used to specify the video encoder. libx264 is the most widely used and compatible H.264 video encoder available today. |
-crf 23 |
This is the core of the compression! CRF (Constant Rate Factor) is the parameter that controls the video quality. A lower value means higher quality and a larger file; a higher value means lower quality and a smaller file. |
output.mp4 |
The filename for the new, compressed output video. |
A Practical Guide to CRF Values:
18is considered to be visually lossless or nearly so, but the compression effect is minimal.23is the default value forlibx264and provides an excellent balance between quality and file size.28is a more aggressive value that will result in a much smaller file, but the quality loss might be noticeable.- You can start with
23and adjust the value up or down based on your results.
FAQ & Variations
1. The compression process is too slow. Is there a way to speed it up?
Absolutely! FFmpeg offers a -preset parameter that dictates how much effort the encoder puts into compression. Faster presets result in lower compression efficiency (i.e., a slightly larger file for the same CRF), while slower presets are more efficient.
# Use the "veryfast" preset to significantly speed up the process
ffmpeg -i input.mp4 -vcodec libx264 -preset veryfast -crf 23 output.mp4
Available preset values include: ultrafast, superfast, veryfast, faster, fast, medium (the default), slow, slower, veryslow. For most day-to-day tasks, veryfast is an excellent choice for speed and efficiency.
2. How can I use the newer, more efficient H.265 (HEVC) encoder for compression?
If your playback devices support it, using libx265 (the H.265/HEVC encoder) can achieve similar visual quality to H.264 at an even smaller file size. The command is very similar; you just need to change the encoder and the corresponding CRF value.
# Compress using the H.265 encoder
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
Note: The CRF scale for libx265 is different from libx264. The default CRF for libx265 is 28, which is intended to provide a similar perceptual quality to libx264 at its default of 23.