Reduce 1.6GB Videos to 300MB on Ubuntu 24.04
Learn how to compress large video files from 1.6GB down to 300MB using FFmpeg on Ubuntu 24.04. Perfect for slow internet connections and cloud storage uploads like Google Drive.
sudo apt update && sudo apt upgrade -y
sudo apt install ffmpeg -y
ffmpeg -version
| Concept | Description | Impact |
|---|---|---|
| Bitrate | Amount of data processed per second | Lower = Smaller file, Lower quality |
| Codec | Compression algorithm (H.264, H.265) | H.265 = 30% smaller than H.264 |
| Resolution | Video dimensions (1920x1080, etc.) | Lower = Much smaller file |
| CRF | Constant Rate Factor (quality setting) | 18-28 is good range (lower=better) |
Two-pass encoding analyzes the video twice to achieve the exact target file size with optimal quality distribution.
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 your_video.mp4
For a 300MB target with 128kbps audio:
# Formula: (Target_MB × 8192 - Audio_kbps × Duration) / Duration
# Example for 600 second video:
# (300 × 8192 - 128 × 600) / 600 = ~3900 kbps
ffmpeg -y -i input.mp4 -c:v libx264 -b:v 3900k -pass 1 -an -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 3900k -pass 2 -c:a aac -b:a 128k output.mp4
Constant Rate Factor is faster and easier, focusing on quality rather than exact file size.
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset slow -c:a aac -b:a 128k output.mp4
-t 15 to encode only 15 seconds first and check quality before running the full video.
Create a reusable script that automatically calculates the perfect bitrate for 300MB output.
nano compress_to_300mb.sh
#!/bin/bash
INPUT="$1"
OUTPUT="${2:-compressed_$(basename "$INPUT")}"
TARGET_MB=300
AUDIO_BITRATE=128
if [ -z "$INPUT" ] || [ ! -f "$INPUT" ]; then
echo "Usage: $0 <input_video> [output_name.mp4]"
exit 1
fi
# Get duration in seconds
DURATION=$(ffprobe -v error -show_entries format=duration \
-of default=noprint_wrappers=1:nokey=1 "$INPUT")
# Calculate video bitrate
VIDEO_BITRATE=$(awk "BEGIN {printf \"%d\",
($TARGET_MB * 8192 - $AUDIO_BITRATE * $DURATION) / $DURATION}")
echo "📏 Duration: ${DURATION}s | 🎯 Bitrate: ${VIDEO_BITRATE}k"
# Two-pass encoding
ffmpeg -y -i "$INPUT" -c:v libx264 -b:v "${VIDEO_BITRATE}k" \
-pass 1 -an -f null /dev/null
ffmpeg -i "$INPUT" -c:v libx264 -b:v "${VIDEO_BITRATE}k" \
-pass 2 -c:a aac -b:a "${AUDIO_BITRATE}k" "$OUTPUT"
# Clean up
rm -f ffmpeg2pass-0.log ffmpeg2pass-0.log.mbtree
echo "✅ Done! Saved as: $OUTPUT"
chmod +x compress_to_300mb.sh
./compress_to_300mb.sh your_camera_video.mp4
Reduce from 4K to 1080p for massive size reduction:
ffmpeg -i input.mp4 -vf "scale=1920:1080" \
-c:v libx264 -crf 26 -c:a aac -b:a 128k output.mp4
30% smaller than H.264 at same quality:
ffmpeg -i input.mp4 -c:v libx265 -crf 28 \
-preset slow -tag:v hvc1 -c:a aac -b:a 128k output.mp4
Reduce from 60fps to 30fps:
ffmpeg -i input.mp4 -r 30 -c:v libx264 \
-crf 26 -c:a aac output.mp4
ls -lh output.mp4
du -h output.mp4
ffprobe -v error -show_entries format=size,duration \
-of csv=p=0 output.mp4
ffprobe -i output.mp4
1. Which method produces the best quality at an exact file size?
2. What CRF value would you use for good quality at ~300MB?
3. Which codec produces smaller files?
| Problem | Solution |
|---|---|
| FFmpeg not found | sudo apt install ffmpeg |
| Output file too large | Increase CRF value or decrease bitrate |
| Quality too poor | Decrease CRF (18-23) or increase bitrate |
| Encoding very slow | Use -preset faster instead of slow |
| No audio in output | Add -c:a aac -b:a 128k to command |
You've completed the Video Compression Masterclass