Each track of a movie is a trak atom inside moov. Offsets below
count from the start of the atom, so data starts at offset 8.
trak
A container that must hold a track header and a media atom.
| Child | Meaning |
|---|---|
prfl | Track profile. Deprecated; older files only. |
tkhd | Track header. Required. |
tapt | Track aperture mode dimensions. |
clip | Track clipping region; same layout as the movie’s. |
matt | Track matte. |
edts | Edit atom holding the edit list. |
tref | Track references. |
txas | Exclude from autoselection. |
load | Track load settings. |
imap | Track input map. |
mdia | Media. Required; see Media atoms. |
udta | User data for this track; see udta. |
meta | Track-level metadata. |
tkhd
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 8 | 1 | uint8 | version | 0. |
| 9 | 3 | bits | flags | See below. |
| 12 | 4 | uint32 | creation time | Seconds since 1 January 1904, preferably UTC. |
| 16 | 4 | uint32 | modification time | Same format. |
| 20 | 4 | uint32 | track ID | Unique in the movie; never 0. |
| 24 | 4 | – | reserved | 0. |
| 28 | 4 | uint32 | duration | In the movie’s time scale: the sum of the edit durations, or of the sample durations when there is no edit list. |
| 32 | 8 | – | reserved | 0. |
| 40 | 2 | int16 | layer | Lower layers are drawn in front of higher ones. |
| 42 | 2 | int16 | alternate group | Tracks with the same non-zero value are alternatives (for example the same audio in several languages); the player picks one. 0 means no group. |
| 44 | 2 | 8.8 fixed | volume | 1.0 is normal. |
| 46 | 2 | – | reserved | 0. |
| 48 | 36 | matrix | matrix structure | The track’s display matrix; see Matrices. |
| 84 | 4 | 16.16 fixed | track width | In pixels. |
| 88 | 4 | 16.16 fixed | track height | In pixels. |
| Flag | Name | Meaning |
|---|---|---|
| 0x0001 | Track enabled | The track is enabled. |
| 0x0002 | Track in movie | The track is used in the movie. |
| 0x0004 | Track in preview | The track is used in the preview. |
| 0x0008 | Track in poster | The track is used in the poster. |
The atom is 92 bytes. As with mvhd, Apple documents only version 0; an
ISO-style version 1 widens the two times and the duration to 64 bits (104 bytes).
tapt: aperture modes
Gives the track size for each way of showing the picture. Without it, the
tkhd size is used for all of them. It holds three atoms of the same layout:
| Atom | Mode | Dimensions |
|---|---|---|
clef | Clean | Both the clean aperture and the pixel aspect ratio applied: the intended display size. |
prof | Production | Pixel aspect ratio applied, clean aperture not, so edge pixels show. |
enof | Encoded pixels | The encoded pixels as they are, no scaling. |
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 8 | 1 | version | 0. |
| 9 | 3 | flags | 0. |
| 12 | 4 | width | 16.16 fixed, in pixels. |
| 16 | 4 | height | 16.16 fixed, in pixels. |
The fourth mode, classic, scales the decoded picture to the tkhd size and
ignores both corrections; it is what players before QuickTime 7 do.
matt and kmat
A track matte blends the track’s image with what lies behind it. matt holds
one compressed matte atom, kmat:
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 8 | 1 | version | 0. |
| 9 | 3 | flags | 0. |
| 12 | varies | matte image description | An image description in the video sample description layout, saying how the matte is coded. |
| … | varies | matte data | The compressed matte image. |
edts and elst
edts holds the edit list, elst, which maps movie time to media
time. Without one, the whole media plays from the start of the movie.
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 8 | 1 | version | 0. |
| 9 | 3 | flags | 0. |
| 12 | 4 | number of entries | Entries that follow. |
| 16 | 12 × n | edit list table | One entry per edit segment, below. |
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 0 | 4 | track duration | Length of this segment, in the movie’s time scale. |
| 4 | 4 | media time | Start of the segment in the media, in the media’s time scale. −1 means an empty edit (nothing plays), used to delay the track. The last edit should not be empty. |
| 8 | 4 | media rate | 16.16 fixed play rate for the segment; never 0 or negative. |
Any gap between the track’s end and the movie’s duration is an implicit empty edit. An ISO-style version 1 entry has 64-bit duration and media time (20 bytes per entry).
load
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 8 | 4 | preload start time | Start, in movie time, of a part of the track to load into memory before playing. |
| 12 | 4 | preload duration | Its length; −1 means to the end of the track. |
| 16 | 4 | preload flags | 1 preload always; 2 preload only if the track is enabled. The two are exclusive. |
| 20 | 4 | default hints | Bit flags: 0x0020 double-buffered I/O; 0x0100 highest quality regardless of real-time performance. |
tref: track references
tref holds one atom per reference type. Each holds an array of uint32 track
IDs to the end of the atom, so the count is (size − 8) ÷ 4. A track ID of 0 is allowed
and means no reference. References point from the track that uses the data to the track
that supplies it.
| Type | Meaning |
|---|---|
cdsc | From a timed metadata track to the tracks it describes. Absent when the metadata describes the whole movie. |
chap | Chapter or scene list, usually a text track. |
clcp | The closed caption track for this track. |
fall | In a sound track: a track with the same content in another format (for example AC-3 to AAC). |
folw | In a sound track: the subtitle track to use by default (the forced track of a pair), when language tags cannot say it. |
forc | In the regular track of a subtitle pair: the forced subtitle track. |
hint | In a hint track: the tracks holding the original media. |
scpt | Transcript, usually a text track. |
ssrc | Non-primary source: the referenced track sends its data to this track, which uses it to change how it presents (see imap). |
sync | The two tracks are synchronised, usually video and sound. May go either way or both. |
tmcd | Time code, usually a timecode track. |
cdep | Structural dependency (registered with the MP4 Registration Authority for QuickTime). |
txas
An 8-byte atom with no data, placed after tkhd. It tells the player not to
pick this track automatically, for alternates such as commentary that are not a
translation of the main content. Such tracks should carry readable tnam
names.
imap: track input map
Says how to interpret data sent to this track by the tracks it references with
ssrc. Unlike most atoms, imap holds QT atoms (see
QT atoms): one track input atom per
input, type in (0x0000696E).
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 0 | 4 | size | Size of the track input atom. |
| 4 | 4 | type | in. |
| 8 | 4 | atom ID | Unique among the track input atoms. |
| 12 | 2 | reserved | 0. |
| 14 | 2 | child count | 1 or 2. |
| 16 | 4 | reserved | 0. |
| 20 | 12 | input type atom | Required: ty (0x00007479) with a uint32 input type. |
| 32 | 12 | object ID atom | Optional: obid with a uint32 object ID, when the input acts on an object such as one sprite. |
Apple gives the input type and object ID atoms as 12 bytes each, which matches a plain 8-byte header and a uint32; written as full QT atoms with the 20-byte QT header they would be 24 bytes. Read their size fields rather than assume either.
| Input type | Name | Data received |
|---|---|---|
| 1 | kTrackModifierTypeMatrix | A 3 × 3 matrix moving or scaling the track. |
| 2 | kTrackModifierTypeClip | A QuickDraw clipping region changing the track’s shape. |
| 3 | kTrackModifierTypeVolume | An 8.8 fixed relative volume, for fades. |
| 4 | kTrackModifierTypeBalance | A 16-bit balance level, for panning. |
| 5 | kTrackModifierTypeGraphicsMode | A graphics mode (int32) and an RGB colour, for visual fades. |
| 6 | kTrackModifierObjectMatrix | A 3 × 3 matrix for an object within the track. |
| 7 | kTrackModifierObjectGraphicsMode | A graphics mode and RGB colour for an object within the track. |
vide | kTrackModifierTypeImage | Compressed image data for an object within the track (formerly kTrackModifierTypeSpriteImage). |