Jump to content

Windows script to remove non [insert your preferred languages] tracks


ginjaninja

Recommended Posts

ginjaninja

Removes eg. Audio and Subtitle Tracks from selected (in Explorer) MKVs which do not match your preferred language(s)

ignores files which do not contain at least 1 audio track with any one of your preferred languages

ignores files which do not contain  audio tracks other than your preferred languages

instances a wait state to prevent multiple mkvmerges running at same time to prevent a disk bottleneck (not spindle aware)

Halts processing if Mkvmerge errors or temp processing file not found. (to protect deleting original file if an issue)

Test with extreme caution. This script deletes processed files

 

Installation

copy script/reg to filesystem.

set your preferred languages in the script

Edit .reg with path to your script and run .reg to import.

Right-click one or more mkvs and choose "KeepLanguage".

Changes

v0.0.0.7 corrects some behaviour when path contains special characters

Keeplanguage v0.0.0.7.zip

 

 

image.png.d751fb774b198a170e41537afdc33062.png
 

Edited by ginjaninja
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
Eigeplackter
On 12/19/2021 at 11:30 AM, ginjaninja said:

Removes eg. Audio and Subtitle Tracks from selected (in Explorer) MKVs which do not match your preferred language(s)

ignores files which do not contain at least 1 audio track with any one of your preferred languages

ignores files which do not contain  audio tracks other than your preferred languages

instances a wait state to prevent multiple mkvmerges running at same time to prevent a disk bottleneck (not spindle aware)

Halts processing if Mkvmerge errors or temp processing file not found. (to protect deleting original file if an issue)

Test with extreme caution. This script deletes processed files

 

Installation

copy script/reg to filesystem.

set your preferred languages in the script

Edit .reg with path to your script and run .reg to import.

Right-click one or more mkvs and choose "KeepLanguage".

Keeplanguage v0.0.0.3.zip 1.71 kB · 6 downloads

 

image.png.d751fb774b198a170e41537afdc33062.png
older batch version

  Reveal hidden contents

 

copy script to "shell:sendto"

 

Test with extreme caution. This script deletes processed files

Use with extreme caution. If the MKV does not contain tracks of your language you will end up with no tracks.

tested on MKVMerge v63

@echo off
REM Dont run on non backed up files prior to extensive testing in your environment, script contains very little error protection!!!!
REM Explanation of ~dpn1, https://stackoverflow.com/questions/5034076/what-does-dp0-mean-and-how-does-it-work/5034119#5034119
REM To keep English and French eg Audio
REM -a "eng,fre"
REM From https://forum.videohelp.com/threads/343271-BULK-remove-non-English-tracks-from-MKV-container/page2#post2538112
REM for other langyage codes https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
REM place script in shell:sendto
REM Right Click one or more MKVs and send to this script.
REM of course tracks in mkv must be tagged with language.
REM the script loops through the one or more files sent by Windows explorer
:Loop

echo Removing Tracks %1
REM Tweak command line to your preference of language and track type
ECHO **********************************
"C:\Program Files\MKVToolNix\mkvmerge.exe" --output "%~dpn1.MUX" -a "eng" -s "eng" "%~1"

if %ERRORLEVEL% EQU 0 CALL del "%~1"
if %ERRORLEVEL% EQU 0 CALL ren "%~dpn1.MUX" "%~n1.mkv"
shift
if not [%1]==[] goto :Loop

 

 

 

*Removes the dust*

Script needs adaption, need to replace pwsh.exe with powershell.exe (Win10 64-bit)

And I need some help, if possible, I get the following output, after I changed lines #6 and #7

#mylanguages=@("ger")
$mylanguages = @("ger")

Quote

mkvfile is M:\Test Library\The King's Man - The Beginning\The King's Man 720p.mkv

id type  codec               Language
-- ----  -----               --------
 0 video AVC/H.264/MPEG-4p10 eng
 1 audio AC-3                ger
 2 audio E-AC-3              eng


Nothing to process

 

Link to comment
Share on other sites

ginjaninja
18 hours ago, Eigeplackter said:

*Removes the dust*

Script needs adaption, need to replace pwsh.exe with powershell.exe (Win10 64-bit)

And I need some help, if possible, I get the following output, after I changed lines #6 and #7

#mylanguages=@("ger")
$mylanguages = @("ger")

 

if you can pm a link to a test file i can check.

you can install pwsh https://github.com/PowerShell/PowerShell/releases/download/v7.3.1/PowerShell-7.3.1-win-x64.msi

cant be sure if anything in the script needs pwsh  or not...

 

 

Link to comment
Share on other sites

  • 4 months later...
Seger

Just discovered your script and I am happy, it is much faster via Powershell than my old .bat file. Thank you!

I have 2 concerns/questions. Can you add a variable so that the subtitles can be separated from the main language?

#1

So audio e.g. "ger

Subtitle "ger" & "eng" 

#2

Is it also possible to right-click on a series folder and the script then dedicates itself to all MKVs in this folder? That way you don't have to select individual MKVs.

Is there actually a log?

Thank you very much!!!

Seger

 

Link to comment
Share on other sites

ginjaninja

#1 happy to help you edit the functionality of the script, am guessing if you can write batch you can follow google and write powershell?

to get you started

$mylanguages = @("eng")

$myaudiotracks = $audiotracks | Where-Object { $_.properties.language -in $mylanguages }
$mysubtitletracks = $subtitletracks | Where-Object { $_.properties.language -in $mylanguages }

$mylanguages = ($mylanguages -join ", ")

modify to

$mylanguages = @("eng")
$mysubtitlelanguages=@("eng","ger")

$myaudiotracks = $audiotracks | Where-Object { $_.properties.language -in $mylanguages }
$mysubtitletracks = $subtitletracks | Where-Object { $_.properties.language -in $mysubtitlelanguages }

$mylanguages = ($mylanguages -join ", ")
$mysubtitlelanguages = ($mysubtitlelanguages -join ", ")

the challenge might be what logic you drive from establishing these variables...probably going to involve tweaking the main condition to suit.

if (($myaudiotracks.count -ge 1 -and $myaudiotracks.count -lt $audiotracks.count) -or ($mysubtitletracks.count -ge 1 -and $mysubtitletracks.count -lt $subtitletracks.count -and $subtitleforce)) {

#2

tweaking the script to operate on a folder is not trivial

the registry file will need to be tweaked to associate the shell command to a folder and the script will need to implement some logic to determine if the passed argument is a file or a folder (unless you maintain a separate folder and file script). and 'if folder' enumerate (see get-item/get-childitem) the contents and act. Alot of busy work / google searching wouldnt attempt this until after #1.

theres no log...

 

give it a go and pm me if you need help.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...