Media Target Compressor is a cross-platform command-line utility written in Python. It takes an image or video input and compresses it to a specific target file size (e.g., "Make this video 8MB" or "Make this image 500KB").
It is designed to be intelligent:
- Videos: Calculates the exact bitrate needed based on duration to hit the target size using a 2-pass FFmpeg encoding.
- Images: Uses an iterative algorithm to lower quality or resize dimensions until the file fits the target.
- 🎯 Precise Targeting: Accepts human-readable sizes (e.g.,
10MB,500KB,1GB). - 🎬 Video Support: Uses industry-standard FFmpeg for high-efficiency H.264 compression.
- 🖼️ Image Support: intelligently handles JPEGs and PNGs using Pillow.
- 💻 Cross-Platform: Works on Windows, macOS, and Linux.
- 📉 Smart Logic:
- If a file is already smaller than the target, it does nothing.
- If an image cannot be compressed enough via quality settings, it automatically resizes dimensions.
- Python 3.6+
- FFmpeg (Required for video processing)
- Windows:
winget install -e --id Gyan.FFmpeg - macOS:
brew install ffmpeg - Linux (Debian/Ubuntu):
sudo apt install ffmpeg
-
Clone the repository:
git clone https://github.com/petercunha/compressor.git cd compressor -
Install the Python requirements:
pip install Pillow
Basic syntax:
python compress.py [INPUT_FILE] [TARGET_SIZE]