Container formats vs codecs
Think of a media file as a shipping box:Container Format
The box itself - defines how media data, metadata, and multiple tracks are organized and stored together. Examples: MP4, WebM, MKV.
Codec
What’s inside the box - the compression algorithm used to encode/decode the actual video or audio data. Examples: H.264, VP9, AAC.
- ✅ MP4 can contain H.264 video and AAC audio
- ✅ WebM can contain VP9 video and Opus audio
- ❌ WebM cannot contain H.264 video (not in WebM specification)
Supported container formats
Mediabunny supports these container formats for both reading and writing:Video containers
- MP4
- WebM
- Matroska (MKV)
- QuickTime (MOV)
- MPEG-TS
MPEG-4 Part 14 - The most widely supported video container format.
- Extension:
.mp4 - MIME Type:
video/mp4 - Best for: Universal compatibility, web delivery, mobile devices
- Video codecs: H.264 (AVC), H.265 (HEVC), VP9, AV1, VP8
- Audio codecs: AAC, MP3, Opus, Vorbis, FLAC, AC-3, E-AC-3, most PCM variants
input-format.ts:83-104
MP4 is based on the ISO Base Media File Format (ISOBMFF), which QuickTime also uses.
Audio-only containers
- MP3
- WAV
- FLAC
- Ogg
- ADTS
MPEG-1/2 Audio Layer 3 - The ubiquitous audio format.
- Extension:
.mp3 - MIME Type:
audio/mpeg - Audio codec: MP3 only
- Track limit: 1 audio track
output-format.ts:589-648
Supported codecs
Mediabunny supports 25+ codecs across video, audio, and subtitle categories.Video codecs (5)
codec.ts:34-40
Video codec details
Video codec details
- AVC (H.264): Most widely supported, good compression, broad device compatibility
- HEVC (H.265): Better compression than H.264, 4K/8K video, newer devices
- VP9: Open-source, YouTube standard, good for web delivery
- AV1: Next-gen open codec, superior compression, growing support
- VP8: Predecessor to VP9, legacy web video
Audio codecs (19)
Audio codecs are divided into compressed and uncompressed (PCM) formats:Subtitle codecs (1)
codec.ts:90-92
Format and codec compatibility
Not all codecs work with all formats. Use this compatibility matrix:Checking compatibility
You can programmatically check if a codec is supported by a format:Error handling for incompatible codecs
Mediabunny will throw an error if you try to use an incompatible codec:Choosing the right format and codec
Consider these factors when selecting formats and codecs:Compatibility
For maximum compatibility across devices and platforms, use MP4 with H.264 video and AAC audio.
Web Delivery
For web streaming, use WebM (VP9/Opus) or MP4 (H.264/AAC). Modern browsers support both.
Quality
For high quality with efficient compression, use HEVC, VP9, or AV1 video codecs.
Open Source
For open-source projects avoiding patent issues, use WebM, MKV, or Ogg with open codecs.
Next steps
Input and Output
Learn how to read and write media files
Sources and Targets
Understand different ways to read and write data