[Matroska-devel] Tagging MKV files

Dan Hinsley danhi at cox.net
Sat Sep 1 19:47:48 CEST 2012

OK, just one more question (for now), the spec says that the offset is from
the FIRST level 1 element, which in the examples I'm looking at is the
seekhead, but is this always the case or do I need to keep track of the
first level 1 element no matter what it is?

I really appreciate your help in all this and I hope I'm not being too much
of a pain.


-----Original Message-----
From: matroska-devel-bounces at lists.matroska.org
[mailto:matroska-devel-bounces at lists.matroska.org] On Behalf Of Moritz
Sent: Saturday, September 01, 2012 9:19 AM
To: Discussion about the current and future development of Matroska
Subject: Re: [Matroska-devel] Tagging MKV files


On Sat, Sep 1, 2012 at 6:06 PM, Dan Hinsley <danhi at cox.net> wrote:

> Thanks for the quick feedback.  I suspect it's #3 that's causing my
> Just so I understand, is the SeekHead always contained in a Segment,

Yes. A segment is a so called "level 0 element" and a seek head a
"level 1 element" (like e.g. the track headers, the clusters or the
segment info elements which are all level 1 elements as well).

> and then all offsets are from the start of that segment?

More precisely: the "seek position" elements are relative to the start
of the _data_ inside the segment, not relative to the position of the
segment element itself. Example output from mkvinfo (limited to the
relevant pieces of information):

+ Segment, size 115780 at 40
|+ Seek head at 52
| + Seek entry at 72
|  + Seek ID: 0x16 0x54 0xae 0x6b (KaxTracks) at 75
|  + Seek position: 4257 at 82
|+ Segment tracks at 4309

The segment element itself is located at position 40. However, this is
not relevant to our discussion. The very first element inside the
segment is the "seek head" at 52. Therefore, judging from mkvinfo's
output, the data start is at 52. This IS relevant.(*)

Now that "seek entry"'s "seek position" child has a value of 4257.
Adding the 52 from step 1 yields 4309 -- which is exactly the position
the element referred to is located at.

(*) Note that the correct way to calculate the segment data start
position is NOT by taking the first child element's start position. I
only do that in this example because that's the only way to do it with
mkvinfo's output only. In a program, however, you can easily calculate
it as "segment element position" + "size in bytes of the segment
element's ID" (which is 4) + "size in bytes of the segment length
field" (which is usually between 1 and 8 bytes). mkvmerge always
creates 8 bytes long "length" fields for the "segment" element,
therefore this calculation would yield 40 + 4 + 8 = 52 -- which is the
very same as the "seek head" element's position. Check OK.

Kind regards,
Matroska-devel mailing list
Matroska-devel at lists.matroska.org
Read Matroska-Devel on GMane:

More information about the Matroska-devel mailing list