Exacting Metadata #1832

ndjamena opened this Issue Dec 22, 2016 · 8 comments


None yet

2 participants

ndjamena commented Dec 22, 2016 edited

I'm trying to replace the mpeg2 video from a DVD rip with reprocessed h264 video.

I need to get the video from the x264 mkv file but take everything else from the original mkv.

If I list the x264 file on the command line first, the file muxes fine but I don't get the file "segment title" in the new file. Getting the "segment title" via cmd/batch and mkvmerge -I would be incredibly difficult without resorting to a third party application.

If I list the original MKV first I get the correct "segment title" but the audio is listed in the file before the video, which can be an eyesore to look at. If I use --trackorder 1:0 I get the video first but the video is still given a "track number" of 2 with the audio given the track number of 1. It is IMPOSSIBLE to change the track number using MKVPropEdit after the fact, so without remuxing again the file is stuck with the reverse "track numbers".

As far as I can tell there's no other way of setting which file to get the "segment title" value from, nor is there a way to set a tracks "track number" during muxing.

Is everything working as intended?

mbunkus commented Dec 22, 2016

You're mentioning several things. Most of them are working as expected, but probably not all of them.

A question about the files in question. Does the first file (the one with the video track) have a title set or not? Judging from what you've written it seems that it does not have one set. In that case this is a bug in mkvmerge which unconditionally uses the title from the first Matroska file listed, even if that file doesn't have a title. I'll fix that.

The track numbers are working as intended. The reason you cannot change them with mkvpropedit is that all blocks (BlockGroup and SimpelBlock elements) in the file use the same track numbers to signal which track they belong to. Therefore changing the track numbers in the headers would mess up those assignments.

The track numbers not being affected by the --track-order parameter may or may not be a bug. I'll have to check that code (which is rather more involved than the code dealing with the title).

@mbunkus mbunkus self-assigned this Dec 22, 2016

According to MKVInfo there's no "Segment Title" in the x264 files.

mbunkus commented Dec 22, 2016

About track numbers vs. --track-order: this is a bug. It only happens when you do not specify all tracks with --track-order.

The following example works as expected:

$ mkvmerge -o out.mkv h264-and-aac.avi mp3.mp3 --track-order 1:0,0:0,0:1
$ mkvinfo out.mkv | grep -Ei 'codec id|track number'
|  + Track number: 1 (track ID for mkvmerge & mkvextract: 0)
|  + Codec ID: A_MPEG/L3
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Codec ID: V_MPEG4/ISO/AVC
|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)
|  + Codec ID: A_AAC

This way track number 1 will be the MP3 track, track number 2 will be the h.264 track and track number 3 will be the AAC track.

However, all tracks that are not explicitly mentioned in the --track-order parameter can wreak havoc because they're being assigned track numbers which should rather be assigned to one of the tracks listed in --track-order. This is the bug. I'll fix this, too.


It's just a very simple batch file, which I only bothered writing because MKVToolNixGUI only allows a single default destination and I can't be bothered changing it every time I switch between projects.

Figuring out if there are extra subtitle tracks would make it far too complicated for me to bother with at this stage.

@mbunkus mbunkus added a commit that referenced this issue Dec 22, 2016
@mbunkus Matroska reader: only set title if title was present in source file
Otherwise a title set in a later file won't be used. Fixes part of #1832.
@mbunkus mbunkus added a commit that referenced this issue Dec 22, 2016
@mbunkus mkvmerge: assign track numbers for tracks in --track-order first
When the user specifies tracks with "--track-order a,b,c…", she expects
track a to be assigned track number 1, b to be assigned track number 2
and 3 for track c.

The old code did not guarantee this. Instead it might assign track ID 1
to a track not listed in "--track-order".

Fixes the second part of #1832.
@mbunkus mbunkus closed this Dec 22, 2016
mbunkus commented Dec 22, 2016

Pre-builds for Windows including the fixes are up.

mbunkus commented Dec 22, 2016

…and those pre-builds are buggy; I've removed them again. Will post new binaries later.

ndjamena commented Dec 22, 2016 edited

Just for fun:


Set "Title="

for /f "tokens=1,* delims= " %%g in ('mkvmerge -I "%~f1"') do if /I "%%~g"=="File" CALL :GetTitle %%h

if defined Title echo Title: %Title:*IAMABACKSLASH*=\%

goto :eof


	if "%~1"=="" goto :eof
	Set "Part=%~1"
	Set "Part=%Part:[=%"
	if NOT "%Part:~0,6%"=="title:" (
		goto :GetTitle
	Set "Part=%Part:~6%"
	Set "Part=%Part:]=%"
	Set "Part=%Part:\\=*IAMABACKSLASH*%"
	Set "Part=%Part:\s= %"
	Set "Part=%Part:\c=:%"
	Set "Part=%Part:\h=#%"
	Set "Part=%Part:\b=[%"
	Set "Part=%Part:\B=]%"
	Set "Title=%Part:\2=^"%"

goto :eof

Both methods seem to work now... should I be wary of the two files I've created using the pre?

mbunkus commented Dec 22, 2016

No, your two files are fine. The 64bit pre-build was generally fine, too, but the 32bit pre-build crashes due to a but in my compiler. So if mkvmerge is not crashing for you then you're good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment