Batch merge/mux .srt with .mkv files

for %%A IN (*.mkv) do (
"B:\OneDrive\Portable applications\mkvtoolnix\mkvmerge.exe" -o "remux-%%~nxA" "%%~A" "%%~nA.srt"
echo  Replace this Line with your othr commands!
)

And see mkvpropedit -- Modify properties of existing Matroska and Change Default Language/Subtitles in MKV Files


I find a good example in another answer[1], use the general sketch below:

for %%f in (*.mkv) do (
        echo %%~nf
         mkvmerge -o "%%~nf_New.mkv" "%%~nf_New.mkv" --language 0:eng "%%~nf.srt"

)

The example more similar I found on the mkvmerge site [2]

mkvmerge -o with-lang-codes.mkv --language 2:ger --language 3:dut \
--default-track 3 without-lang-codes.mkv --language 0:eng english.srt \
--default-track 0 --language 0:fre french.srt

It's enough that you put inside the for cycle, the command line that works in your single case, changing the mkv file with %%~nf.mkv and the srt with %%~nf.srt and all the options in the correct place.


I had the same problem as yourself and put together the below PowerShell Script to achieve the batch muxing of subtitles.

#Batch Merge Subtitles with MKVMerge - Iain McCain

#Set MKVMerge.exe Path
$MKVMerge = 'C:\Program Files\MKVToolNix\mkvmerge.exe'
#Set Target
$Directory = "Z:\Films\"
#Set Subtitle Extension
$SubExtension = 'eng.srt'

#Process
$Subs = Get-ChildItem $Directory -Filter "*.$SubExtension" -Recurse | % { $_.FullName } | Sort-Object
$Count = $Subs.count
Write-Host "$Count MKV's to be processed."

Foreach ($Sub in $Subs) 
{
#Get File Name
$FormatName = $Sub.ToString()
$Name = $FormatName.TrimEnd(".$SubExtension")
$MKV = $Name + '.mkv'

#Set Output File Name
$Output = $Name + '___MERGED' + '.mkv'

#Execute
& $MKVMerge -o "$Output" --default-track "0" --language "0:eng" "$Sub" "$MKV"

#Clean Up
Remove-Item $MKV
Remove-Item $Sub
Rename-Item $Output -NewName $MKV
} 

Old post, but in case others are looking, I created a program that leverages MKVToolNix and is able to do what's being asked and process entire directories in a single batch.

https://github.com/iPzard/mkvtoolnix-batch-tool

MKVToolNix Batch Tool