Introduction
MP4 is the most widely used video file. It is a container: it holds video, audio and subtitle tracks together, with the timing needed to play them in step. The video inside is usually H.264, H.265 or AV1 and the audio usually AAC, but the container itself does not decide the codec.
The format is defined by ISO/IEC 14496-14. It is built on the ISO base media file
format (ISO/IEC 14496-12), which grew out of Apple’s QuickTime format. The same
structure underlies .m4v video, .m4a audio, .mov
and the HEIF and AVIF image formats.
Structure
An MP4 file is a sequence of boxes, also called atoms. Each box starts with a 32-bit big-endian size and a four-letter type, and many boxes contain further boxes. A size of 1 means a 64-bit size follows the type, and a size of 0 means the box runs to the end of the file.
Three boxes sit at the top level of every file; see
Box structure. ftyp names
the brands the file conforms to.
moov holds the description of
the whole movie: one trak per track, each with
sample tables that give the size, time
and file position of every frame. mdat holds the encoded frames themselves.
A file with moov before mdat can start playing before it has
fully downloaded. A fragmented MP4, used
for streaming, repeats moof and mdat pairs, each describing a
few seconds of media. The registered
box types and
sample entries have their own
pages.
0ftyp major brand, version, compatible brandsvaries…moov the movie descriptionvaries…mvhd timescale and duration of the movievaries…trak one per track: header, media info and sample tablesrepeated
…mdat the encoded audio and video samplesvaries
Not described
Known, not yet covered
- Reference: the field layouts of the boxes that only ISO/IEC 14496-12 defines (
tfhd,trun,tfdt,sidx,sbgp,sgpd,stz2,tfra,mfro,trex,mehd,emsg) come from memory of the standard and of common implementations, because the standard was not opened. The pages say so. - Viewer: an MP4 viewer plugin exists on the site, but this pass did not audit which of the boxes above it names and decodes.
Not described
ISO/IEC 14496-12 is a paid standard and the free copy could not be fetched. The pages follow the MP4 Registration Authority's lists, Apple's QuickTime pages, the 3GPP specification and what files made and read by FFmpeg show. The viewer (drop a file on any page) reads every box it has a layout for, field by field, and shows the rest as “registered box” (named by the registry, bytes shown whole) or “unknown box” (type and size), then carries on.
Known, not yet covered
- Reference: the byte layouts of the ISO-only boxes on
Movie and track boxes,
Sample tables,
Fragments,
Metadata and items and
Encryption boxes are from memory of the
standard. The viewer reads every box of the files FFmpeg writes with these layouts and
leaves no byte over, but a layout that FFmpeg never writes (a second SPS list in
avcC, theseiggroup,sencsub-samples) has not been checked against any file. - Reference and viewer: the registry's boxes for OMAF, V3C, JPEG 2000, JPEG XL, JPEG XS, OMA DRM, DECE, the ISO partial-file boxes, SVC, MVC and 3D video, the audio element boxes and the Dynamic Range Control boxes. They are named (see Box types) and shown as registered boxes; their fields are not laid out.
- Reference and viewer: sample group entries other than
roll,prol,rap,sync,teleandseig: the viewer shows their bytes under the grouping type's name. - Viewer: pictures. The video codec is named, its configuration
(
avcC,hvcC,av1C,vpcC, the H.264 sequence parameter set) is read, and the NAL units or OBUs of every sample are listed. Only H.264 (avc1,avc3) is decoded: the Video tab draws four pictures of a track (the first sync sample and three more; interlaced tracks too) and says why for a track it cannot decode; no HEVC, AV1, VP8, VP9 or MPEG-4 Part 2 frame is decoded. - Viewer: sound in AMR-WB+, EVRC, QCELP, SMV, EVS, AC-4, MPEG-H, DTS
Express (
dtse), DTS:X, MLP, IAMF, G.719, DRA, USAC (xHE-AAC), QDesign, and QuickTime's GSM and IMA ADPCM: no decoder is wired in, and the Sound tab says so. DTS indtsc,dtshanddtslentries, and inmp4aentries of object type 0xA9, 0xAA and 0xAB, is decoded (the core and its extensions, including the lossless layer of DTS-HD Master Audio; theddtsbox is read). Sound in Opus is trimmed by its pre-skip, not by the edit list. - Viewer: HEIF and AVIF item data: the items, their types,
locations and properties are listed, but a
gridoriovldescription, an Exif block and the coded images are not decoded. - Viewer: encrypted samples (no key exists in the file) and the
data inside
psshboxes. - Viewer: compressed boxes (
!mov,!mof,brob) are not expanded.
Unknown
- Reference and viewer: any box type that is in neither the registry nor a specification here (vendor extensions without a published layout). The viewer marks each “unknown box” with its type, size and place, lists them in the File tab and keeps their bytes whole.
Links
Software
- VLC media player – free media player that plays MP4 files (Windows, macOS, Linux, mobile)
- mpv – free, minimal media player (Windows, macOS, Linux)
- HandBrake – free video converter that writes MP4 (Windows, macOS, Linux)
- FFmpeg – command-line tools that read, write and convert MP4 (Windows, macOS, Linux)
- Adobe Premiere Pro – Adobe’s video editor, which imports and exports MP4 (Windows, macOS)
- DaVinci Resolve – video editor and colour grading app that reads and renders MP4 (Windows, macOS, Linux)
- Shotcut – free, open-source video editor (Windows, macOS, Linux)
- Kdenlive – free, open-source video editor from KDE (Windows, macOS, Linux)
- GPAC and MP4Box – tools that inspect, build and fragment MP4 files (Windows, macOS, Linux)
- Bento4 – command-line tools that inspect and package MP4 files (Windows, macOS, Linux)
Developers
- libavformat – FFmpeg’s container library, which reads and writes MP4 (C)
- mp4box.js – reads and writes MP4 boxes in the browser (JavaScript)
- Bento4 – library behind the Bento4 tools, for reading and writing MP4 (C++)
Reference
- MP4 Registration Authority – the registered box types, brands and codec codes
- QuickTime File Format – Apple’s specification of the format MP4 grew from