- This is useful for remuxes where each episode has the same basic input and output variables.
- My fork of this script allows you to map different titles to both the mkv and filename for each episode, offset episode numbers by a predetermined amount, autocomplete filenames, automatically calculate the CRC of output files, and automatically mux in required fonts.
- Only works on Windows for now.
-
pip install FontCollector Colorama
- FontCollector is used for automatic font muxing
- Advanced Renamer to batch rename files.
-
Clone this repository.
-
Make sure all your MKV files have the same name apart from the episode numbers.
- Note: this can now be bypassed by using filepath autocompletion.
-
Open
mkvtoolnix-gui.exe
. -
Insert all the media for your first episode of the batch.
-
Do your edits in the GUI, including naming the output file whatever you'd like.
- If you want to add different attachments for each episode, see the relevant section.
-
Go to
Menu Bar > Multiplexer > Create option file
, and save it asoptions.json
in the same directory as themkv_merge_mapper.py
script. You can then close the GUI. -
Open said
options.json
file with your text editor:-
Where there is an episode number, replace the number with the text
EPNUM
(S01E01 -> S01EEPNUM) -
Do this for all the file paths in the
options.json
file. -
For more options on manipulating episode numbers, see Episode Number Modifiers
-
-
Find the MKVToolNix folder and get its path. (
Shift + Right-Click > Copy as path
from Windows File Explorer).- Typically
C:\\Program Files\\MKVToolNix
.
- Typically
-
Edit
mkvconfig.json
and insert the path to the MKVToolNix folder into the quotes after the variablemkv_merge_path
. You can also change other script variables here.- You MUST replace every instance of a backslash
\
in mkvmerge's filepath with two backslashes\\
.
- You MUST replace every instance of a backslash
-
Optional edits to
options.json
. See following sections. -
Run
mkvtoolnix_merge_mapper.py
. -
When prompted, enter the range of episode numbers you want to mux. These should be in the format
1-2,4,6-22,24
, where-
denotes a range and,
acts as a separator. In this example, episodes 3, 5, and 23 are skipped.- The order you specify the episodes in will be the order in which they are muxed. So if you enter
5-8,1-4,9
, episodes 5-8 will be muxed before 1-4, with 9 being muxed at the end.
- The order you specify the episodes in will be the order in which they are muxed. So if you enter
Your files will then be muxed into the set output directory (mkvmerge_out
by default).
The script will put the episode title in filenames and automatically mux episode titles to the mkv header without having to manually change them in each file.
In order to do this, a titles.txt
file must be in the working directory (alongside the options file and the script).
Write the desired titles for each episode in titles.txt
, with each separate title on a new line. (The first line will be the first episode's title, the second line will be the second episode's title, and so on).
You can also include an mkvtitles.txt
file in the working directory, which can be used to use separate titles for the filename and mkv header. If only titles.txt
is present, its titles will be used in both the filenames and mkv header, and vice versa with mkvtitles.txt
.
In the options file, any instance of EPTITLE
or MKVTITLE
will be replaced with the current episode's title, from either titles.txt
or mkvtitles.txt
respectively. For example, Show - EPNUM - EPTITLE.mkv
will become Show - 01 - dumb title.mkv
.
If the output filename doesn't have EPTITLE
or MKVTITLE
in it, and the filename title option is enabled, the title will be automatically placed after the episode number, using the separator specified in mkvconfig.json
.
The script will automatically detect the fonts needed in included .ass files and will mux them into the output file. This feature also removes any unneeded fonts that may have been included in the input mkv files.
This feature requires FontCollector to be installed.
-
Simply run
mkvtoolnix_merge_mapper.py
, and when prompted on whether you want to automatically mux fonts, inputyes
ory
.- This preference can also be set in the
mkvconfig.json
file
- This preference can also be set in the
-
If you want to mux fonts that aren't installed or in one of the input mkv files, you have to specify their directory in the
additional_fonts_folder
inmkvconfig
. Multiple folders can be specified. -
I have introduced a feature where a log of FontCollector's activity is generated in the output directory, and all fonts from input mkvs will be copied to a
Fonts
folder. This should make it easier to spot and fix errors. It can be enabled inmkvconfig.json
. -
FontCollector is not perfect. Always QC your files!
The script will autocomplete the paths of specified files. Useful if the filenames you want to use have a CRC or episode name in them, which means they won't match the rule in your options file. (For example, if the releases you want to remux have filenames like Show - 01 - dumb title.mkv
, Show - 02 - different title.mkv
, the rule Show - EPNUM.mkv
won't work.)
-
Put three stars (
***
) wherever you want the script to autocomplete the filename. Using the example above, the ruleShow - EPNUM - ***
would match both of those filenames. This can also be used in folder names. -
Put two stars (
**
) if you want to specify an extension for the file. For example, let's say you have bothShow - 01 - dumb title.mkv
andShow - 01 - dumb title.ass
in the same directory. In this case the ruleShow - EPNUM - **.mkv
would match the first file andShow - EPNUM - **.ass
would match the second. -
As long as your rule gives enough information to single out one file, it will be accepted.
The script will calculate a CRC32 hash for the file and insert it into the filename.
-
Include
CRC
anywhere in the output filename. The script will calculate the CRC of the output file and replaceCRC
with it. -
For example, if your output rule is
Show - EPNUM [CRC].mkv
, the output will beShow - 01 [CF022A71]
.
The script will offset the episode numbers in the options file by a certain amount each time. Useful if you're muxing different releases that use different episode numbers.
-
Put
MOD()
with the offset in the brackets after any instance of EPNUM that you want to change in the options file.- For example, all my input files say "Episode 31", "Episode 32", but I want the episode numbers in my output file to be "Episode 01", "Episode 02", and so on. To do so, I would edit any instance of
EPNUM
that I would want to offset toEPNUMMOD(-30)
in the options file.
- For example, all my input files say "Episode 31", "Episode 32", but I want the episode numbers in my output file to be "Episode 01", "Episode 02", and so on. To do so, I would edit any instance of
-
If you want the episode numbers in the mkv title changed, just put
MOD()
with your offset number in the brackets anywhere in the title field.
The script will mux different (specified) attachments for each episode. Can be used instead of the automatic font muxer.
-
Create a separate folder for each episode, with the attachments for each episode in their respective folders.
- For example, if you have different font attachments for episodes 1 and 2, make folders called
..\01
and..\02
, with the attachments for episode 1 in..\01
and those for episode 2 in..\02
.
- For example, if you have different font attachments for episodes 1 and 2, make folders called
-
Add a file from one of the folders as an attachment in mkvtoolnix before you export as
options.json
. -
When editing
options.json
:-
Edit the aforementioned attachment's
attachment-mime-type
to bebatch/attachment
. -
attachment-name
can be left as-is. -
Replace the episode number in the folder name with
EPNUM
.
-
Code licensed under GNU General Public License v3.0.