Choosing a video container: MP4, MKV, WebM, MOV, AVI and MPEG-TS compared
A video file's extension (.mp4, .mkv, .webm, .mov, .avi, .ts) only names the container box—not the video or audio codec inside. Learn how container structures affect browser playback, HTTP streaming, subtitle tracks, and upload validation.
1. How a video container organizes tracks and timestamps
Every digital video file separates two layers of responsibility: the codecs (such as H.264/AVC, H.265/HEVC, VP9, AV1 for video, and AAC, Opus, MP3, AC-3, or PCM for audio) compress the raw pictures and sound, while the container format interleaves those compressed packets with presentation timestamps (PTS), decode timestamps (DTS), keyframe seek tables, audio language tags, and subtitle cues.
| Container | Internal structure | Typical video codecs | Typical audio codecs | Native HTML5 browser playback |
|---|---|---|---|---|
| MP4 (.mp4) | ISO/IEC 14496-12 boxes (ftyp, moov, mdat) | H.264, HEVC, AV1 | AAC, MP3, Opus, AC-3 | Universal (when H.264 + AAC) |
| WebM (.webm) | EBML binary XML subset of Matroska | VP8, VP9, AV1 | Opus, Vorbis | Chrome, Edge, Firefox, Safari 16+ |
| MKV (.mkv) | EBML Matroska (1A 45 DF A3) | Any codec (H.264, HEVC, AV1, MPEG-2) | Any codec + multiple tracks | Partial (Chrome plays H.264 inside MKV, often without subtitles) |
| MOV (.mov) | Apple QuickTime atoms (ftypqt ) | H.264, HEVC, Apple ProRes | AAC, Linear PCM | Safari native; other browsers if H.264/AAC |
| AVI (.avi) | Microsoft RIFF chunks (hdrl, movi, idx1) | MPEG-4 Part 2, MJPEG | PCM, MP3 | None (requires transcoding) |
| MPEG-TS (.ts) | Fixed 188-byte packets with 0x47 sync byte | H.264, HEVC, MPEG-2 | AAC, MP2, AC-3 | Via MSE / HLS.js player |
2. The MP4 "moov atom at end of file" streaming trap
In an MP4 or MOV file, the raw compressed video and audio frames live inside the mdat (media data) box, while the track headers, codec configuration (SPS/PPS), and frame byte-offset table live inside the moov (movie metadata) box. When a camera or screen recorder records a video in a single pass, it writes mdat first and appends the moov box at the very end of the file when recording stops.
If you host an MP4 file whose moov box sits at the end of a 50 MB file, a web browser cannot start playing Second 1 until it either downloads all 50 MB or issues an HTTP Range request to the end of the file and back. Remuxing with FFmpeg's -movflags +faststart moves the moov atom to the front of the file immediately after ftyp so playback begins on the first TCP round trip.
3. When to choose MP4 vs. WebM vs. MKV vs. MPEG-TS
- Choose MP4 (H.264 + AAC) for universal single-file playback: Every desktop and mobile browser, smart TV, and social platform decodes H.264 High/Main/Baseline Profile (`yuv420p`) with AAC-LC audio in an MP4 container.
- Choose WebM (VP9 or AV1 + Opus) for royalty-free web video and alpha transparency: WebM supports alpha-channel transparent video overlay in browsers and avoids MPEG-LA/Via licensing fees.
- Choose MKV for multi-track archival and subtitle muxing: Matroska (.mkv) can bundle unlimited audio tracks, soft SRT/ASS/PGS subtitle tracks (see video-embedded-subtitles.mkv), and font attachments in a single file.
- Choose MPEG-TS (.ts) or fragmented MP4 (fMP4) for live streaming: Because
.tspackets repeat stream headers every few hundred milliseconds and have no end-of-file index requirement, cutting a live stream at any 188-byte boundary still leaves a valid playable segment.