A powerful tool for automatically downloading, compressing, and re-uploading videos from FTP servers with optimized AV1 encoding. The tool is specially designed to work with BunnyCDN storage but is compatible with any standard FTP server.
FTP Video Compressor helps you reduce your storage costs by intelligently compressing video files while maintaining a target visual quality. The tool uses NVIDIA's AV1 hardware encoding to achieve high compression ratios with minimal quality loss, as measured by the industry-standard VMAF quality metric.
Key features:
- Automatic recursive scanning of FTP directories
- Intelligent sample-based analysis to determine optimal encoding settings
- VMAF-guided quality control
- Multi-threading for parallel processing
- Special handling for BunnyCDN storage
- Detailed compression statistics
- Subtitle and audio track handling
- NVIDIA GPU with AV1 encoding support (RTX 40 series or newer)
- Python 3.7+
- FFmpeg with NVIDIA hardware encoding support
- VMAF executable in the working directory
ftplib
subprocess
multiprocessing
concurrent.futures
json
-
Clone or download this repository
-
Install the required Python packages:
pip install ftplib
-
Install FFmpeg with NVIDIA hardware acceleration support:
- Windows: Download from BtbN's FFmpeg Builds with NVIDIA support
- Linux: Follow FFmpeg NVIDIA GPU acceleration guide
-
Ensure you have the latest NVIDIA drivers installed that support AV1 encoding
Run the script with the following command-line arguments:
python ftp_video_compressor.py --host <ftp_host> --user <username> --password <password> --output <local_output_dir> [options]--host: FTP server hostname or IP address--user: FTP username--password: FTP password--output: Local output directory for working files
--directory: FTP directory to scan for videos (default:/)--storage-zone: BunnyCDN storage zone name (if using BunnyCDN)--vmaf-diff: Target VMAF quality difference (default:8)--concurrent: Number of videos to process concurrently (default:2)--audio-track: Audio track to include (default:0)--include-subtitles: Include subtitles in output--subtitle-track: Subtitle track to include (default:0)--skip-existing: Skip processing if output file already exists--replace-originals: Replace original files on FTP with compressed versions (default:True)--keep-originals: Keep original files on FTP and save compressed versions locally--scan-all: Scan all directories including those that fail initially (useful for BunnyCDN)
python ftp_video_compressor.py --host ftp.example.com --user myusername --password mypassword --output /path/to/output --directory /videos --vmaf-diff 10 --concurrent 4python ftp_video_compressor.py --host storage.bunnycdn.com --user storagezonename --password api-access-key --output /path/to/output --storage-zone storagezonename --vmaf-diff 8 --concurrent 2# Process HD content with higher quality retention
python ftp_video_compressor.py --host ftp.example.com --user myusername --password mypassword --output /path/to/output --directory /HD_content --vmaf-diff 5
# Process SD content with more aggressive compression
python ftp_video_compressor.py --host ftp.example.com --user myusername --password mypassword --output /path/to/output --directory /SD_content --vmaf-diff 12- The script connects to the FTP server and recursively scans for video files (.mp4, .mkv)
- For each directory found, it downloads a representative video file
- It analyzes the video by extracting short samples from the beginning, middle, and end
- It tests various encoding parameters to find the optimal setting that maintains the target VMAF score difference
- Once the optimal encoding setting is determined for a directory, it's applied to all videos in that directory
- The videos are processed concurrently (limited by the
--concurrentparameter) - Processed videos are either re-uploaded to the FTP server (replacing originals) or saved locally
- Detailed statistics are provided about space savings
VMAF (Video Multi-method Assessment Fusion) is a perceptual video quality metric developed by Netflix. The --vmaf-diff parameter controls the quality/compression tradeoff:
- Lower values (e.g., 5): Higher quality retention but less compression
- Higher values (e.g., 15): More aggressive compression but potentially more visible quality loss
- Recommended range: 6-12 for most content
The default value of 8 provides a good balance between quality and compression for most content.
If you encounter "Directory Not Found" errors when the directories are clearly visible:
- Double-check your FTP path structure
- Ensure you're not using absolute paths when already in a subdirectory
- Try running without a specific directory to auto-scan from the current location
For BunnyCDN connections:
- Ensure you're using the storage hostname (storage.bunnycdn.com)
- The username should be your storage zone name
- The password should be your API access key
- Use the
--storage-zoneparameter if your FTP username is different from your storage zone name
If encoding is too slow:
- Reduce the number of concurrent processes with
--concurrent - Ensure your NVIDIA drivers are up to date
- Monitor GPU utilization to ensure it's being properly utilized
- The script requires an NVIDIA GPU with AV1 encoding support
- Processing very large files may require substantial local storage
- The VMAF analysis temporarily needs disk space for sample extraction
- FTP transfer speeds may limit overall performance for large libraries
- The script caches encoding settings for each directory, so subsequent runs will be faster
- For optimal results, organize your videos by quality/resolution in different directories
- AV1 encoding provides significant space savings over H.264, often 40-60% for the same visual quality
- Consider using a higher
--vmaf-diffvalue for content where visual quality is less critical