How to Compress Large Videos Without Losing Much Quality Using FFmpeg
Recording tutorials, gameplay, or OBS sessions often results in videos that are several gigabytes in size. Uploading or storing these files quickly becomes expensive, especially when working with limited disk space or slower internet connections. Fortunately, FFmpeg makes it possible to reduce video size significantly while maintaining excellent visual quality.
In this guide, you'll learn how to compress MP4, MKV, and other video formats using FFmpeg, understand the most important encoding options, and avoid common mistakes that lead to poor quality or corrupted files.
What is FFmpeg?
FFmpeg is a free and open source multimedia framework that allows you to record, convert, compress, stream, and edit audio and video directly from the command line. It is available for Windows, Linux, and macOS and is trusted by developers, video editors, and streaming platforms.
Why Compress Videos?
Compressing videos has several advantages:
- Save storage space
- Upload videos faster
- Reduce bandwidth usage
- Share files more easily
- Archive recordings efficiently
Installing FFmpeg
Ubuntu:
sudo apt update
sudo apt install ffmpeg
Verify the installation:
ffmpeg -version
Basic Compression Command
The following command provides a great balance between quality and file size:
ffmpeg -i input.mp4 \
-c:v libx264 \
-crf 23 \
-preset medium \
-c:a aac \
-b:a 128k \
output.mp4
Understanding Each Option
| Option | Description |
|---|---|
| libx264 | Uses the H.264 video encoder. |
| CRF | Controls video quality. Lower values produce higher quality and larger files. |
| Preset | Determines encoding speed versus compression efficiency. |
| AAC | Compresses audio while maintaining good quality. |
Choosing the Right CRF Value
| CRF | Quality | File Size |
|---|---|---|
| 18 | Excellent | Large |
| 23 | Recommended | Balanced |
| 28 | Acceptable | Small |
| 35+ | Poor | Very Small |
Compress Every Video Inside a Folder
If you have many recordings, use a simple Bash loop:
mkdir compressed
for file in *.mkv; do
ffmpeg -i "$file" \
-c:v libx264 \
-crf 23 \
-preset medium \
-c:a aac \
-b:a 128k \
"compressed/${file%.mkv}.mp4"
done
This script converts every MKV file in the current directory into a compressed MP4 version inside the
compressed folder.
Speed vs Compression
| Preset | Encoding Speed | Compression |
|---|---|---|
| ultrafast | Very Fast | Poor |
| fast | Fast | Good |
| medium | Balanced | Very Good |
| slow | Slow | Excellent |
| veryslow | Very Slow | Best |
Common Mistakes
- Using a CRF value that is too high, resulting in blurry videos.
- Choosing the ultrafast preset for permanent archives.
- Overwriting the original recording before checking the compressed version.
- Compressing an already compressed video multiple times.
- Ignoring audio bitrate, which can noticeably reduce sound quality.
Recommended Settings
| Purpose | CRF | Preset |
|---|---|---|
| YouTube Upload | 23 | medium |
| OBS Recordings | 22 | slow |
| Long-term Archive | 18 | slow |
| Quick Sharing | 28 | fast |
Final Thoughts
FFmpeg is one of the most powerful tools available for video compression. By combining the H.264 encoder with a sensible CRF value and an appropriate preset, you can reduce file sizes dramatically while preserving excellent visual quality. Whether you're compressing tutorial videos, OBS recordings, or personal archives, these settings provide a reliable starting point for most workflows.
Written by A.M. Rinas