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




Prerequisite

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.

25 comments... read them below or respond.

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

    ReplyDelete
    Replies
    1. Try this: https://1drv.ms/u/s!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

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

    ReplyDelete
  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

    ReplyDelete
  4. 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

    ReplyDelete
  5. After looking through a few blog articles on your website,
    we sincerely appreciate the way you blogged.
    We've added it to our list of bookmarked web pages and will be checking back in the near
    future. Please also visit my website and tell us what you think.
    Adobe Premiere Pro Crack
    Letasoft Sound Booster Crack
    Native Instruments Massive Crack
    MKVToolNix Crack
    Backup4all Pro crack

    ReplyDelete

  6. Thank you so much for sharing this amazing informationhttps://www.fullcracked.org/mkvtoolnix-crack/

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

    ReplyDelete
  8. So nice I am enjoying for that post as for u latest version of this Security tool Available
    mkvtoolnix-crack
    avs-video-editor-crack
    iobit-smart-defrag-pro-crack

    ReplyDelete
  9. 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.
    key4pc.com
    iobit-smart-defrag-pro-crack

    ReplyDelete
  10. This site have particular software articles which emits an impression of being a significant and significant for you individual, able software installation.This is the spot you can get helps for any software installation, usage and cracked.
    thecrackfiles.com
    mkvtoolnix-crack
    rekordbox-dj-crack
    reaper-crack

    ReplyDelete
  11. I guess I am the only one who comes here to share my very own experience guess what? I am using my laptop for almost the post 2 years.

    AVS Audio Editor Crack

    Muvizu Play Crack

    Betternet VPN Premium Crack

    Hotspot Shield Crack

    ReplyDelete
  12. So nice I am enjoying for that post as for u latest version of this Security tool Available
    letasoft sound booster crack

    ReplyDelete
  13. So nice I am enjoying for that post as for u latest version of this Security tool Available.
    Letasoft Sound Booster Crack
    windowsup.net

    ReplyDelete


  14. Guest blogging is crucial for SEO that's why this post Crack Pro Software provides a free best blog and article submission sites list with instant approval
    reaper-crack
    serif-affinity-photo-crack
    mkvtoolnix-crack
    crackny.com/minitab-crack
    imindmap-pro-crack
    boom-3d-crack
    restoro-crack
    fireshot-pro-crack
    microsoft-visio-pro-crack

    ReplyDelete
  15. Very good article! We will be linking to this particularly great post on our website. Keep up the good writing.
    Driver Talent Pro Crack
    Weather Pro Crack
    reflector Pro Crack
    keyscape Crack
    ozone imager Crack
    vstfull.com

    ReplyDelete
  16. Amazing blog! I really like the way you explained such information about this post with us. And blog is really helpful for us this website.
    WonderShare UniConverter Crack
    Color Finale Pro Crack
    Sound theory Gullfoss Crack
    ascrack.org

    ReplyDelete
  17. Amazing blog! I really like the way you explained such information about this post with us. And blog is really helpful for us this website
    Ozone Imager Crack
    up4crack.net

    ReplyDelete
  18. Amazing blog! I really like the way you explained such information about this post with us. And blog is really helpful for us this website
    Ozone Imager Crack
    Nova Launcher Prime APK Crack
    up4crack.net

    ReplyDelete
  19. Very good article! We will be linking to this particularly great post on our website. Keep up the good writing.downloadpc.co
    Auslogics BoostSpeed Crack
    Wondershare Uniconverter Crack

    ReplyDelete
  20. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. crackdoc.org I hope to have many more entries or so from you.
    Very interesting blog.
    Hotspot Shield Elite Crack
    Wondershare UniConverter Crack
    OpenShot Video Editor Crack
    Mackeeper Crack

    ReplyDelete

Copyright Dave Thijssen. Powered by Blogger.