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.

ContainerInternal structureTypical video codecsTypical audio codecsNative HTML5 browser playback
MP4 (.mp4)ISO/IEC 14496-12 boxes (ftyp, moov, mdat)H.264, HEVC, AV1AAC, MP3, Opus, AC-3Universal (when H.264 + AAC)
WebM (.webm)EBML binary XML subset of MatroskaVP8, VP9, AV1Opus, VorbisChrome, Edge, Firefox, Safari 16+
MKV (.mkv)EBML Matroska (1A 45 DF A3)Any codec (H.264, HEVC, AV1, MPEG-2)Any codec + multiple tracksPartial (Chrome plays H.264 inside MKV, often without subtitles)
MOV (.mov)Apple QuickTime atoms (ftypqt )H.264, HEVC, Apple ProResAAC, Linear PCMSafari native; other browsers if H.264/AAC
AVI (.avi)Microsoft RIFF chunks (hdrl, movi, idx1)MPEG-4 Part 2, MJPEGPCM, MP3None (requires transcoding)
MPEG-TS (.ts)Fixed 188-byte packets with 0x47 sync byteH.264, HEVC, MPEG-2AAC, MP2, AC-3Via 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 .ts packets 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.

Related guides and test tools

Frequently asked questions

Why do WebM and MKV files have the exact same first 4 magic bytes (1A 45 DF A3)?
Both formats use Extensible Binary Meta Language (EBML), which starts with the 4-byte EBML Header ID 1A 45 DF A3. A parser distinguishes them by reading the DocType string inside that EBML header: 'matroska' for .mkv and 'webm' for .webm.
Can I change a .mkv or .avi file to .mp4 just by renaming the extension?
No. Renaming the extension leaves the internal EBML or RIFF container bytes unchanged. To switch containers without re-encoding the video quality, run `ffmpeg -i input.mkv -c copy output.mp4` to remux the streams.