https://github.com/visual1mpact/8mb-video-compressor
A simple Bash script that compresses videos to ~8MB using ffmpeg, designed for Termux and lightweight environments.
https://github.com/visual1mpact/8mb-video-compressor
8mb-limit aac android-cli bash bitrate-calculation cpu-multithreading discord-upload ffmpeg ffmpeg-script file-size-optimization h264 libx264 linux low-bitrate media-processing termux two-pass-encoding video-compression video-encoder video-optimization
Last synced: 6 days ago
JSON representation
A simple Bash script that compresses videos to ~8MB using ffmpeg, designed for Termux and lightweight environments.
- Host: GitHub
- URL: https://github.com/visual1mpact/8mb-video-compressor
- Owner: Visual1mpact
- License: mit
- Created: 2026-02-25T17:19:31.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-13T17:14:31.000Z (4 months ago)
- Last Synced: 2026-03-14T04:57:13.441Z (4 months ago)
- Topics: 8mb-limit, aac, android-cli, bash, bitrate-calculation, cpu-multithreading, discord-upload, ffmpeg, ffmpeg-script, file-size-optimization, h264, libx264, linux, low-bitrate, media-processing, termux, two-pass-encoding, video-compression, video-encoder, video-optimization
- Language: Shell
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฌ 8MB Video Compressor (Termux)
A smart Bash script that compresses videos to a **user-defined target size** using `ffmpeg`, designed for **Termux** and lightweight environments.
> ๐ฌ **Discord Note:** Discord currently allows **10MB uploads** for free users. The script defaults to **8MB** for safety but lets you choose another target size interactively at runtime.
Perfect for:
* Discord uploads (10MB free limit โ 8MB default)
* Quick file sharing
* Mobile encoding via Termux
* Low-resource Linux systems
---
## ๐ฆ Features
* ๐ฏ **User-selectable target output size (default 8MB)**
* ๐ 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
---
## ๐ Requirements
You need:
* `bash`
* `ffmpeg`
* `ffprobe`
* `coreutils` (for `nproc`, usually preinstalled)
Install in Termux:
```sh
pkg update
pkg install ffmpeg
````
---
## ๐ Usage
```sh
chmod +x compress8mb.sh
./compress8mb.sh input.mp4 output.mp4
```
When running, you will be prompted:
```text
Enter target size in MB (default 8 MB):
```
* Press **Enter** to keep 8MB
* Type `10` or any other number to change target size
Example:
```sh
./compress8mb.sh video.mp4 compressed.mp4
```
---
## โ๏ธ How It Works
1. Prompts for target size (default 8MB)
2. Reads video duration using `ffprobe`
3. Converts target size into total available kilobits
4. Reserves **64 kbps** for audio
5. Assigns remaining bitrate to video
6. Downscales to **720p** if width > 1280px
7. Performs **2-pass encoding**:
* Pass 1: analysis
* Pass 2: final encode with progress tracking
8. If file exceeds target:
* Reduces video bitrate by 5%
* Re-encodes automatically
9. Cleans up temporary files
---
## ๐งฎ Bitrate Formula
```bash
Target size (MB) ร 8192 = total kilobits
Total kilobits รท duration (seconds) = total bitrate (kbps)
Video bitrate = total bitrate โ audio bitrate
```
---
## ๐ Example Output
```text
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
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)
```
---
## โ ๏ธ Notes
* Output size will **never exceed target**
* 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
---
## ๐ง Customization
You can **change the default prompt value** or modify audio/preset options:
```bash
# Default prompt value
DEFAULT_TARGET_MB=8
# Change audio bitrate (kbps)
AUDIO_BITRATE=64
# Change x264 preset
-preset fast
```
---
## ๐ Why 2-Pass?
2-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.
---
## ๐ License
MIT License โ free to use and modify.
---