A smart Bash script that compresses videos to ≤8MB by default using ffmpeg, designed for Termux and lightweight environments.
💬 Discord Note: Discord currently allows 10MB uploads for free users. This script defaults to 8MB to ensure guaranteed compatibility. You can change the target to 10MB if desired (see “Customization” below).
Perfect for:
- Discord uploads (10MB free limit — 8MB used by default for safety)
- Quick file sharing
- Mobile encoding via Termux
- Low-resource Linux systems
- 🎯 Guaranteed ≤8MB output by default
- 🔁 2-pass encoding for accurate size targeting
- 📊 Real-time progress bar
- 🧠 Automatic bitrate calculation
- 🔊 Smart audio/video bitrate allocation
- 📐 Auto resolution detection
- 📉 Auto downscale to 720p if width > 1280px
- ⚡ Uses all available CPU cores
- 📱 Optimized for Termux & minimal systems
- 🧹 Automatic temporary file cleanup
You need:
bashffmpegffprobecoreutils(fornproc, usually preinstalled)
Install in Termux:
pkg update
pkg install ffmpegchmod +x compress8mb.sh
./compress8mb.sh input.mp4 output.mp4Example:
./compress8mb.sh video.mp4 compressed.mp4-
Reads video duration using
ffprobe -
Converts target size (8MB default) into total available kilobits
-
Reserves 64 kbps for audio
-
Assigns remaining bitrate to video
-
Downscales to 720p if width > 1280px
-
Performs 2-pass encoding:
- Pass 1: analysis
- Pass 2: final encode with progress tracking
-
If file exceeds target:
- Reduces video bitrate by 5%
- Re-encodes automatically
-
Cleans up temporary files
Target size (MB) × 8192 = total kilobits
Total kilobits ÷ duration (seconds) = total bitrate (kbps)
Video bitrate = total bitrate − audio bitrate══════════════════════════════════════
Duration: 120s
Target: 8MB
Video Bitrate: 482k
Audio Bitrate: 64k
Threads: 24
Scaling: 720p
Codec: libx264 (2-pass)
══════════════════════════════════════
Progress: [########################## ] 54% (65s/120s)
Done: compressed.mp4 (~8MB)
- Output size will never exceed target (default 8MB)
- Very long videos will have lower quality (bitrate constrained)
- Very short videos may look very high quality
- Uses all logical CPU cores detected via
nproc - Designed for reliability over raw speed
Change target size:
# Default (safe for Discord)
TARGET_MB=8
# Use full Discord free limit
TARGET_MB=10Change audio bitrate:
AUDIO_BITRATE=64Change preset:
-preset fast2-pass encoding:
- Improves bitrate distribution
- Ensures accurate file size
- Produces better quality at low bitrates
- Guarantees ≤TARGET_MB output
This version prioritizes accuracy and reliability while remaining lightweight.
MIT License — free to use and modify.