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 family

  • moov - contains movie-level metadata, track definitions, timing information, and sample tables

  • mdat - contains the encoded media payload

  • trak - describes an individual track, such as one video stream or one audio stream

  • mdia - contains media information for a track

  • stbl - contains sample tables that map decode time, composition time, sample size, keyframes, and byte offsets

  • moof / 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

MP4 Demuxing

MP4 Parameters