Mkvmerge vs ffmpeg concat demuxer

I have some footage of episodes from a show, with each episode in its own MKV file.

I would like to append each of these episodes to another MKV (an opening for the show), so that in the end I will have an MKV for each episode that has this other MKV “prepended” to it.

The opening MKV had to have its video stream re-encoded from MPEG-2 to H.264. I was able to match the stream settings to the episodes’ stream settings enough to make it mkvmerge-able with the episode footage (also H.264).

The problem I’m having is that the resulting MKV (opening + episode) suffers considerable de-coloration in the episode’s footage (see below, left).

I’ve read around on the internet about mkvmerge, and people have said that it doesn’t do any re-encoding of the video stream. I’m inclined to believe this given how quickly it completes, but it definitely appears to be doing something.

One other “video concatenation” solution I’ve tried is using ffmpeg’s concat demuxer. This method produces the footage I want (ie, w/o the discoloration above), but it has its own downsides (like stripping away all of the chapter metadata).

What I’m mostly interested in is how the mkvmerge and ffmpeg solutions differ in their processing of the video files to produce these different results. I’m no expert in any of this, so I’m sure there’s a lot I’m missing, but conceptually it seems like they should both just copy the video stream, and only ffmpeg appears to be doing that.

Some other experimentation I’ve done:

  • Instead of appending the episode to the opening, I tried appending the opening to the episode just to see if that would make a difference in color, and it did. The color in the episode footage is restored to what it should be (of course, the problem with this is that the opening now plays after the show ends!).
  • I ran the episode footage through a bitstream filter per the answer here, thinking that the episode’s “stream configuration” (for lack of a better term) is being supplanted by that of the opening. This significantly improved the color in the episode, but it’s still not perfect.

Thank you!

I looked at this case a little more, and I noticed that, similar to how appending the episode to the opening changes the colors in the episode footage, so too does appending the opening to the episode footage change the colors in the opening. It seems like the resultant MKV uses the “color information” from the first video stream in the sequence for all streams.

This gave me an idea: if I could split out this “color-corrected” opening and use that as the opening that I prepend to all the episodes, then maybe the colors will be retained in the episodes since their color information will match. I tried this out, and it works! The colors are no longer washed out in the episode footage when I append to this new opening.

So, in summary, what I did was:

  1. Re-encoded the original opening footage from MPEG-2 to H.264 using highly-similar codec settings to the episode footage, such that the opening and the episodes could be appended to each other with no display artifacts
  2. Appended the re-encoded opening to the episode footage, and then split this opening from the resultant MKV to obtain a “color-corrected” opening
  3. Used this “color-corrected” opening as the opening to prepend to the episode footage

I’m not sure what I would need to do to manually ensure this color information is the same between the tracks, but I guess I don’t need to, since mkvmerge will do it for me as long as I order the tracks properly.

I still don’t know what’s going on under the hood, but I’m happy with this solution, as it lets me continue to use mkvmerge, which will make it much easier to batch these merges while retaining chapter metadata :smile: