Container (media container)
/kənˈteɪnər/ · noun · media format
A media container is the file format that holds audio, video and subtitle streams together with timing and metadata. MP4, MKV and MOV are containers.
In more detail
A video file is usually several streams wrapped together: one or more video tracks, audio tracks, subtitle tracks and chapter markers. The container defines how those streams are stored, kept in sync and described. The codec defines how each stream is compressed.
Common containers are MP4 and MOV from the QuickTime family, MKV, WebM, AVI and, for audio, M4A, Ogg and WAV. The file extension usually names the container, not the codec.
Containers vs codecs
An MP4 file can hold H.264, HEVC or AV1 video with AAC or MP3 audio. An MKV can hold almost any codec. So two files with the same extension can need different decoders, and a player that opens one MP4 may fail on another.
Which codecs a container allows is decided by its specification and by what players support. WebM, for example, only allows VP8, VP9 or AV1 video with Vorbis or Opus audio.
Remuxing
When the streams inside one container are allowed in another, they can be copied across without re-encoding. This is called remuxing. It is fast and lossless, which is why an H.264 MOV or MKV can become an MP4 in seconds. When the codecs don't fit, the streams have to be transcoded, which takes longer and loses a little quality.
Key points
- The container holds the streams. The codec compresses each stream.
- MP4, MKV, MOV and WebM are containers with different codec rules.
- Remuxing changes the container without re-encoding the streams.