To remove specific audio tracks, add new ones, and include extra subtitles, you can achieve this using mkvmerge. Here’s how:
Step 1: Identify the Current Tracks
Use mkvmerge to list the tracks in the original file:
mkvmerge -i input.mkv
Note the track IDs of:
- The audio tracks you want to keep.
- The audio tracks you want to remove.
- The new audio and subtitle files you want to add.
Step 2: Remove Unwanted Audio Tracks
Use the --audio-tracks option to specify the audio tracks you want to keep (e.g., Track ID 1 is English):
mkvmerge -o temp.mkv --audio-tracks 0,1 input.mkv
Here:
0is the video track.1is the English audio track.- This excludes unwanted tracks like
Track ID 2 (French),Track ID 3 (Spanish), andTrack ID 4 (German).
Step 3: Add New Audio and Subtitle Files
Use the --track-name and --language options to add the new tracks and label them. For example, if you have:
- An audio track in Japanese (
japanese.aac). - Subtitles in Japanese (
japanese.srt).
Run:
mkvmerge -o output.mkv temp.mkv \
--language 0:jpn --track-name 0:"Japanese Audio" japanese.aac \
--language 0:jpn --track-name 0:"Japanese Subtitles" japanese.srt
Explanation of the Options:
--language 0:jpn: Sets the language of the new track to Japanese (jpnis the ISO 639-2 language code).--track-name 0:"Japanese Audio": Names the new audio track “Japanese Audio”.--track-name 0:"Japanese Subtitles": Names the new subtitle track “Japanese Subtitles”.temp.mkv: The intermediate file from which unnecessary tracks were removed.output.mkv: The final MKV file with the changes applied.
Step 4: Verify the Output
Check the resulting file to confirm it includes the correct tracks:
mkvmerge -i output.mkv
Example: One-Liner Command
If you want to do everything in one step (remove, keep, and add tracks), you can chain the options:
mkvmerge -o output.mkv \
--video-tracks 0 --audio-tracks 1 --subtitle-tracks 5 \
input.mkv \
--language 0:jpn --track-name 0:"Japanese Audio" japanese.aac \
--language 0:jpn --track-name 0:"Japanese Subtitles" japanese.srt
Here:
--video-tracks 0: Keeps the video track.--audio-tracks 1: Keeps the English audio track.--subtitle-tracks 5: Keeps a specific subtitle track from the original file.- The new audio and subtitle tracks are added as part of the same command.