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.
Metadata
Release files for merge-subtitles 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| merge_subtitles-1.0.0.tar.gz | 9.3 kB | Without provenance | Details for merge_subtitles-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| merge_subtitles-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for merge_subtitles-1.0.0-py3-none-any.whl |
Total release size: 18.8 kB
Release files / merge_subtitles-1.0.0.tar.gz
| Download URL | merge_subtitles-1.0.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74937ee066e1cf377327fe18bde4f3fe5329af6c0e9d9ab269b3d88bad2a0324
|
|
BLAKE2b-256 checksum How to use checksums |
345e1c9636814f664d093a2c6743bddd66aa3f29e6e0e6cc741b9b083d447306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / merge_subtitles-1.0.0-py3-none-any.whl
| Download URL | merge_subtitles-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49de44fc35c1e0475280fabd647ee80c8527441449557298cfda32ebd657f779
|
|
BLAKE2b-256 checksum How to use checksums |
bd2d56a98de1095086da088b9ecbbc15faf572953cacb2ecb8346b318ae2ac81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Security for merge-subtitles 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.