A Python script to compress video files using ffmpeg. It supports both single file compression and batch processing of entire directories.
- Smart Compression: Uses
libx264codec with a CRF of 28 for a good balance between quality and file size. - Batch Processing: Can process an entire folder of videos at once.
- Safe Output:
- For folders: Creates a new folder (e.g.,
videos_compressed) so original files are untouched. - For files: Creates a new file with
_compressedsuffix (e.g.,video_compressed.mp4).
- For folders: Creates a new folder (e.g.,
- Reporting: Shows progress and calculates total space saved after compression.
- Cross-Platform Checks: Automatically detects if
ffmpegis missing and provides OS-specific installation commands.
- Python 3: Ensure you have Python 3 installed.
- FFmpeg: This tool requires
ffmpegto be installed on your system.
- macOS:
brew install ffmpeg
- Linux (Debian/Ubuntu):
sudo apt install ffmpeg
- Windows/Other: Download from ffmpeg.org and add it to your system PATH.
To compress a single video file, provide the path using the -p flag:
python3 video_compressor.py -p /path/to/your/video.mp4Output: Creates /path/to/your/video_compressed.mp4
To compress all videos in a folder, provide the folder path and add the -f (folder) flag:
python3 video_compressor.py -p /path/to/your/video_folder -fOutput: Creates a new folder /path/to/your/video_folder_compressed containing all the compressed videos.
The tool automatically detects and processes the following video extensions:
.mp4, .mov, .avi, .mkv, .flv, .wmv, .m4v, .webm