Format:ISO base media file format
| Developer | ISO/IEC MPEG (QuickTime format by Apple) |
|---|---|
| Magic | xx xx xx xx 66 74 79 70 (box type "ftyp" at offset 4) |
| Extensions | .mp4, .m4a, .m4v, .mov, .3gp, .heic, .m4s |
| Endianness | big |
| On this wiki | Facts · Code · Notes · Topics |
The box-based container behind MP4, M4A/M4V, 3GP, QuickTime MOV, fragmented MP4 (DASH/CMAF) and HEIF (ISO/IEC 14496-12): every box is a 32-bit big-endian size plus a four-character type, a file starts with ftyp, and the tracks live in moov/trak/mdia/minf/stbl with the codec named in stsd.
Box structure
Everything is a box: u32 size (big endian, includes the 8-byte header), char[4] type, then the payload. Size 1 means a 64-bit largesize follows the type; size 0 means the box runs to the end of the file; type uuid is followed by a 16-byte extended type. A "full box" starts its payload with u8 version and u24 flags. Container boxes simply hold child boxes, so a parser is a recursive walk. Atoms of the older QuickTime format have the same header, which is why MOV and MP4 share most code (FFmpeg: libavformat/mov.c, isom.h).
File layout
ftyp: major brand (4 bytes), minor version (u32), then a list of compatible brands. Common brands:isom,iso2,mp41,mp42,M4A,M4V,qt(QuickTime),3gp4,avc1,dash,cmfc,heic/mif1(HEIF). The brand tells the family, not the codec.moov: movie metadata.mvhd(timescale, duration), then onetrakper track:tkhd(id, size),mdia>mdhd(track timescale, language),hdlr(handler typevide,soun,text,subt,meta),minf>stbl.stbl(sample table):stsd(sample descriptions: the sample entry type is the codec FourCC, e.g.avc1/hvc1/av01video,mp4a/Opus/fLaC/ac-3audio, each followed by a codec config box such asavcC,hvcC,esds,dOps),stts(decode times),ctts(composition offsets),stsc(samples per chunk),stsz/stz2(sample sizes),stco/co64(chunk offsets, 32 or 64 bit),stss(sync samples).mdat: the media bytes; a sample's position comes from stco + stsc + stsz, not from any marker inside mdat.moovcan sit before or aftermdat("fast start" moves it to the front); a file withmdatand nomoovis truncated.free/skip/wide: padding.- Fragmented MP4: an init segment (
ftyp+moovwithmvex/trex) followed bymoof(mfhd,traf>tfhd,tfdt,trun) +mdatpairs, optionally indexed bysidx. - Metadata:
udta>meta>ilst(iTunes tags such as©nam).
Encryption boxes (recognition only)
A protected track is recognisable without any key: the sample entry type becomes encv (video) or enca (audio) and contains a sinf (protection scheme information) box with frma (the original codec FourCC), schm (scheme type: cenc, cens, cbc1, cbcs; scheme version) and schi > tenc (default IV size, default key id). Fragments carry senc, saiz/saio and the moov/moof may hold pssh (DRM system id plus opaque data). Seeing these boxes tells you the media is DRM-protected common encryption; this wiki does not document decryption. Older iTunes files use drms in sinf; the same applies.
The pssh box layout (read in FFmpeg mov.c, mov_read_pssh): version u8, flags u24, system id (16 bytes), for version above 0 a u32 key id count and the 16-byte key ids, then a u32 data size and the opaque data. The system id identifies the DRM system; the commonly published ids (identifiers only) are Widevine edef8ba9-79d6-4ace-a3c8-27dcd51d21ed, PlayReady 9a04f079-9840-4286-ab92-e65be0885f95 and the W3C Common system 1077efec-c0b2-4d02-ace3-3c1e52e2fb4b. Unverified: those three ids are quoted from memory of the DASH-IF/W3C registries, not read in the FFmpeg source.
Reversing notes
- To list tracks: walk moov > trak > mdia > hdlr and stsd; to dump a sample, compute its offset from stsc/stco/stsz.
- Unverified: games rarely ship MP4 directly; video appears as MP4/H.264 on mobile and as WebM or proprietary containers elsewhere.
- Offsets in stco are absolute file offsets, so moving moov changes them (the reason ffmpeg's faststart rewrites stco).
Code & repositories
See Library:FFmpeg (libavformat/mov.c, isom.h) and the linked repositories on this page.
- https://github.com/FFmpeg/FFmpeg @
7045cc9b8020ebaae156f4947baa752625056f90· license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
FFmpeg libavformat demuxers: riff.c (wFormatTag and FourCC tables), wavdec.c, avidec.c/avi.h, matroska.h (element ids), id3v2.h, isom.h/mov.c.
Tested on: source read, not run: Read riff.c tag table, wavdec.c probe, avi.h, matroska.h and id3v2.h at this commit (sparse checkout). Not built. · checked 2026-10-18