Last active
December 5, 2021 05:55
-
-
Save DessertArbiter/870fa17afeb4e63941cb1403f5e90a25 to your computer and use it in GitHub Desktop.
PowerShell script to run mkvmerge on all mkv and mp4 files in a directory, supports all mkvmerge parameters. Creates new mkv files in "mkvmerge" subdirectory of current folder without overwriting or deleting the originals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$parameters = Read-Host "Enter parameters, leave blank for defaults" | |
$parameterArray = $parameters.Split(" ") | |
Write-Host "For single subtitle, base name must match video file name (without extension).`nIf files have multiple external subtitles, they must be named like so: videoFileName_Track[0 - 99].[ext]" | |
$numSubs = Read-Host "Number of external subtitles to merge? (0 for none)" | |
if ($numSubs -gt 0) { | |
Write-Host "External subtitles:`n`tass,pgs,vobsub,srt,etc." | |
$subsExt = Read-Host "Subtitle file type?" | |
} | |
$subsName = @() | |
Get-ChildItem -Path '*.mkv', '*.mp4' | ForEach-Object { | |
Write-Verbose "Processing file: $_" | |
$mkvFullName = [System.IO.Path]::ChangeExtension($_.FullName, "mkv") | |
$mkvFileName = [System.IO.Path]::GetFileName($mkvFullName) | |
$mkvBaseNameNoExt = [System.IO.Path]::GetFileNameWithoutExtension($_.FullName) | |
if ($numSubs -gt 1) { | |
for ($i = 0; $i -lt $numSubs; $i++) { | |
$subsName = $subsName + "$mkvBaseNameNoExt`_Track$i.$subsExt" | |
} | |
} | |
elseif ($numSubs -eq 1) { | |
$subsName = "$mkvBaseNameNoExt.$subsExt" | |
} | |
& mkvmerge -o ".\mkvmerge\$mkvFileName" $parameterArray $_.FullName $subsName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment