Ch. 10 · In Practice

한국어日本語
6 min

Container vs. Codec: What's the Difference Between MP4 and H.264?

An .mp4 file doesn't tell you which codec it uses. Learn how containers (MP4, MKV, WebM) differ from codecs (H.264, HEVC, AV1), and how to check with ffprobe.

This is the most common point of confusion for people learning codecs. Before the question "What codec is this mp4 file?" even makes sense, you have to know that mp4 is not a codec.

Container vs. codec

A codec (what you learned in Chapters 5-9) is the algorithm that actually compresses video and audio. A container is the "envelope," or file format, that holds the compressed data (plus subtitles, metadata, chapters, and so on). mp4 is only an envelope. Inside it you might find H.264, HEVC, or AV1. Audio codecs such as AAC and Opus for the audio track are covered in Chapter 12, and the inner structure of MP4 in Chapter 16.

MP4 container Video: H.264/HEVC/AV1 Audio: AAC/Opus ... Subtitle track Metadata Chapters · timecodeColor metadata(CICP, Ch. 1)
Container = envelope, codec = the letter inside
ContainerTypical codecs it can holdNotes
MP4 (ISOBMFF)H.264, HEVC, AV1, AACMost widely supported; used for both streaming and storage
MKV (Matroska)Almost any codecOpen source, flexible metadata
WebMVP9, AV1, OpusWeb standard, geared toward royalty-free codecs (Ch. 7)
MOV (QuickTime)ProRes, H.264, etc.Apple ecosystem, friendly to editing codecs (Ch. 9)
MPEG-TSH.264, HEVCBroadcast delivery, good at joining streams together
Why you must keep them apart in practice

"The file won't open" can have two completely different causes. ① The container can't be read (the parser doesn't understand the file structure at all). ② The container can be read, but the codec inside can't be decoded (there is no hardware or software decoder for one of the codecs from Chapters 5-9). The diagnosis is completely different for each, so codec engineers always use ffprobe to check the container and the codec separately.

The most basic command for checking container and codec separately
ffprobe -v error -show_entries \
  stream=codec_name,codec_type,width,height,pix_fmt \
  -of default=noprint_wrappers=1 input.mp4

# Example output:
# codec_type=video
# codec_name=hevc      ← the codec
# width=3840
# height=2160
# pix_fmt=yuv420p10le  ← chroma format + bit depth from Chapter 1
ContainerContainer

A file format that bundles compressed media and metadata. A separate concept from the codec.

ISOBMFFISO Base Media File Format

The international standard container structure that MP4 and others are built on.

TrackTrack

An individual stream inside a container (video, audio, subtitles, and so on).

Check yourself

When an mp4 file won't play, which two causes must you tell apart?