MPEG-4 Part 14 / MP4 Container¶
Overview¶
MP4, formally MPEG-4 Part 14, is a digital media container format standardized as ISO/IEC 14496-14. It is based on the ISO Base Media File Format (ISO/IEC 14496-12), the same structural foundation used by related formats such as QuickTime File Format, 3GP, and fragmented MP4.
MP4 is one of the most widely used formats for storing and delivering audio/video content across desktop, mobile, broadcast, and web platforms. It is commonly used for local files, progressive download, adaptive streaming packaging, camera recordings, and distribution workflows.
MP4 is a container, not a codec. The container controls how streams are packaged, indexed, timed, and synchronized; the codec controls how each audio or video stream is compressed.
Container Structure¶
MP4 files are organized as nested boxes, also called atoms. Each box has a type and size, and may contain media data, metadata, timing tables, or child boxes.
Important MP4 boxes include:
ftyp- identifies the file type, compatible brands, and format familymoov- contains movie-level metadata, track definitions, timing information, and sample tablesmdat- contains the encoded media payloadtrak- describes an individual track, such as one video stream or one audio streammdia- contains media information for a trackstbl- contains sample tables that map decode time, composition time, sample size, keyframes, and byte offsetsmoof/traf- used by fragmented MP4 to describe media fragments
For normal playback, the demuxer uses the metadata in moov and trak boxes to locate compressed samples in mdat, recover timestamps, identify keyframes, and feed each compressed stream to the appropriate decoder.
Common Streams¶
MP4 commonly stores:
Video - AVC / H.264, HEVC / H.265, MPEG-4 Visual, and other ISO BMFF-compatible video streams
Audio - AAC, ALAC, MP3, AC-3, and other supported audio formats
Timed metadata - subtitles, chapters, captions, and auxiliary metadata tracks depending on the workflow
H.264 and H.265 streams in MP4 are usually stored in length-prefixed form rather than Annex B start-code form. Codec initialization data such as SPS/PPS for AVC or VPS/SPS/PPS for HEVC is stored in container metadata, commonly in codec configuration boxes such as avcC or hvcC.
Muxing and Demuxing¶
Muxing creates an MP4 file by writing encoded media samples, timestamps, track metadata, codec configuration records, and sample tables into the container. The muxer is responsible for producing a valid file structure that players can seek, synchronize, and decode.
Demuxing reads an MP4 file, parses the box structure, selects tracks, and extracts compressed stream samples. Demuxing does not inherently decode audio or video; it separates the streams and preserves their compressed form unless the workflow also includes decoding or transcoding.
Key features of MP4 include:
Broad compatibility - Supported by common operating systems, browsers, mobile devices, and media players
Audio/video synchronization - Stores timing and track information for synchronized playback
Streaming support - Can be structured for progressive download and adaptive streaming workflows
Codec flexibility - Commonly used with H.264/AVC, H.265/HEVC, AAC, and other compressed streams
Seekable structure - Sample tables allow players and editing tools to locate frames and keyframes efficiently
AVBlocks provides support for MP4 container workflows, allowing you to:
Mux encoded audio and video streams into an MP4 file
Demux streams from an MP4 file into separate output files
Re-encode streams while preserving a container-based processing workflow
MP4 Muxing¶
Mux Audio and Video Into MP4 - Mux AAC audio and H.264 video into an MP4 file using Transcoder::run
MP4 Demuxing¶
Demux Audio and Video From MP4 - Extract the first audio and video streams from an MP4 file using Transcoder::run
MP4 Parameters¶
MP4 Muxer Parameters - Configure MP4 muxer behavior with AVBlocks muxer parameters