Posted by Dave Thijssen Thursday 18 September 2014

Say, you have about 160 mkv files with a 160 seperate subtitles. Matroska is a container format which can hold multiple content such as video, chapters, subtitles and audio tracks. So it's much neater to have a single file for each film or episode.

Doing this manually, even using the mkvmerge job queue, is mind numbing and can take hours. Here's a relatively quick way of automatizing this.

Old situation

New situation


Download and install MKVToolNix.

Part 1

  1. Load the first mkv file and the srt file into mkvmerge GUI.
  2. Set the options as desired.
  3. Click Muxing.
  4. Click Show the command line.
  5. Modify the $mkvmergecommand variable in the PowerShell script below to math the parameters in the Current command line.

This is the command line you need to run in bulk with slightly different parameters, being the input and output files.

Part 2

  1. Modify the variables at the top of the script to reflect your situation.
  2. Run the script.

$directory = "M:\Downloads\Prison Break"
$mkvmergecommand = [String]"""""C:\Program Files\MKVToolNix\mkvmerge.exe"" -o ""%outputfile%""  ""--forced-track"" ""0:no"" ""-s"" ""0"" ""-D"" ""-A"" ""-T"" ""--no-global-tags"" ""--no-chapters"" ""("" ""%srtinputfile%"" "")"" ""--language"" ""0:eng"" ""--default-track"" ""0:yes"" ""--forced-track"" ""0:no"" ""--display-dimensions"" ""0:1280x720"" ""--language"" ""1:eng"" ""--default-track"" ""1:yes"" ""--forced-track"" ""1:no"" ""-a"" ""1"" ""-d"" ""0"" ""-S"" ""-T"" ""--no-global-tags"" ""--no-chapters"" ""("" ""%mkvinputfile%"" "")"" ""--track-order"" ""0:0,1:0,1:1"""""
$files = Get-ChildItem $directory -Filter "*.mkv" | Sort Name
Foreach ($file in $files) {
    $mkvinputfile = ($directory -replace "\\", "\\") + "\\" + ($file.Name)
    $srtinputfile = ($directory -replace "\\", "\\") + "\\" +($file.Name -replace ".mkv", ".srt")
    $outputfile =  ($directory -replace "\\", "\\") + "\\" +($file.Name -replace ".mkv", "Merged.mkv")
    $mergecommand = (($mkvmergecommand -replace "%outputfile%", $outputfile) -replace "%mkvinputfile%", $mkvinputfile) -replace "%srtinputfile%", $srtinputfile
    cmd /c $mergecommand

Download MergeMKVSRT.ps1.

10 comments... read them below or respond.

  1. Not working for me :(
    Powershell kicking out errors

    1. Try this:!AjBPRo9wXw9s2eg3AoRAwm2KGxJkwg

      To be copied to the folder containing the input files; you might need to tweak the part of the code that derives the filename of the .SRT from the .AVI's filename

  2. This comment has been removed by a blog administrator.

  3. Hello My Name is Joni and I am glad to welcome you to my site. I am a Blogger by profession. This is where you will find so many tips and tricks for Crack any product that are Related to Download Crack Softwares.

    MKVToolNix Crack


  4. Thank you so much for sharing this amazing information

  5. My response on my own website. Appreciation is a wonderful thing...thanks for sharing keep it up. MKVToolnix Crack

  6. So nice I am enjoying for that post as for u latest version of this Security tool Available

  7. It is the best website for all of us. It provides all types of software and apps which
    we need. you can visit this website.


Copyright Dave Thijssen. Powered by Blogger.