Using --track-tags

#3598
Hello, I don’t quite understand what mkvmerge does when using --track-tags.
From documentation:
–track-tags [!]n,m,…
Copy the tags for tracks n, m etc. The numbers are track IDs which can be obtained with the --identify switch (see section track IDs). They’re not simply the track numbers. Default: copy tags for all tracks.

If the IDs are prefixed with ! then the meaning is reversed: copy everything but the IDs listed after the !.
Below is the text of the command line and the result of the program execution.

mkvmerge.exe --identify --ui-language en 1.mkv
File ‘C:\1.mkv’: container: Matroska
Track ID 0: video (AVC/H.264/MPEG-4p10)
Track ID 1: audio (AC-3)
Track ID 2: audio (AC-3)
Track ID 3: subtitles (SubRip/SRT)
Track ID 4: subtitles (SubRip/SRT)

mkvmerge.exe -o C:\2.mkv --track-tags 0,1 C:\1.mkv
mkvmerge v76.0 (‘Celebration’) 64-bit
‘C:\1.mkv’: Using the demultiplexer for the format ‘Matroska’.
‘C:\1.mkv’ track 0: Using the output module for the format ‘AVC/H.264’.
‘C:\1.mkv’ track 1: Using the output module for the format ‘AC-3’.
‘C:\1.mkv’ track 2: Using the output module for the format ‘AC-3’.
‘C:\1.mkv’ track 3: Using the output module for the format ‘text subtitles’.
‘C:\1.mkv’ track 4: Using the output module for the format ‘text subtitles’.
The file ‘C:\2.mkv’ has been opened for writing.
The cue entries (the index) are being written…
Multiplexing took 1 second.
–track-tags [!]n,m,…

My Question is why are all tracks copied and not just 0 and 1?

BTW I tried :
C:\mkvmerge.exe -o C:\2.mkv --no-track-tags C:\1.mkv
mkvmerge v76.0 (‘Celebration’) 64-bit
‘C:\1.mkv’: Using the demultiplexer for the format ‘Matroska’.
‘C:\1.mkv’ track 0: Using the output module for the format ‘AVC/H.264’.
‘C:\1.mkv’ track 1: Using the output module for the format ‘AC-3’.
‘C:\1.mkv’ track 2: Using the output module for the format ‘AC-3’.
‘C:\1.mkv’ track 3: Using the output module for the format ‘text subtitles’.
‘C:\1.mkv’ track 4: Using the output module for the format ‘text subtitles’.
The file ‘C:\2.mkv’ has been opened for writing.
The cue entries (the index) are being written…

Is that how it’s supposed to be?
And if so, how to correctly write the command line so that only tracks 1 and 2 are copied?

Welcome!

The option --track-tags only applies to tags that are attached to certain tracks. It doesn’t affect whether or not tracks themselves are copied. For the latter use the options --audio-tracks, --video-tracks, --subtitle-tracks or their shortcuts -a, -d, -s. See also --no-<type> (e.g. --no-audio) for completely preventing tracks of certain categories to be copied.

Thanks, it’s clear now. But this is extremely inconvenient. When writing scripts, if you need to copy certain tracks. I search for the track title and copy it.
Then it’s easier to use FFMEG/

With the help of mkvmerge’s JSON identification mode (mkvmerge --identification-mode json --identify yourfile.ext or its shortcut, mkvmerge -J yourfile.ext) which tells you exactly what’s inside a file including the IDs of all tracks you can fully automate your mkvmerge-based workflow. But sure, you can also use ffmpeg. Use whatever suits your needs best.