Log in

View Full Version : mkv concatenate and chapters


SamLowry
10th February 2009, 19:12
Hi
I want to concatenate several video clips in one single matroska file/segment.
At the same time I want to generate chapters based on the clip files I concatenate, so, every chapter corresponds to one single clip with a video frame precision.

In mkv, chapters are based on timecodes with milliseconds (or even nanoseconds) precision. The problem is that I can’t figure out what exact duration a clip will have being part of a mkv, thus can’t figure out what exact offset a clip will get being n-th part of the concatenation.

My clips are h.264/avc video and AAC audio in a MP4 container. Before concatenating them in a MKV by issuing:
mkvmerge –o new.mkv clip1.mp4 +clip2.mp4 … +clipN.mp4
I try to acquire the exact duration of each clip by using mp4box:
mp4box –info clipI.mp4


mp4box reports three durations – for audio stream based on audio sample rate and number of audio samples, for video stream based on fps (25 in my case) and number of frames and an “overall” movie duration. These three durations differ. For example I get results like:
Movie duration: 00:01:11.380
Video duration: 00:01:11.320 (1783 frames, 25fps)
Audio duration: 00:01:11.381 (3346 samples, 48K SampleRate)

I want to predict the exact time offset the first frame of a clip will get in the resulting mkv, so I can generate a proper chapters file that would be merged with mkvmerge. In a chapter I don’t want to refer timecode “near by” the start of a clip but exactly the first frame (the beginning of the first GOP).

Please, advice.