Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 video-compressor

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.

✨ Features

  • 🎯 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

πŸ“¦ Requirements

Install on macOS:

brew install ffmpeg

Install on Debian/Ubuntu:

sudo apt install ffmpeg

πŸš€ Usage

bash compress_video.sh input.mp4

The compressed file is written next to your input as input_compressed.webm.

Example

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

βš™οΈ How it works

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

πŸ“„ License

MIT

About

🎬 Tiny dependency-free Bash script that compresses any video to a target size (~20MB) as 720p WebM using two-pass VP9 + Opus β€” great for email, Slack/Discord, and web embeds.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages