Compress Hundreds of Videos Without Fancy Software Using FFmpeg on Ubuntu
If you record tutorials, gameplay, lectures, or meetings, you've probably noticed how quickly video files consume storage. A few recordings can easily take tens or even hundreds of gigabytes.
The good news is that you don't need expensive video editing software to reduce file sizes. With FFmpeg and a simple Bash script, you can compress every video in a folder automatically while keeping excellent visual quality.
In this article, I'll show you how to install FFmpeg on Ubuntu, explain the compression settings, and share a script that processes every MKV video automatically.
Why Use FFmpeg?
FFmpeg is a free, open source command line tool used by developers, video editors, and streaming platforms worldwide. It supports almost every video and audio format while offering professional grade compression.
Benefits include:
- Completely free
- No watermark
- No file size limits
- Works offline
- Supports batch processing
- Available for Linux, Windows, and macOS
Install FFmpeg on Ubuntu
Update your package list:
sudo apt update
Install FFmpeg:
sudo apt install ffmpeg
Verify the installation:
ffmpeg -version
If you see version information, you're ready to start compressing videos.
Create the Compression Script
Create a new file:
nano compress.sh
Paste the following script:
#!/bin/bash
mkdir -p compressed
for file in *.mkv; do
echo "Compressing: $file"
ffmpeg -i "$file" \
-c:v libx265 \
-preset medium \
-crf 28 \
-c:a aac \
-b:a 128k \
"compressed/${file%.mkv}.mp4"
done
echo "Done"
Make the Script Executable
chmod +x compress.sh
Run the Script
./compress.sh
The script will automatically:
- Create a folder named
compressed - Find every MKV file in the current directory
- Compress each video
- Save the new MP4 files inside the compressed folder
Understanding the Compression Settings
| Option | Purpose |
|---|---|
| libx265 | Uses the H.265 encoder, producing smaller files than H.264. |
| preset medium | Balances encoding speed and compression. |
| crf 28 | Controls visual quality. Lower values mean better quality and larger files. |
| aac | Modern audio codec with good compatibility. |
| 128k | Audio bitrate suitable for most recordings. |
Expected Results
| Original Size | Compressed Size | Typical Reduction |
|---|---|---|
| 2 GB | 600 MB to 900 MB | 55% to 70% |
| 5 GB | 1.5 GB to 2 GB | 60% to 70% |
| 10 GB | 3 GB to 4 GB | 60% to 70% |
Actual results depend on the video's resolution, frame rate, and content. Videos with little movement generally compress much better than fast action scenes.
Can You Compress Without Any Quality Loss?
This is one of the biggest misconceptions about video compression.
If you're re-encoding a video using codecs like H.264 or H.265, there is always some quality loss. However, by choosing a sensible CRF value such as 22 to 28, the difference is often impossible to notice with the human eye while achieving significant file size reductions.
If you need truly lossless compression, your file size reduction will be minimal. For most users, visually lossless compression offers the best balance between quality and storage savings.
Tips
- Keep your original files until you verify the compressed versions.
- Use H.265 for maximum storage savings.
- Use CRF 22 to 24 for higher quality.
- Use CRF 28 for smaller files with excellent quality.
- Store compressed videos in a separate folder to avoid overwriting originals.
Final Thoughts
You don't need premium software to manage large video collections. FFmpeg is powerful, reliable, and completely free. Combined with a simple Bash script, it can automatically compress hundreds of videos with just one command, saving both storage space and upload time while maintaining excellent visual quality.
Written by A.M. Rinas