A robust Python script for batch converting video files using FFmpeg with hardware-accelerated encoding and automatic color profile detection. Converts DLOG-M, HLG, and other formats to REC709 with appropriate color grading.
- Batch Processing: Automatically processes all MP4/MOV files in a directory
- Hardware Acceleration: Uses VideoToolbox on macOS for efficient encoding
- Automatic Color Profile Detection: Detects DLOG-M, HLG, and REC709 color profiles
- Smart LUT Application: Automatically applies appropriate LUT files for color grading
- Progress Tracking: Real-time progress bars for individual files and overall progress
- Comprehensive Logging: Detailed logs with conversion statistics
- Error Handling: Robust error handling with detailed error messages
- Flexible Configuration: Command-line options for customization
- Skip Existing: Automatically skips files that have already been converted
- Size Comparison: Shows input/output file sizes and compression ratios
- Python 3.8+: Required for running the script
- FFmpeg: Must be installed and available in your PATH
- On macOS:
brew install ffmpeg - On Ubuntu/Debian:
sudo apt install ffmpeg - On Windows: Download from ffmpeg.org
- On macOS:
- Clone or download this repository
- Make sure FFmpeg is installed and accessible from command line
- The script is ready to use - no additional Python dependencies required
# Install using uv (recommended)
uv sync
# Or install using pip
pip install -e .
# Then run from anywhere
ffmpeg-batch-convertConvert all video files in the current directory:
python main.py# Convert files in a specific directory
python main.py -d /path/to/videos
# Use a custom output suffix
python main.py -s _converted
# Use a custom LUT file
python main.py -l my_custom_lut.cube
# Enable verbose logging
python main.py -v
# Combine options
python main.py -d /path/to/videos -s _hlg_converted -v-d, --directory: Input directory containing video files (default: current directory)-o, --output: Output directory (default: same as input directory)-s, --suffix: Output file suffix (default:_REC709)-l, --lut: Custom LUT file for color grading (auto-selects by default)-v, --verbose: Enable verbose logging-h, --help: Show help message
The script provides:
- Real-time Progress: Shows encoding progress for each file
- File Information: Displays input size, duration, and output filename
- Conversion Summary: Final statistics including:
- Total files processed
- Success/failure counts
- Total processing time
- File size comparisons
- Space saved
The script uses the following FFmpeg configuration:
- Hardware Acceleration: VideoToolbox (macOS)
- Codec: HEVC (H.265) with hardware encoding
- Pixel Format: YUV420P10LE (10-bit)
- Bitrate: 20Mbps with 25Mbps max rate
- Output Color Space: BT.709 (REC709)
- Audio: Copy without re-encoding
- DLOG-M (DJI footage): Applies
luts/DJI_DLogM_to_Rec709.cube - HLG (iPhone footage): Applies
luts/iPhone_2020_to_709_33.cube - REC709: No LUT needed, direct encoding
- Unknown: Defaults to DLOG-M LUT
- Supports:
.mp4,.mov,.MP4,.MOVfiles - Output format: MP4 with HEVC encoding
- Automatically skips existing output files
- Creates detailed logs in
conversion.log
The script includes comprehensive error handling:
- Dependency checking (FFmpeg/ffprobe availability)
- File access permissions
- FFmpeg process errors
- Timeout handling for long operations
- Graceful handling of user interruption (Ctrl+C)
- Console output with colored progress indicators
- Detailed log file (
conversion.log) with timestamps - Error tracking and reporting
- Processing statistics and summaries
- Hardware-accelerated encoding for optimal performance
- Real-time progress monitoring
- Efficient memory usage
- Parallel-ready architecture (can be extended for concurrent processing)
The tool is built around a single VideoConverter class that handles the entire conversion pipeline:
- File Discovery: Scans for video files in the input directory
- Metadata Analysis: Uses ffprobe to extract color profile information
- Color Profile Detection: Automatically detects DLOG-M, HLG, or REC709 profiles
- LUT Selection: Chooses appropriate LUT file based on detected profile
- Hardware-Accelerated Conversion: Executes FFmpeg with VideoToolbox acceleration
- Progress Monitoring: Real-time progress parsing and display
- VideoInfo: Dataclass storing video metadata (duration, color space, dimensions)
- Color Profile Detection: Analyzes ffprobe metadata to determine source format
- FFmpeg Command Builder: Constructs appropriate FFmpeg commands with LUT filters
- Progress Display: Real-time encoding progress with colored terminal output
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Error: ffmpeg not found in PATH
Solution: Install FFmpeg and ensure it's in your system PATH.
PermissionError: [Errno 13] Permission denied
Solution: Check file permissions and ensure you have write access to the output directory.
If hardware acceleration fails, the script will fall back to software encoding. Check your system's VideoToolbox support.
For very large files, consider:
- Ensuring sufficient disk space
- Monitoring system resources
- Using the verbose flag to track progress