A comprehensive, production-ready Command Line Interface for FFmpeg operations built with Python. This tool provides a modern, user-friendly interface for video and audio processing tasks.
- Format Conversion: Convert between MP4, MKV, AVI, WebM, MOV, and more
- Resolution Change: Resize videos to 4K, 1080p, 720p, or custom resolutions
- Compression: Reduce file size using CRF quality settings
- Trimming: Cut videos by specifying start time and duration
- GIF Creation: Convert videos to animated GIFs with customizable FPS
- And More: Crop, rotate, speed adjustment, frame extraction
- Format Conversion: Convert between MP3, WAV, FLAC, AAC, M4A, OGG
- Audio Extraction: Extract audio from video files
- Volume Adjustment: Increase or decrease audio volume
- Normalization: Normalize audio levels using EBU R128 standard
- Audio Removal: Create videos without audio tracks
- Bitrate Control: Adjust audio quality and file size
- Real-time Progress Tracking: Visual progress bars with ETA
- Smart Input Validation: Intelligent file path and parameter validation
- Automatic Defaults: Smart default values for output paths
- Graceful Cancellation: Ctrl+C support with cleanup
- Cross-Platform: Works on Windows, Linux, and macOS
- Session Logging: All operations logged to
session.log
- Python 3.8 or higher
- FFmpeg installed and accessible in system PATH
Windows:
- Download FFmpeg from ffmpeg.org/download.html
- Extract the archive
- Add the
binfolder to your system PATH - Restart your terminal
macOS:
brew install ffmpegLinux (Ubuntu/Debian):
sudo apt update
sudo apt install ffmpegLinux (Fedora):
sudo dnf install ffmpegcd ffmpeg_cli_tool
pip install -r requirements.txtRun the application:
python main.py- Use numeric keys to select menu options
- Press
Bto go back to the previous menu - Press
0to exit the application - Press
Ctrl+Cto cancel any ongoing operation - Press
Enterto accept default values
- Start the application
- Select "Video Operations" from the main menu
- Choose "Convert Format"
- Enter the path to your video file
- Select the desired output format
- Confirm the operation
- Watch the real-time progress
- Find your converted file in the output directory
ffmpeg_cli_tool/
├── main.py # Application entry point
├── requirements.txt # Python dependencies
├── README.md # This file
├── core/ # Core functionality
│ ├── __init__.py
│ ├── config.py # Configuration singleton
│ ├── command_builder.py # FFmpeg command builder (Builder pattern)
│ ├── validator.py # Input validation
│ ├── ffmpeg_engine.py # FFmpeg execution engine
│ └── ui_manager.py # User interface manager
├── modules/ # Operation modules
│ ├── __init__.py
│ ├── factory.py # Module factory (Factory pattern)
│ ├── video.py # Video operations
│ └── audio.py # Audio operations
└── utils/ # Utility functions
- Singleton Pattern: Used in
Configclass for centralized configuration - Builder Pattern:
FFmpegCommandBuilderfor constructing complex FFmpeg commands - Factory Pattern:
ModuleFactoryfor dynamic module loading
- Config: Centralized configuration management
- Validator: Comprehensive input validation (paths, formats, parameters)
- CommandBuilder: Fluent interface for building FFmpeg commands
- FFmpegEngine: Subprocess management with progress tracking
- UIManager: Rich-based UI components (menus, prompts, panels)
The FFmpegCommandBuilder class provides a fluent interface for constructing FFmpeg commands:
command = (builder
.set_input(input_file)
.set_output(output_file)
.set_video_codec("libx264")
.set_crf(23)
.add_filter("scale=1920x1080")
.build())The tool parses FFmpeg's output in real-time to display:
- Percentage completed
- Time elapsed
- Estimated time remaining
- Processing speed
All operations include:
- Try-catch blocks around subprocess calls
- User-friendly error messages
- Automatic cleanup of partial files on failure
- Session logging for debugging
The Config singleton stores default settings:
- Default output directory
- Preferred video codec (default: libx264)
- Preferred audio codec (default: aac)
- Default CRF value (default: 23)
- Logging preferences
- Add a method to the appropriate module (e.g.,
video.py) - Update the
get_operations()method to include the new operation - Follow the existing pattern for input validation and command building
- Create a new module file (e.g.,
subtitle.py) - Implement the required methods
- Update
ModuleFactoryto include the new category - Add the category to
get_available_categories()
All operations are logged to session.log in the current directory:
- Timestamp of each operation
- Full FFmpeg command executed
- Error messages if operations fail
Ensure FFmpeg is installed and added to your system PATH. Run ffmpeg -version in your terminal to verify.
Ensure you have write permissions in the output directory.
Use absolute paths or ensure your current working directory is correct.
If you cancel with Ctrl+C, any partial output files are automatically cleaned up.
This project is provided as-is for educational and personal use.
To contribute:
- Follow PEP 8 style guidelines
- Add type hints to all functions
- Include docstrings for classes and methods
- Test on multiple platforms
- Update documentation
For issues or questions:
- Check the session.log file for detailed error messages
- Verify FFmpeg installation
- Ensure file paths are correct and accessible
- Review FFmpeg documentation for specific codec/filter questions