🍋
Menu
How-To Beginner 2 min read 318 words

Video Container vs Codec: Understanding MP4, WebM, AVI, and MKV

Demystify the relationship between video containers and codecs. Learn why changing a file extension does not convert video, and how to choose the right container-codec combination for your needs.

Key Takeaways

  • A container (MP4, WebM, MKV) is a wrapper that holds encoded video, audio, subtitles, and metadata.
  • For maximum browser compatibility, use MP4 with H.264 video and AAC audio.
  • Re-encoding video is computationally intensive.

Containers and Codecs Are Different Things

A container (MP4, WebM, MKV) is a wrapper that holds encoded video, audio, subtitles, and metadata. A codec (H.264, VP9, AV1) is the algorithm that compresses and decompresses the actual video data. Renaming a file from .avi to .mp4 does not re-encode the video — it just changes the wrapper, often producing a broken file.

Container Comparison

Container Common Codecs Streaming Subtitles Patent Status
MP4 (.mp4) H.264, H.265, AAC Yes Limited Patented codecs
WebM (.webm) VP8, VP9, AV1, Opus Yes WebVTT Royalty-free
MKV (.mkv) Any codec Limited Extensive Open format
AVI (.avi) Legacy codecs No Limited Legacy
MOV (.mov) H.264, ProRes Yes Limited Apple ecosystem

Codec Comparison

Codec Compression Speed Quality Browser Support
H.264 Good Fast encode/decode Good Universal
H.265 (HEVC) 50% better than H.264 Slow encode Excellent Safari, some others
VP9 Similar to H.265 Medium Excellent Chrome, Firefox, Edge
AV1 30% better than VP9 Very slow encode Best Growing support

Choosing for the Web

For maximum browser compatibility, use MP4 with H.264 video and AAC audio. For better compression, add a WebM (VP9/Opus) source and let browsers choose. AV1 offers the best quality per bit but encoding is computationally expensive.

Conversion Tips

Re-encoding video is computationally intensive. Use stream copying (-c copy in FFmpeg) when changing containers without changing codecs — it completes in seconds instead of minutes.