[Matroska-devel] Tagging MKV files

Moritz Bunkus moritz at bunkus.org
Sat Sep 1 18:18:47 CEST 2012


Hey,

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 problem.
> 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,
mosu


More information about the Matroska-devel mailing list