MP4 Container Format: The Universal Video Standard
MP4 (MPEG-4 Part 14) is the world's most widely supported video container format. Since its standardization in 2001, it has become the default format for internet video, mobile devices, streaming platforms, and consumer cameras. Understanding MP4's internal architecture explains why it delivers such broad compatibility while maintaining excellent quality.
The MPEG-4 Family and ISO Base Media File Format
MP4 is formally specified as MPEG-4 Part 14 (ISO/IEC 14496-14), a direct extension of the ISO Base Media File Format (ISOBMFF, ISO/IEC 14496-12). This shared lineage means MP4 is structurally identical to MOV (QuickTime), M4V, M4A, and 3GP — they differ mainly in the four-byte brand identifier stored in the ftyp box.
The ISOBMFF specification defines a hierarchical "box" (or "atom") structure:
[ftyp] File Type Box — identifies the brand and compatible brands
[moov] Movie Box — container for all metadata
[mvhd] Movie Header — duration, timescale, creation date
[trak] Track Box (video)
[tkhd] Track Header
[mdia] Media Box
[mdhd] Media Header — language, timescale
[hdlr] Handler Reference — 'vide' for video
[minf] Media Information
[stbl] Sample Table — indexes every frame: size, offset, timing
[trak] Track Box (audio)
[udta] User Data — metadata (title, artist, GPS, etc.)
[mdat] Media Data Box — raw compressed frame data
The critical insight: all playback metadata lives in moov, while actual encoded data lives in mdat. For streaming, moov must appear before mdat — this is the "fast start" or "web optimize" requirement. Tools accomplish this with qt-faststart or ffmpeg -movflags +faststart.
Supported Codecs
MP4's container is codec-agnostic. Common combinations:
| Track | Common Codecs | Notes |
|---|---|---|
| Video | H.264 (AVC), H.265 (HEVC), AV1, MPEG-4 Part 2, VP9 | H.264 universally supported; AV1 growing |
| Audio | AAC, MP3, AC-3, E-AC-3, Opus, ALAC | AAC is the standard; AC-3 for Dolby |
| Subtitles | 3GPP Timed Text (tx3g), WebVTT, MPEG-4 Timed Text | tx3g native; SRT not natively supported |
| Data | MPEG-4 BIFS, MPEG-4 OD | Scene description (rarely used) |
The most universal combination for web delivery is H.264 + AAC — every browser, device, and media player supports this pair without additional codecs.
Fragmented MP4 (fMP4) and Streaming
Traditional MP4 requires the complete file before playback begins. Fragmented MP4 restructures the file into independent segments, enabling:
- MPEG-DASH: adaptive bitrate streaming using
.mpdmanifests +.mp4segments - HLS (RFC 8216 bis): Apple's HTTP Live Streaming with native fMP4 support (replacing MPEG-TS segments)
- CMAF: Common Media Application Format — a unified fMP4 profile for both DASH and HLS
A fragmented MP4 looks like:
[ftyp] — brand: 'iso5' or 'dash'
[moov] — initialization segment (no sample data, just codec config)
[styp] — segment type
[moof] — movie fragment header (timing + offsets for this segment)
[mdat] — data for this fragment only
[moof][mdat]... — repeated for each segment
This architecture means a 2-hour video can be served as thousands of 2-second fragments, each independently decodable. CDNs cache individual segments, and players switch quality levels between fragments.
The moov Fast-Start Problem
When moov appears at the end of the file (the default for many encoders), a browser must download the entire file before it can begin parsing metadata and start playback. This is the most common cause of MP4 streaming delays.
Detection: ffprobe -v quiet -show_format input.mp4 | grep start_time — a large start_time indicates moov is at the end.
Fix with ffmpeg:
ffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4
This moves moov to the front without re-encoding. The -c copy flag ensures stream copy (no quality loss, near-instant for large files).
Encoding MP4 with H.264 — Practical ffmpeg Commands
Web delivery (broad compatibility):
ffmpeg -i input.mp4 \
-c:v libx264 -crf 23 -preset slow \
-profile:v high -level 4.1 \
-c:a aac -b:a 128k \
-movflags +faststart \
output.mp4
4K HDR with HEVC:
ffmpeg -i input.mp4 \
-c:v libx265 -crf 22 -preset medium \
-x265-params hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc \
-c:a aac -b:a 192k \
-movflags +faststart \
output_4k_hdr.mp4
Hardware-accelerated encoding (NVIDIA NVENC):
ffmpeg -i input.mp4 \
-c:v h264_nvenc -rc vbr -cq 23 \
-b:v 0 -maxrate 8M -bufsize 16M \
-profile:v high \
-c:a aac -b:a 128k \
-movflags +faststart \
output_nvenc.mp4
CRF Quality Reference (libx264)
| CRF | Quality | Typical Use |
|---|---|---|
| 18 | Near lossless | Archival, mastering |
| 20–22 | Very high | High-quality streaming |
| 23 | Default | Good balance quality/size |
| 26–28 | Acceptable | Social media, mobile |
| 32+ | Low | Thumbnails, previews |
MP4 vs. MKV vs. MOV vs. WebM
| Feature | MP4 | MKV | MOV | WebM |
|---|---|---|---|---|
| Browser support | Universal | Limited (needs codec) | Safari-native | Chrome/Firefox |
| Codec flexibility | High | Highest | High | VP8/VP9/AV1 only |
| Chapter support | Limited (udta) | Full | Limited | Basic |
| Streaming (fMP4) | Yes (CMAF/DASH) | No native | No | Yes |
| HDR metadata | Yes (HDR10, HLG) | Yes (all formats) | Yes | Yes (VP9/AV1) |
| Subtitle tracks | tx3g, WebVTT | ASS, SRT, PGS, all | tx3g | WebVTT |
| Editing metadata | Limited | Extensive | Extensive | Limited |
| DRM support | Widevine, PlayReady, FairPlay | Limited | FairPlay | Widevine |
Metadata and Apple Compatibility
MP4 uses udta atoms for user metadata and iTunes-style ilst atoms for tags recognized by Apple:
# Set title, artist, year
ffmpeg -i input.mp4 -c copy \
-metadata title="My Video" \
-metadata artist="Creator Name" \
-metadata year="2024" \
-movflags +faststart output_tagged.mp4
# Extract all metadata
ffprobe -v quiet -print_format json -show_format input.mp4 | jq '.format.tags'
Apple devices add GPS coordinates in udta atoms when recording with iPhone/iPad cameras — a privacy consideration for shared files.
Common Issues and Solutions
Issue: Video plays on desktop but not on iPhone
Cause: Codec (HEVC) not supported on older iOS / H.264 profile too high
Fix: Re-encode with -profile:v baseline -level 3.1 for maximum iOS compatibility
Issue: File is huge despite small duration
Cause: Variable bitrate poorly tuned, or source is lossless/RAW
Fix: Use CRF encoding with libx264 -crf 23 instead of bitrate-based encoding
Issue: Audio/video out of sync after editing
Cause: PTS (Presentation Timestamp) discontinuities after cutting
Fix: ffmpeg -i input.mp4 -c copy -avoid_negative_ts make_zero output.mp4
Issue: Black bars in landscape/portrait mixed content
Cause: rotate metadata present but ignored by some players
Fix: Apply rotation physically: ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output.mp4
Summary
MP4's combination of universal device support, efficient ISOBMFF architecture, fMP4 streaming capability, and broad codec support makes it the correct default for virtually all video distribution use cases. For archival or complex multi-track content, MKV offers more flexibility. For browser-only delivery at maximum compression, WebM with AV1 is ideal. But for everything else — mobile, streaming, social media, camera footage — MP4 with H.264/AAC remains the undisputed standard.
Related conversions
Common video conversions that pair well with this guide: