A tiny, dependency-free Bash script that compresses any video down to a target size (~20 MB by default) as a 720p WebM file β perfect for email attachments, Slack/Discord uploads, web embeds, or shrinking large screen recordings.
It uses a two-pass VP9 encode with Opus audio and automatically calculates the right bitrate based on your video's duration, so the output reliably lands near the target size.
- π― Target-size aware β picks the bitrate from the video's length to hit ~20 MB
- π Auto-scales to 720p while preserving aspect ratio
- ποΈ Two-pass VP9 (
libvpx-vp9) for the best quality-per-byte - π Opus audio at 64 kbps
- π Friendly guard rails β checks for missing files, missing
ffmpeg, and very long videos
ffmpeg(includesffprobe)
Install on macOS:
brew install ffmpegInstall on Debian/Ubuntu:
sudo apt install ffmpegbash compress_video.sh input.mp4The compressed file is written next to your input as input_compressed.webm.
Input: demo.mp4
Duration: 312s
Video bitrate: 461kbps
Audio bitrate: 64kbps
Output: demo_compressed.webm
Starting two-pass VP9 encode (this will take a while for large files)...
Done! Output saved as: demo_compressed.webm
File size: 19M
The target size in kilobits is divided by the video duration to get a total bitrate budget. After reserving 64 kbps for audio, the rest goes to video. A two-pass encode then distributes those bits intelligently across the timeline for consistent quality.
To change the target size, edit this line in the script:
TARGET_SIZE_KB=20480 # 20MB in KB