Try DVDFab Video Downloader and rip Netflix video! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!

# BATCH remove audio track from mkv

1. Hi,
I've got a lot of mkv-Files from which I want to remove an audio track. Is there a program that allows to batch remove those?

I know I can load every single file in a program an remove them by clicking through 2-4 options, but with that amount of files that just isnt an option.
2. Tried MKVcleaver ?
3. If understood the program right, I can batch extract tracks from mkvs with that tool. But I want to delete a track from the mkv - can I do this with the program as well (Source: 2 audio tracks - after batch: 1 audio track, rest the same)? Couldnt find the option for that myself...
4. You are right...it's probably only extracting.
5. I'm unsure of the exact syntax you'd use, but you could probably do it with ffmpeg or mkvmerge batch file . Maybe one of the programming gurus will pop in and give you the commands
6. Yes, ffmpeg will do the job.

This is the command for video and first audio track:-
Code:
ffmpeg -i input.mkv -map 0:0 -map 0:1 -vcodec copy -acodec copy output.mkv
This is the command for video and second audio track:-
Code:
ffmpeg -i input.mkv -map 0:0 -map 0:2 -vcodec copy -acodec copy output.mkv
So you could try your hand at writing a bash script (or whatever the equivalent is for Windows and Mac).

It's also very simple to design a pre-set for a GUI such as WinFF.
7. Thanks bat, I tried adding a profile in winff, using these parameters: "-map 0:0 -map 0:2 -vcodec copy -acodec copy"
This gives me the error message: "Number of stream maps must match number of output streams". I've never used ffmpeg on the command-parameter side and don't really know what that means I've tried searching for the error message, but the answers only confuse me more.
Can someone give me a heads up what this means in my case?
8. Hi
Please use MediaInfo to show me what's inside one of those mkv files.

Basically it's just 1 video, 2 audio and 2 subtitle streams. I only need the video and the second (english) audio stream.

Code:
General
Format                           : Matroska
File size                        : 796 MiB
Duration                         : 21mn 8s
Overall bit rate                 : 5 266 Kbps
Encoded date                     : UTC 2010-03-12 01:22:19
Writing application              : mkvmerge v3.2.0 ('Beginnings') gebaut am Feb 12 2010 16:46:17
Writing library                  : libebml v0.7.9 + libmatroska v0.8.1

Video
ID                               : 1
Format                           : AVC
Format profile                   : High@L3.1
Format settings, CABAC           : No
Format settings, ReFrames        : 2 frames
Muxing mode                      : Container profile=Unknown@3.1
Codec ID                         : V_MPEG4/ISO/AVC
Duration                         : 21mn 8s
Bit rate                         : 4 329 Kbps
Width                            : 1 280 pixels
Height                           : 720 pixels
Display aspect ratio             : 16:9
Frame rate                       : 25.000 fps
Color space                      : YUV
Chroma subsampling               : 4:2:0
Bit depth                        : 8 bits
Scan type                        : Progressive
Bits/(Pixel*Frame)               : 0.188
Stream size                      : 654 MiB (82%)
Title                            :
Language                         : German
Color primaries                  : BT.709-5, BT.1361, IEC 61966-2-4, SMPTE RP177
Transfer characteristics         : BT.709-5, BT.1361
Matrix coefficients              : BT.709-5, BT.1361, IEC 61966-2-4 709, SMPTE RP177

Audio #1
ID                               : 2
Format                           : AC-3
Format/Info                      : Audio Coding 3
Mode extension                   : CM (complete main)
Codec ID                         : A_AC3
Duration                         : 21mn 8s
Bit rate mode                    : Constant
Bit rate                         : 448 Kbps
Channel(s)                       : 6 channels
Channel positions                : Front: L C R, Side: L R, LFE
Sampling rate                    : 48.0 KHz
Bit depth                        : 16 bits
Stream size                      : 67.7 MiB (9%)
Title                            : German AC3@448kbps
Language                         : German

Audio #2
ID                               : 3
Format                           : AC-3
Format/Info                      : Audio Coding 3
Mode extension                   : CM (complete main)
Codec ID                         : A_AC3
Duration                         : 21mn 8s
Bit rate mode                    : Constant
Bit rate                         : 384 Kbps
Channel(s)                       : 6 channels
Channel positions                : Front: L C R, Side: L R, LFE
Sampling rate                    : 48.0 KHz
Bit depth                        : 16 bits
Stream size                      : 58.1 MiB (7%)
Title                            : Englisch AC3@384kbps
Language                         : English

Text #1
ID                               : 4
Format                           : UTF-8
Codec ID                         : S_TEXT/UTF8
Codec ID/Info                    : UTF-8 Plain Text
Language                         : German

Text #2
ID                               : 5
Format                           : UTF-8
Codec ID                         : S_TEXT/UTF8
Codec ID/Info                    : UTF-8 Plain Text
Language                         : English
10. Hi
I can't see any problems with that printout.
You want the video and the English soundtrack.

Here's what to do.

Shut down WinFF.
Look among the WinFF files for a file named presets.xml
Open it with a text editor.
Then save it as presets_old.xml
(That's your backup if things go pearshaped).

Now we add an extra preset to the file.
Look at the file, you see the top 2 lines probably look something like this :-
Code:
<?xml version=\\\\\\\\\\\\\\\\\\\\\"1.0\\\\\\\\\\\\\\\\\\\\\"?>
<presets>
Now you need to paste some text straight underneath it.

This is the text:-

Code:
  <mkv2>
<label>mkv Video and second audio</label>
<params>-map 0:0 -map 0:2 -vcodec copy -acodec copy</params>
<extension>mkv</extension>
<category>Special</category>
</mkv2>
So when you've finished the top will look something like this (with all the original presets underneath)
Code:
<?xml version=\\\\\\\\\\\\\\\\\\\\\"1.0\\\\\\\\\\\\\\\\\\\\\"?>
<presets>
<mkv2>
<label>mkv Video and second audio</label>
<params>-map 0:0 -map 0:2 -vcodec copy -acodec copy</params>
<extension>mkv</extension>
<category>Special</category>
</mkv2>
Now save the file.
Then start WinFF.
You should see a new category named 'Special'.
And a preset named 'mkv Video and second audio'.

If everything looks OK, test it with one mkv file before you try to do the whole batch

EDIT
It's just occurred to me.
You might need to use the parameter -sn to prevent the subtitles from being copied.
So in the text that I gave you above, look at the line:-
Code:
<params>-map 0:0 -map 0:2 -vcodec copy -acodec copy</params>
and change it to:-
Code:
<params>-map 0:0 -map 0:2 -vcodec copy -acodec copy -sn</params>
Then save the file again.

Thanks bat, I tried adding a profile in winff, using these parameters: "-map 0:0 -map 0:2 -vcodec copy -acodec copy"
This gives me the error message: "Number of stream maps must match number of output streams".
Probably that profile will work OK if you use -sn!
"-map 0:0 -map 0:2 -vcodec copy -acodec copy -sn"
11. Strange - the preset entered in the xml does not appear in winff...
I edited the string of my preset I entered in WinFF and tried running ffmpeg directly in the command prompt, both times I get the following error: "[NULL @ 0x36462c0]error, non monotone timestamps 80 >= 40
av_interleaved_write_frame(): Error while opening file"
12. OK
If the modified presets file isn't working then go back to using your original presets file.

"[NULL @ 0x36462c0]error, non monotone timestamps 80 >= 40
av_interleaved_write_frame(): Error while opening file"
I don't know what's causing this error.
I'm out of ideas and I haven't got a similar file to experiment with.
13. bat999, thank you for your time and help.
I finally found a way to get the job done via mkvtoolnix / mkvmerge, as described here:
http://superuser.com/questions/77504/how-to-strip-audio-streams-from-an-mkv-file
Now I only need to find a way to get "batch" into that whole thing... But that shouldnt be too hard
14. From the information in your link I think the command to try first is this:-
Code:
mkvmerge -o output.mkv --vtracks 1 --atracks 3 input.mkv
15. Actually, this worked just fine:
Code:
mkvmerge -o output.mkv --atracks 3 input.mkv
Now, can someone help me with putting this to "batch"-use? I basically want to apply this to all files in a folder with all output files going into a different folder, but I don't know how to give mkvmerge all the filenames at once without merging them all into one or typing them all in one by one.
16. My scripting is rusty, but here's an attempt.

First make yourself a new_folder in your home directory to hold the new files.

Then 'change directory' to the folder where your mkv files are.
Something like this:-
cd Videos
Then paste this command:-
for i in *mkv; do mkvmerge -o ~/new_folder/basename "$i" mkv.mkv --atracks 3 "$i" ; done
Do a dummy run first with a few duplicate files in a temporary folder.
17. Thanks bat! I didnt know the Windows Commandline had batch capabilites

from your master, I worked the following batch-line out:
for %i in (*) do "path\to\mkvmerge.exe" -o new_folder/"%i" --atracks 3 --no-subtitles "%i"
Thanks again, without you help I probably would have either killed the whole project or done it all by hand
U R the command line guru now.
19. Trial and error, that is
Wonderful how you have helped, can't help repeating it. Thanks!
20. Hello bat999 and MarquisdeOz,

I've been trying to do *exactly* what's described here, remove unwanted audio tracks from MKV's to reduce the size considerably.
But I guess I am missing a part of the conversation because I can't get the batch command to work.

I put 'for %i in (*) do "path\to\mkvmerge.exe" -o new_folder/"%i" --atracks 3 --no-subtitles "%i" ' in a .bat file and run it with the files in the same dir and get no result (no good one anyway).
Am I missing something?
21. Try doing it directly in the command line (run "cmd.exe") - you'll get feedback what might have gone wrong there
22. I know this is an old thread, but I thought I should post for people like me who may stumble across this thread in their search.

Originally Posted by tijgert
I put 'for %i in (*) do "path\to\mkvmerge.exe" -o new_folder/"%i" --atracks 3 --no-subtitles "%i" ' in a .bat file and run it with the files in the same dir and get no result (no good one anyway).
Am I missing something?
When using batch commands in a batch file rather than directly at the command prompt, you need to specify variables with %% rather than just %. Also using (*) would process all the files in the directory INCLUDING the batch file itself, which obviously isn't an .mkv video. So a .bat friendly version would look something like this:

Code:
for %%i in (*.mkv) do mkvmerge -o new_folder/"%%i" --atracks 3 --no-subtitles "%%i"
This would work, however it is not a very good idea to use that as a batch file because "--atracks 3" and "--no-subtitles" are only really useful for those specific files. If you wanted to remove a different audio track or keep a sub track, then you would have to change the .bat file every time, and you might as well just run the command from a prompt.

Here is the .bat file I have been using to batch remove audio and sub streams from my .mkvs. It automatically creates a directory for output files and allows you to choose which tracks to keep. Just drop it into a directory of videos and run it. Please feel free to use it if anybody finds it helpful, and if anybody has problems with it, let me know (I haven't come across any yet, but my use cases are pretty limited).

https://dl.dropbox.com/u/96883351/mkvstrip.bat
23. Thanks Patrick!
24. Since posting that, I actually have come across a problem with specifying multiple track IDs (which apparently, I've never actually had to do before). I forgot that commas are considered white space and therefore must be enclosed in quotation marks, but if you type those manually then the quotation marks are passed on to mkvmerge, which may also cause problems.

At least that is what I'm guessing the problem is. I'm kind of busy lately, but I might get around to fixing this if it is a problem for people. Otherwise, it is still perfectly usable for removing single tracks at a time.
25. Originally Posted by PatrickEM
Since posting that, I actually have come across a problem with specifying multiple track IDs (which apparently, I've never actually had to do before). I forgot that commas are considered white space and therefore must be enclosed in quotation marks, but if you type those manually then the quotation marks are passed on to mkvmerge, which may also cause problems.

At least that is what I'm guessing the problem is. I'm kind of busy lately, but I might get around to fixing this if it is a problem for people. Otherwise, it is still perfectly usable for removing single tracks at a time.
Thanks for posting your batch file PatrickEM.

Do you know if it will work for a series of mkvs with 4 audio tracks and 3 subtitle tracks which need to be stripped down to 1 audio track and 1 sub track?

Does the whitespace issue you mentioned cause a problem in this type of situation?
26. Originally Posted by jmcr

Do you know if it will work for a series of mkvs with 4 audio tracks and 3 subtitle tracks which need to be stripped down to 1 audio track and 1 sub track?

Does the whitespace issue you mentioned cause a problem in this type of situation?

Sorry for making you wait. That should work just fine. It would only cause an issue if you wanted to keep more than one audio or sub track. As long as you only specify one of each to keep, the issue won't effect you.
27. Much appreciated Patrick!
This was *exactly* what I wanted over two years ago.. (jees! two years? What patience I have ) and I'm now SO easily removing the excess audio tracks of all seasons of BSG and other series (TV hoarder).

What a time and frustration saver! (and space too).

Still, I did try to keep two subtitle tracks at first and indeed that didn't work. No real biggy, but IF it should be fixable.. I wouldn't mind.
28. You're very welcome.

Yes, the problem most likely can be fixed, but it probably won't be fixed by me. I've since switched to Mac, so I've left .bat files behind. Maybe I'll check it out later in Parallels, but I haven't thought about this in a while. If anybody else knows the solution, please post it, because it's not a priority of mine and I hate to leave people hanging.
29. That extra subtitle track is just nice to have and has zero priority.
What's a little handier, and dare is day has any importance, is a destination drive query.

Now it asks me nicely what audio track and subtitle track I want to keep, but it outputs it in the same dir and grinds my drive down to dust (and it's slow). It'd be great if it could ask me what station (e.g. K: ) I would like to write it to, possibly with no input as default to the same dir.

Being a batch-nincompoop I'd need someones help, or at least hints to do this...

Is this something you could perhaps do by heart Mr.Patrick Sir?
30. As I haven't used batch files nor command-line mkvmerge in a while, I don't know off the top of my head. I can't even recall what switches are used to specify output directory at the moment. I'll check it out later, but I just woke up. It's 6AM here.

Statistics