An MP4 file is built from the ISO base media file format, ISO/IEC 14496-12, which ISO sells and this reference could not read. Layouts on these pages come from memory of the standard and from public implementations, with the box names checked against the MP4 Registration Authority; treat the byte offsets as a guide. All numbers are big-endian.
Box header
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | uint32 | size | Total size of the box, including this header. 1 means a 64-bit size follows the type; 0 means the box runs to the end of the file. |
| 4 | 4 | FourCC | type | The box type. uuid means a 16-byte extended type follows. |
| 8 | 8 | uint64 | largesize | Present when size is 1. |
| … | 16 | UUID | usertype | Present when type is uuid. |
A full box adds a one-byte version and a 3-byte
flags after the header. Most boxes that have fields are full boxes.
ftyp
The file type box comes first in the file. A segment instead starts with styp,
which has the same layout.
| Offset | Size | Name | Meaning |
|---|---|---|---|
| 0 | 4 | major_brand | The brand the file is best read as. |
| 4 | 4 | minor_version | Version of the major brand, informative. |
| 8 | 4 × n | compatible_brands | Brands the file conforms to, to the end of the box. |
Other top-level boxes
| Box | Meaning |
|---|---|
mdat | Media data: the encoded samples. Its contents are found through the sample tables, not by reading the box itself. |
free, skip | Free space, ignored. |
uuid | A box whose type is its 16-byte UUID. |
pdin | Progressive download information. |
moof, mfra, styp, sidx, ssix, prft, emsg | See Fragments. |
meta | Timed and static metadata; a full box holding hdlr and item boxes. |
The box tree
ftypfile typemoovmoviemvhdmovie headertrakone per tracktkhdtrack headeredtswithelst, the edit listtreftrack referencesmdiamediamdhdmedia headerhdlrhandlerminfmedia informationvmhd,smhd,hmhd,nmhdmedia header by kinddinfwithdref, data referencesstblsample tables
mvexpresent when the file is fragmentedudtauser data
mdatthe media