Merge linked MKV segments (ordered chapters, hard linking) into standalone files
Project description
mkvunlink
Merge linked MKV segments into standalone files.
Matroska can store content once and have several files reference it, through two linking mechanisms:
- Ordered chapters with segment linking: the chapter list is a playlist whose entries can point into other files by segment UID.
- Hard linking: the segment header names a previous and/or next segment, chaining whole files together.
Players that implement linking (mpv, MPC-HC) stitch the pieces together at playback. Everything else plays the file alone, with the linked content missing. mkvunlink resolves the linked timeline the way mpv does and writes it as a single self-contained file that plays anywhere.
Requirements
MKVToolNix v52 or later and FFmpeg on PATH:
| Windows | winget install MKVToolNix.MKVToolNix Gyan.FFmpeg |
| macOS | brew install mkvtoolnix ffmpeg |
| Debian/Ubuntu | apt install mkvtoolnix ffmpeg |
| Arch | pacman -S mkvtoolnix-cli ffmpeg |
The MKVToolNix installer on Windows may not add itself to PATH; add
its folder (C:\Program Files\MKVToolNix) manually.
Installation
uv tool install mkvunlink
or using pip
pip install mkvunlink
Usage
mkvunlink 'Episode 01.mkv'
mkvunlink --outdir flattened /path/to/series
mkvunlink --edition 2 'Movie.mkv'
The linked segment files must be in the same directory as the files
that reference them. Output goes to ./unlinked unless --outdir is
given.
| Option | |
|---|---|
--outdir DIR |
output directory, created if missing |
--edition N |
1-based edition to flatten when the file has several |
--no-verify |
skip the decoded-checksum check of re-encoded audio |
--keep-temp |
keep the working directory for inspection |
Behavior
- Video and bitmap subtitles (PGS/VobSub) are stream copied.
- Audio is stream copied. Codecs mkvmerge cannot split or append (FLAC) are rebuilt with ffmpeg instead: lossless codecs are cut sample-accurately and re-encoded to the same codec, then checked against the sources by decoded checksum; lossy codecs are copied per span without re-encoding.
- Text subtitles (ASS/SRT) are merged onto the joined timeline. Styles keep their names; a style is aliased only when two sources define the same name differently. Segments typeset at a different PlayRes have their styles resampled.
- Chapters are regenerated at the joined positions with their display names in every language. Title, global tags, attachments and track metadata carry over from the main file.
- Multiple editions produce a warning;
--editionselects one.
Limitations
- Segments whose video encoding parameters differ cannot be appended by mkvmerge; mkvunlink reports the error rather than transcoding video.
- WebVTT subtitles are downgraded to SRT, losing cue positioning and styling.
- A flattened file embodies one edition; run once per edition for multi-edition files.
Troubleshooting
An audio track whose header reports no sampling frequency fails the run, and PCM with a missing bit depth is stream copied per span instead of rebuilt sample-accurately. Both header fields can be repaired in place with mkvpropedit, which ships with MKVToolNix.
For example, a 48 kHz 24-bit PCM track is fixed with:
mkvpropedit broken.mkv --edit track:a1 --set sampling-frequency=48000
mkvpropedit broken.mkv --edit track:a1 --set bit-depth=24
License
MIT
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 mkvunlink-0.1.0.tar.gz.
File metadata
- Download URL: mkvunlink-0.1.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4a0f85d6c7b0e9d3515527f6bb3b5f2156d1661dfd0aeb25ae2e218d1f3c90a
|
|
| MD5 |
f5e130ba5a3dd82eb0ec1bb37d90bedb
|
|
| BLAKE2b-256 |
3b101e856d30bba4cdd50e9e0d81ef9f9c0e36760b7af5e15f320295a8e07a85
|
File details
Details for the file mkvunlink-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mkvunlink-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af66e2b7645aa3c970a3dc404f53d3ed303a936800e3d775e465ed3b134b87b1
|
|
| MD5 |
8c8769c3ff4a2d35525311c9c2460c58
|
|
| BLAKE2b-256 |
51c0fca68face6574c595b102a5bc82ff444806df5d5e7878a56286a0cee21ed
|