A tool for merging MP4 video files with SRT subtitle files into MKV format
Project description
merge-subtitles
A Python command-line tool that merges MP4 video files with SRT subtitle files into MKV format using FFmpeg.
Features
- Merge MP4 videos with SRT subtitles into MKV containers
- Process single files or multiple files using wildcards
- Automatically extract and add season/episode numbers to output filenames
- Archive original files after processing
- Dry-run mode to preview operations
- Intelligent episode/season number detection from directory names and filenames
Prerequisites
- Python 3.6+
- FFmpeg installed and available in your PATH
Installing FFmpeg
macOS (using Homebrew):
brew install ffmpeg
Ubuntu/Debian:
sudo apt update
sudo apt install ffmpeg
Windows: Download from https://ffmpeg.org/download.html
Installation
From PyPI (Recommended)
pip install merge-subtitles
From Source
-
Clone this repository:
git clone https://github.com/lorenzowood/merge-subtitles.git cd merge-subtitles
-
Install the package:
pip install .
Development Installation
For development, install in editable mode:
git clone https://github.com/lorenzowood/merge-subtitles.git
cd merge-subtitles
pip install -e ".[dev]"
Development
Running Tests
Install test dependencies:
pip install -r requirements-dev.txt
Run the test suite:
pytest
Run tests with coverage:
pytest --cov=merge-subtitles
The test suite includes:
- Unit tests for episode/season number detection
- Integration tests for file processing with mocked FFmpeg calls
- Tests for all command-line options (--dry-run, --add-episode-numbers, --archive-after-processing)
- Tests for error handling and edge cases
Usage
Basic Usage
Process a single file pair:
merge-subtitles "movie_name"
This will look for movie_name.mp4 and movie_name.srt and create movie_name.mkv.
Process Multiple Files
Use wildcards to process multiple files:
merge-subtitles "*"
It's important to use quotation marks to prevent the shell from expanding the wildcard. When used with a wildcard, it looks for matching pairs of MP4 and SRT files and then works through those.
Options
--add-episode-numbers: Add season/episode numbers to output filenames--archive-after-processing: Move original files to anarchive/directory--dry-run: Show what would be done without actually processing files
Examples
# Process all episodes and add episode numbers
merge-subtitles "episode_*" --add-episode-numbers
# Process files and archive originals
merge-subtitles "movie" --archive-after-processing
# Preview what would happen
merge-subtitles "season_*" --dry-run --add-episode-numbers
Episode Number Detection
The tool can automatically detect season and episode numbers from:
Directory names:
Series 1/,Season 2/, etc.
File names:
e1,e12(episode numbers)ep1,ep 12episode1,episode 121.,12.(number followed by period)
When both season and episode numbers are detected, output files will be named:
original_name - s01e01.mkv
If you use the --add-episode-numbers switch, any files where it can't detect the season or episode number will be named:
original_name - MISSING EPISODE NUMBER.mkv
Output
- Creates MKV files with embedded SRT subtitles
- Preserves video and audio streams (copy mode for efficiency)
- Subtitle track is set to SRT format
Error Handling
- Checks for FFmpeg availability before processing
- Validates input file existence
- Reports processing errors with FFmpeg output
- Continues processing remaining files if one fails
License
Contributing
Feel free to submit issues and pull requests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file merge_subtitles-1.0.0.tar.gz.
File metadata
- Download URL: merge_subtitles-1.0.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74937ee066e1cf377327fe18bde4f3fe5329af6c0e9d9ab269b3d88bad2a0324
|
|
| MD5 |
e70bd37da283ae7b618f0db9a1033c9a
|
|
| BLAKE2b-256 |
345e1c9636814f664d093a2c6743bddd66aa3f29e6e0e6cc741b9b083d447306
|
File details
Details for the file merge_subtitles-1.0.0-py3-none-any.whl.
File metadata
- Download URL: merge_subtitles-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49de44fc35c1e0475280fabd647ee80c8527441449557298cfda32ebd657f779
|
|
| MD5 |
db2cd74f3b0f5c33aa18fe3afdffd147
|
|
| BLAKE2b-256 |
bd2d56a98de1095086da088b9ecbbc15faf572953cacb2ecb8346b318ae2ac81
|