Ah ok, first cup of coffee is on me, just for your willingness to want to help at all (at 6 freaking AM)
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 31 to 54 of 54
Thread
-
-
Hey, I know this is an ancient thread, but I thought I would go ahead and post. I have found PatrickEM's script extremely useful, aside from the issue with trying to keep multiple (but not all) audio or subs tracks. Anyways, I recently found a solution after quite a bit of fussing, and it turns out it was pretty simple. While enclosing a comma in quotes is ineffective, I found that enclosing the full string of track numbers and commas with quotes seems to work. So for instance, instead of 3,4 or 3","4 try "3,4". So far it is working well for me. I reworked the script to allow for keeping all subtitle tracks as well as removing all (originally there was only the option to keep one or remove all, which limited its usefulness for me). I also reworded the onscreen prompts a bit.
Here's my updated version:
https://www.dropbox.com/s/9p1r7xv0govl8y7/mkvstrip.bat?dl=0
Thanks for the original script, PatrickEM!Last edited by Surlias; 22nd Oct 2014 at 23:56.
-
-
THIS is exactly what i was googling for! thank you! (My mkv files folder has a structure 4 audio tracks, of which i need only the 4th one - so i changed the 0:2 to 0:4)
Only one small thing - i need the subtitles to remain - how do i do this? i tried with and without the -sn but it always removes the subs!
P.S.
Is it possible to also, while removing batch tracks, to convert the remaining tracks from DTS to AC3?
I can do it later via Popcorn converter, but would be convenient if this could be done all at the same timeLast edited by assburger; 11th Mar 2015 at 18:41.
God is a superstition; religion is poison. -
hi @ll
after downloading and playing around with 64bit edition of https://www.videohelp.com/software/MKVtoolnix i wanted it to be done more automatic
!!!!!!!!!!!!!!!!!!!!!!!!!! Thx !!!!!!!!!!!!!!!!!!!!!!
to PatrickEM and Surlias
i only changed 2 things
1st path to mkvmerge.exe
since i didn't want to change my windows path variable to include the c:\Program Files\MKVToolNix\ directory or copy the exe around... i just hard coded it into the .BAT
2nd the Output directory
... since i have more than one HDD i want to used the performance gain of reading from one and writing the new files to another HDD thus rendering the automatic output folder Creation useless .. hence the REM in front of it.. you could also delete these lines
what remains... is to copy the .bat to the Dir with the files u wanna edit
paste in editor and save and save as .bat file
Code:@echo off title MKVstrip cls set /p MM=This batch script will strip unwanted audio/subtitle tracks from ALL .mkv files in the directory it is run from. The changes will be made to copies of the files and the originals will remain untouched. For this reason, please make sure you have enough disk space for the output files. Continue? (Y/N): IF '%MM%' == 'Y' GOTO AS IF '%MM%' == 'y' GOTO AS IF '%MM%' == 'N' GOTO EN IF '%MM%' == 'n' GOTO EN :AS echo. set /p AT=Type the track ID(s) of the audio track(s) you would like to KEEP, seperated by commas. For multiple tracks, enclose the entire statement in quotes (to KEEP ALL type a, or to view track IDs type i): IF '%AT%' == 'i' GOTO ID IF '%AT%' == 'a' GOTO SSNA IF '%AT%' == 'A' GOTO SSNA :SS echo. set /p ST=Type the track ID(s) of the subtitle track(s) you would like to KEEP, seperated by commas. For multiple tracks, enclose the entire statement in quotes (if none are present or to REMOVE ALL then type n, or to keep all type a): IF '%ST%' == 'n' GOTO NS IF '%ST%' == 'N' GOTO NS IF '%ST%' == 'a' GOTO ASS IF '%ST%' == 'A' GOTO ASS :WS echo. rem md output for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -o d:/!temp/"%%i" --atracks "%AT%" --stracks "%ST%" "%%i" echo. Echo The process is complete. The stripped files are located in the "output" folder. pause exit :SSNA echo. set /p ST=Type the track ID(s) of the subtitle track(s) you would like to KEEP, seperated by commas. For multiple tracks, enclose the entire statement in quotes (if none are present or to REMOVE ALL then type n, or to keep all type a): IF '%ST%' == 'n' GOTO NANS IF '%ST%' == 'N' GOTO NANS IF '%ST%' == 'a' GOTO NASS IF '%ST%' == 'A' GOTO NASS :NA echo. rem md output for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -o d:/!temp/"%%i" --stracks "%ST%" "%%i" echo. Echo The process is complete. The stripped files are located in the "output" folder. pause exit :NANS echo. rem md output for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -o d:/!temp/"%%i" --no-subtitles "%%i" echo. Echo The process is complete. The stripped files are located in the "output" folder. pause exit :NS echo. rem md output for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -o d:/!temp/"%%i" --atracks "%AT%" --no-subtitles "%%i" echo. Echo The process is complete. The stripped files are located in the "output" folder. pause exit :ASS echo. rem md output for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -o d:/!temp/"%%i" --atracks "%AT%" "%%i" echo. Echo The process is complete. The stripped files are located in the "output" folder. pause exit :NASS echo. rem md output for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -o d:/!temp/"%%i" "%%i" echo. Echo The process is complete. The stripped files are located in the "output" folder. pause exit :ID echo. for %%i in (*.mkv) do "c:\Program Files\MKVToolNix\mkvmerge.exe" -i "%%i" echo. pause GOTO AS :EN exit
the only thing being more awesome .. would be for auto detection of the eng. audio track to be the one kept...
in the mkvtoolnix-gui.exe i see an info of the tracks respective language code, like "eng" but not in the command line -
THANK YOU!
Here it is, 2015. I found your .bat file and it was exactly what I was looking for!
With your .bat file, I was able to strip the Italian audio track 1 from 6 seasons of 'Lost'. Now I can play the .mkv's back-to-back without having to switch audio tracks each time a new episode starts. -
This thread saved my life. Thank you to all the contributors, especially PatrickEM for his bat.
Since i needed this for avi files i just edited it and changed all *.mkv to *.avi. Script attached.
You guys kick ass.Last edited by CardinalFang; 4th Aug 2015 at 04:25.
-
It's been a while. Amazing to see people still thanking me after all this time.
I'd like to apologize to anyone in this thread who was still waiting for me to respond (especially tijgert, really sorry man), but I no longer even own a valid Windows license, so further batch file tweaking was out of the question for me, and I have moved on to ffmpeg+AppleScript to fill these needs. Nice to see that other people stepped up to fill the empty space I so negligently left behind.
I should really get more active around here someday... -
Oh how I wish it worked for me. I put the mkv video in a folder together with the .bat file. I double-clicked on it and then it asked if i had enough space, i typed "Y" and pressed enter, then it asked me which audio stream i'd like to keep. When I type "i" and enter it tells me mkvmerge is not recognized as an internal or external command. I'm a complete dummy. Am I doing something wrong?
-
I know this is an old thread but,
I use the following command prompt entry to batch process files to eliminate unneeded audio files. I place all the files I want to convert in a folder then change the command prompt entry folder names - it works. The command, in this case, eliminates the unwanted audio track and assigns the remaining audio as 'eng' - it names the new file same as the original name with an added .mkv extension.
Example: Input file name - inputfile.avi Output file name becomes inputfile.avi.mkv.
My question is how do I change the command to output a file named inputfile.mkv (without the .avi included in the name). Currently I use a renaming program to delete the '.avi' in the output file name. Like I say it works okay, but I'm sure there is a way to alter the command prompt command to output the original file name without the .avi extension being included in output file name.
My procedure is as follows:
Open Command Prompt
change command prompt dir to input folder dir
change directory names in command line below then execute.
FOR /F "delims=*" %A IN ('dir /b *.avi') DO "C:/Program Files/MKVToolNix\mkvmerge.exe" ^"--ui-language^" ^"en^" ^"--output^" ^"D:/OutputFolder/%A.mkv^" ^"--audio-tracks^" ^"2^" ^"--language^" ^"0:und^" ^"--language^" ^"2:eng^" ( ^"D:/InputFolder/%A^" ) ^"--track-order^" ^"0:0,0:2^"
Rename the misnamed files.
What do I change the instances of %A to in the command (ie. ^"D:/OutputFolder/%A.mkv^) to get the original file name without the old extension included? -
Problem solved: Changed the command to:
FOR /F "delims=*" %I IN ('dir /b *.avi') DO "C:/Program Files/MKVToolNix\mkvmerge.exe" ^"--ui-language^" ^"en^" ^"--output^" ^"D:/OutputFolder/%~nI.mkv^" ^"--audio-tracks^" ^"2^" ^"--language^" ^"0:und^" ^"--language^" ^"2:eng^" ( ^"D:/InputFolder/%I^" ) ^"--track-order^" ^"0:0,0:2^"
With this change, the batch process runs properly, making the changes and outputing files with the original name (substituting an extension of .mkv without the old extension in the name).
NOTE: The ('dir /b *.avi') needs to be changed to the your input files extension.
For input files with .mkv extension it needs to be changed to ('dir /b *.mkv') .
************************************************** ********************
BTW: I got the main part of this command by opening MKVMerge, adding one of the files I wanted to change, made the changes to the track attachments (Unchecking the audio track I wanted to elliminate, changing the remaining audio track language to english) and then MENU - Merge -- Show command line --- copy to clipboard. Made changes (noted in the quote) in my text editor and pasted the changed command into the Command Prompt.
Example MKVMerge Command line:
"C:/Program Files/MKVToolNix\mkvmerge.exe" ^"--ui-language^" ^"en^" ^"--output^" ^"D:/InputFolder/Inputfile.S04E01.mkv^" ^"--audio-tracks^" ^"2^" ^"--language^" ^"0:und^" ^"--language^" ^"2:eng^" ( ^"D:/InputFolder/Inputfile.S04E01.avi^" ) ^"--track-order^" ^"0:0,0:2^"Last edited by noblemd; 16th Dec 2015 at 12:24.
-
I've used the following PowerShell script to remove the DTS-HD audio tracks from all my TV series BD-rips.
I wanted to keep audio track 2 (regular DTS) and subtitle track 3 from them all, so I just hard-coded that into the script. You can always alter the script to take arguments from command-line or in-script dialogues.
Code:$env:Path += ";C:\Program Files\MKVToolNix\" $files = Get-ChildItem -Include *.mkv -Name -Recurse | Sort-Object Foreach ($Item in $files) {mkvmerge -o new_folder/$Item --atracks 2 --stracks 3 $Item}
The second line scapes the current folder, and all subfolders, finds all .mkv files and adds them to a collection, sorted by name.
The third line processes the input-files, removing the DTS-HD track (audio track 1) and stores the new file in a folder names "new_folder". -
I will add to this old thread as others may end up here as I did, but still not find a workable solution.
Selecting the audio and video tracks by static numbers is a no go, as a few others have noted, I can't count on the order of the tracks (video before audio or one language before another) in the video file.
So I wrote a vbscript file that uses mkvmerge to identify the tracks and languages of interest, and then builds and executes the command to create a new mkv file with the desired tracks.
- The script can be executed by dragging and dropping video files on to the script.
- The source video file is renamed to filename.ext.tmp in the orginal folder.
- The new video file is named filename.mkv in the orginal folder.
- My video files are named in the format "title (year) [rating].mkv". The title and year are written to the track name fields.
- Optionally, auto deletion of the source video can be enabled by uncommenting the "Call DeleteSource" sub routine, once your confident that the script does what you want.
- I am selecting on english and undefined tracks, you can change to other language codes as needed.
- If at least one audio and one video track are not identified, the script stops processing that file and leaves it with a .tmp extension for manual examination.
"C:\path to your vbscript\ConvertToMKV.vbs" %*
Place the batch file in "C:\Users\Your Username\AppData\Roaming\Microsoft\Windows\SendTo"
Why the batch file? If you put the vbs script in "SendTo" and select multiple videos, they process in parallel (all at the same time, each running thier own copy of mkvmerge). If you use the batch file to call the vbs script, they run in serial (one at a time, only one mkvmerge instance in memory at a time).
So here is my script, I call ConvertToMKV.vbs
'Start of script
Option Explicit
Dim strInputFileName
Dim strBaseFileNameNoExt
Dim strTempFileName
Dim strOutputFileName
Dim MediaObjectList
Dim objArgs
Dim objFSo
Dim objShell
Dim strTitle
Dim strTitleChunks
Dim TrackSelection
Set objArgs = WScript.Arguments
Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
For Each strInputFileName in objArgs
Call GetBaseFileNameNoExt ' FQ FileName without extension
Call ParseTitle ' Filename without Path or Extension
Call GetTrackInfo ' Identify Desired Tracks
Call RenameInputFile ' Rename Input to .tmp in case input is already .mkv
Call SetOutputFileName ' FQ FileName with MKV extension
Call RemuxFile ' Remux
'Call DeleteSource ' Delete Source if Output Created
Next
Sub GetBaseFileNameNoExt
strBaseFileNameNoExt = Trim(Left(strInputFileName,InstrRev(strInputFileNa me,".")-1))
End Sub 'GetBaseFileNameNoExt
Sub RenameInputFile
strTempFileName = strInputFileName & ".tmp"
objFSO.MoveFile strInputFileName ,strTempFileName
End Sub 'RenameInputFile
Sub SetOutputFileName
strOutputFileName = strBaseFileNameNoExt & ".mkv"
End Sub 'SetOutputFileName
Sub ParseTitle
strTitleChunks = Split(strBaseFileNameNoExt,"\")
strTitle = strTitleChunks(UBound(strTitleChunks))
If Instr(strTitle,"[") Then strTitle = Trim(Left(strTitle,InstrRev(strTitle,"[")-1))
End Sub 'ParseTitle
Sub GetTrackInfo
Dim CommandLine
Dim MediaObject
Dim MediaObjects
Dim Track
Dim VideoTracks
Dim AudioTracks
Dim SubTracks
Dim TrackOrder
TrackSelection = ""
CommandLine = """" & GetMKVExecutable & """ "
CommandLine = CommandLine & "-i -F verbose-text "
CommandLine = CommandLine & """" & strInputFileName & """ "
Set MediaObjectList = objShell.Exec(CommandLine)
MediaObjects = Split(MediaObjectList.StdOut.ReadAll, vbCrLf)
For Each MediaObject In MediaObjects
Select Case Left(MediaObject,8)
Case "Track ID"
Track = Split(MediaObject," ",5)
Select Case Track(3)
Case "video"
TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
VideoTracks = VideoTracks & " " & Replace(Track(2),":","")
Case "audio"
If Instr(Track(4),"language:eng") Then
TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
AudioTracks = AudioTracks & " " & Replace(Track(2),":","")
ElseIf Instr(Track(4),"language") = 0 Then
TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
AudioTracks = AudioTracks & " " & Replace(Track(2),":","")
End If
Case "subtitles"
If Instr(Track(4),"language:eng") Then
TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
SubTracks = SubTracks & " " & Replace(Track(2),":","")
ElseIf Instr(Track(4),"language") = 0 Then
TrackSelection = TrackSelection & "--track-name """ & Track(2) & strTitle & """ "
SubTracks = SubTracks & " " & Replace(Track(2),":","")
End If
Case Else
'msgbox(Track(3))
'Not Processing other values at this time
End Select
Case Else
'Not Processing other values at this time
End Select
Next
If Len(SubTracks) > 0 Then
TrackSelection = "-s " & Replace(Trim(SubTracks)," ",",") & " " & TrackSelection
TrackOrder = Replace(RTrim(SubTracks)," "," 0:")
Else
TrackSelection = "-S " & TrackSelection
End If
If Len(AudioTracks) > 0 Then
TrackSelection = "-a " & Replace(Trim(AudioTracks)," ",",") & " " & TrackSelection
TrackOrder = Replace(RTrim(AudioTracks)," "," 0:") & TrackOrder
End If
If Len(VideoTracks) > 0 Then
TrackSelection = "-d " & Replace(Trim(VideoTracks)," ",",") & " " & TrackSelection
TrackOrder = Replace(RTrim(VideoTracks)," "," 0:") & TrackOrder
End If
TrackOrder = "--track-order " & Replace(Trim(TrackOrder)," ",",")
TrackSelection = TrackSelection & TrackOrder & " "
End Sub 'GetTrackInfo
Sub RemuxFile
Dim CommandLine
CommandLine = """" & GetMKVExecutable & """ "
CommandLine = CommandLine & "--title """ & strTitle & """ --no-global-tags --no-track-tags "
CommandLine = CommandLine & TrackSelection
CommandLine = CommandLine & "-o """ & strOutputFileName & """ "
CommandLine = CommandLine & """" & strTempFileName & """ "
If Instr(TrackSelection,"-d ") = 0 Then Exit Sub 'Video Track Not Identified
If Instr(TrackSelection,"-a ") = 0 Then Exit Sub 'Audio Track Not Identified
objShell.Run CommandLine,7,True
End Sub 'RemuxFile
Sub DeleteSource
If ValidFile(strOutputFileName) Then objFSO.DeleteFile strTempFileName
End Sub 'DeleteSource
Function GetMKVExecutable
If ValidFile("C:\Program Files\MKVToolNix\mkvmerge.exe") Then
GetMKVExecutable = "C:\Program Files\MKVToolNix\mkvmerge.exe"
ElseIf ValidFile("C:\Program Files (x86)\MKVToolNix\mkvmerge.exe") Then
GetMKVExecutable = "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe"
Else
GetMKVExecutable = NULL
msgbox("*** MKV Tools NOT Detected ***")
End If
End Function 'GetMKVExecutable
Function ValidFile(FileName)
Dim Outfile
ValidFile = False
If objFSO.FileExists(FileName) Then
Set Outfile = objFSO.GetFile(FileName)
If Outfile.size > 100 Then
ValidFile = True
End If
End If
End Function 'ValidFile
'End of script
I hope that this makes life easier for someone. -
Hi @High Plains Scripter and @PatrickEM...
Any chance of updating your scripts (I use both, love them!) to support MKVtoolnix v20? I've done a little digging and have determined...
They both work with v19 but since v20 they have dropped "-i -F verbose-text" from mkvmerge.exe as per:
http://ubuntuhandbook.org/index.php/2018/01/mkvtoolnix-20-0-0-released-with-mkvinfo-rewritten/
I believe the same functionality can be derived from mkvinfo.exe and/or using the command line argument "-i -F json" from mkvmerge.exe.
THANKS AGAIN, your scripts are so good I'm refusing to update to v20 (and all the associated bug fixes) of MKVtoolnix just so I can continue to use your scripts.Last edited by kurosh; 20th Jan 2018 at 06:31.
-
Try replacing all instances of mkvmerge.exe with mkvinfo.exe. If info takes the same params and produces the same output, it should work. Switching to JSON output will take substantial rewriting of GetTrackInfo.
Similar Threads
-
How do i remove an audio track from an AVI file?
By alih786 in forum AudioReplies: 51Last Post: 29th Nov 2016, 06:31 -
How to remove audio track?
By MAAG in forum AudioReplies: 13Last Post: 13th Jun 2012, 18:19 -
How to Remove subtitle track from .MKV ?
By Clifurd in forum SubtitleReplies: 2Last Post: 13th May 2011, 23:32 -
Batch remove audio/subs
By BVT in forum Newbie / General discussionsReplies: 3Last Post: 27th Jul 2008, 12:58 -
how can i remove wind noise from a audio track
By suomiaussie in forum AudioReplies: 2Last Post: 23rd Mar 2008, 09:10