Skip to content

MKV Tag Generator

patrickenfuego edited this page Jun 20, 2022 · 11 revisions

Introduction

Using the parameter -GenerateMKVTagFile (or its alias, -CreateTagFile) you can automatically pull, process, and mux custom XML tag files into your encoded output file. This only works for files in the Matroska format (duh), but it's a cool way to add interesting metadata to your container. The metadata is pulled from the TMDB API and requires a valid TMDB API key to work (its free, you just need to sign up. Currently, there is very little support for TV shows (sorry).

The script called from the parameter will automatically attempt to detect the film's title and year based on the input path (if that data is present) using regular expressions, so giving your encode a clean output title is recommended. Sometimes, the wrong data is pulled and you will need to specify a title and year via parameters; this is especially true for films with multiple releases (Like Dune, for example) and foreign films.

Software Requirements

The MKVToolnix suite, which can be downloaded here or from pretty much any package manager in existence. Specifically, the command line tools mkvmerge and mkvpropedit are used.

Parameter Options

The parameter accepts a hashtable argument which is then splatted to the script MatroskaTagGenerator.ps1 in the scripts top-level directory. The script can accept the following parameters either contained within the hashtable or run as a standalone script:

Parameter Mandatory Description
Path True Path to the encoded output file - this is already covered by the -OutputPath parameter
APIKey True TMDB API Key
Title False Specify an optional clean title to use for search
Year False Specify the release year (sometimes required for multiple release films)
Properties False Pull additional metadata properties from the API by name (not guaranteed to work)
SkipProperties False Default properties to skip, like Cast, Directors, Writers, & IMDB ID (this can be customized)
NoMux False Creates the XML file, but does not multiplex it into the output file automatically
AllowClobber False Switch to enable overwriting of an existing XML files

Usage

Only the -APIKey parameter is required as the other mandatory parameter -Path is already covered (unless you run the script on its own), but you can include them all if you want. Example:

PS > .\FFEncoder.ps1 ~/Movies/Ex_Machina_remux.mkv -CRF 18 `
>>     -GenerateMKVTagFile @{APIKey='9862555x293fab2551aaffej22n93bb1';SkipProperties=@('Writers','Directors'); NoMux=$true} `
>>     -o '/Users/patrickenfuego/Movies/Ex Machina 2014.mkv'

Notice the use of a clean title and year in the output file - this is recommended but not required.

Customization

You can set your own defaults for most of the parameters, depending on how you want to use it. You can also make APIKey non-mandatory and give it a default value so you don't have to pass it each time (this is what I do). To do this change lines 88-90:

# Change this
[Parameter(Mandatory = $True, Position = 1)]
[Alias('Key')]
[string]$APIKey,

# To this
[Parameter(Mandatory = $false, Position = 1)]
[Alias('Key')]
[string]$APIKey = '9862555x293fab2551aaffej22n93bb1', # Whatever your API key is

For more info:

PS> Get-Help .\scripts\MatroskaTagGenerator.ps1 -Full
Clone this wiki locally