-
-
Save jwallet/52834b7a1e293e481ebe9ab1870f25b3 to your computer and use it in GitHub Desktop.
# Credit: https://www.github.com/jwallet | |
function mkv-set-language([string]$lang="eng") { | |
Get-ChildItem -Path "." -Name -Recurse -File -Include *.mkv | ForEach { echo ">>> Getting file: $_"; Set-ItemProperty $_ -name IsReadOnly -value $false | & 'C:\Program Files (x86)\MKVToolNix\mkvpropedit.exe' --tags all:'' --delete title --edit track:v1 --set language=$lang --edit track:a1 --set language=$lang "$_" } | |
} | |
function to-mkv([string]$lang="eng") { | |
Get-ChildItem -Path "." -Name -Recurse -File -Include *.avi,*.mp4 | ForEach { echo ">>> Getting file: $_"; $_ -match '(?<filename>.*)[.]'; $output = $matches["filename"] + ".mkv"; Set-ItemProperty $_ -name IsReadOnly -value $false | & 'C:\Program Files (x86)\MKVToolNix\mkvmerge.exe' -o $output --default-language $lang "$_" }; mkv-set-language $lang; | |
} |
Any chance to make it so it only changes the language on files that report back as "und"?
Hello, thx for this PS, if possible help me with how get func change track name. Thank you
Here is the script if you want to do the same thing but leverage the Handbrake CLI. Open Powershell as Administrator then run the script with PowerShell.exe -ExecutionPolicy Bypass -File C:\Users\Username\Documents\WindowsPowerShell\Microsoft.PowerShell_HandBrake_profile.ps1
`$sourcePath = "C:\Video-File-Directory"
$handbrakePath = "C:\Program Files\Handbrake\tools\HandBrakeCLI.exe"
$videofiles = Get-ChildItem $sourcePath -Filter *.mp4 -Recurse
$filecount = $videofiles.Count
$i = 0
ForEach ($file in $videofiles) {
$i++
$origfile = $file.FullName
$newfile = $file.DirectoryName + "" + $file.BaseName + ".mkv"
$progress = ($i / $filecount) * 100
$progress = [Math]::Round($progress, 2)
Clear-Host
Write-Host "-------------------------------------------------------------------------------"
Write-Host "Handbrake Batch Encoding"
Write-Host "Processing - $origfile"
Write-Host "File $i of $filecount - $progress%"
Write-Host "-------------------------------------------------------------------------------"
$args = "-i `"$origfile`" -t 1 -o `"$newfile`" -f mkv -O --decomb -e x264 -q 22 --pfr -a 1 -E av_aac -B 160 -R Auto --x264-preset=fast --x264-profile=main --h264-level=`"4.0`" --verbose=0"
Start-Process $handbrakePath -ArgumentList $args -Wait -NoNewWindow
}`
Functions that collect recursively all videos in a folder to set them to mkv with a new language (default track (first track) only)
PLEX
Use it for your PLEX server too, so all your tv shows and movies will have more data
Requirements
Set the script file
notepad $PROFILE
, then copy paste the content and save.Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
to enable custom scriptFunctions
Run this one to set only the language for your .mkv files

mkv-set-language
mkv-set-language eng
(english: eng (default), spanish: spa, german: ger, fre: french, ...)Run this one to copy and convert your .avi and .mp4 to .mkv and then set the default language:

to-mkv
to-mkv eng
Before using it
Change in the functions the paths related to mkvtoolnix tools to yours
Warnings
Troubleshoothing
could not be opened for reading: open file error.
that means the function failed to switch thereadonly
property tofalse
you will have to run the terminal as an administrator or make the change yourself before running the functionKnow which plex files that don't have the language set yet
Feel free to edit the functions as you wish