Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.14.0
๐ฌ Video Compressor (ffmpeg + Gradio)
This project is a simple video compression tool built with Gradio for the user interface and FFmpeg for the actual compression.
It allows you to upload a video, set the CRF (Constant Rate Factor) value for compression quality, and download the compressed video.
A real-time progress bar shows the compression progress.
๐ Features
- Upload common video formats:
.mp4,.avi,.mov,.mkv - Compress videos using H.265 (HEVC) codec (
libx265) - Adjust CRF (23 = high quality, 32 = lower quality but smaller file size)
- Real-time progress updates during compression
- Automatic file size comparison after compression
- Download compressed video directly
- Built with Gradio UI โ lightweight and easy to run
๐ Requirements
Python 3.9+ recommended
Install dependencies:
pip install gradioInstall FFmpeg (required for video compression).
- On macOS (Homebrew):
brew install ffmpeg - On Ubuntu/Debian:
sudo apt update && sudo apt install ffmpeg - On Windows: Download FFmpeg and add it to your PATH.
- On macOS (Homebrew):
๐ Project Structure
video-compressor/
โโโ app.py # Main Python script (the Gradio app)
โโโ README.md # Documentation
โถ๏ธ Usage
Run the app locally with:
python app.py
Then open your browser at: http://127.0.0.1:7860
- Upload a video file
- Choose compression level (CRF)
- Lower CRF = higher quality, larger file size
- Higher CRF = lower quality, smaller file size
- Default: 28 (balanced)
- Click "Compress Video"
- Wait for the progress bar to reach 100%
- Download your compressed video
โ๏ธ How It Works
- The app calls
ffprobeto read the video duration. - It runs
ffmpegwithlibx265codec and user-specified CRF. - While running, stderr output from ffmpeg is parsed (
time=HH:MM:SS.xx) to update progress. - After finishing, the app calculates:
- Original size (MB)
- New size (MB)
- Reduction percentage
- Displays results + download link for the compressed file.
๐ Example Results
- Original: 100 MB
- Compressed: 35 MB
- Reduced by: 65% ๐
๐งฉ Code Highlights
- Helper functions keep the code clean:
get_video_duration()โ fetch video length with ffprobebuild_ffmpeg_command()โ builds ffmpeg CLI commandsummarize_compression()โ calculates file size reduction
- Unified exception handling with
safe_none_on_error() - Progress tracking uses regex on ffmpeg stderr
๐ฎ Future Improvements
- Option to downscale resolution (1080p โ 720p, 480p)
- Add support for different codecs (VP9, AV1)
- Cloud deployment with Hugging Face Spaces or Docker
๐ License
MIT License. Free to use and modify.
๐จโ๐ป Author
Developed by Pavel Lakov
๐ GitHub