I have a folder of MKVs with audio tracks I don’t need. To remove them all at once without needing to reencode every file, we can use the mkvmerge tool from MKVToolnix. This is done in two steps:
Determine which tracks you want to keep
Use mkvinfo to list all tracks and their IDs so you’ll know which you want to keep:
1 | mkvinfo -g your_file.mkv |
You’ll need a list of track IDs you want to keep.
In the event that some of your MKVs have a different number of tracks to others, you’ll want to do something like the following:
1 | for f in *.mkv; do echo "$f" && mkvinfo "$f" | grep "mkvextract: 10"; done |
The above will find all MKVs with 10 tracks. In my case I grouped all the MKVs with 10, 8 and 7 tracks into individual folders then performed the below step on each folder.
Remove the tracks from each file
Use the following command to create a copy with a v2 suffix of each MKV. This is a safe way to ensure your changes are correct without deleting the original files.
1 | for f in *.mkv; do mkvmerge -o "${f%.mkv} v2.mkv" -a 0,1,2,9,10 "$f"; done |
That’s it! When you’re done, delete your original files and remove the v2 suffix from your new ones.