What Are Video Containers and Codecs? The Real Source of Compatibility Problems
8 min read
Why does a video file open on one device but not another? Why can two videos of the same length differ tenfold in size? The answer to those questions lies in video files' two-layer structure. This article explains the container/codec distinction, how codecs work, and the real source of compatibility problems.
A two-layer structure
A video file is really a package. Inside it you find:
- One or more video tracks
- One or more audio tracks (different languages, different channel layouts)
- Subtitle tracks
- Metadata (title, duration, creation date, chapter markers)
- Timestamps — which frame gets shown when
The container is the structure holding those parts together. The file extension indicates the container: .mp4, .mkv, .avi, .mov, .webm.
The codec determines how the tracks are compressed. For video: H.264, H.265, VP9, AV1; for audio: AAC, MP3, Opus, AC3.
The most practical consequence of that distinction: the extension doesn't tell you whether the file will play. Of two MP4 files, one can work everywhere while the other won't open on an older television — because the codecs inside differ.
The containers' characteristics
| Container | Strength | Weakness | Typical use | |---|---|---|---| | MP4 | Universal support, streaming-friendly | Limited codec/subtitle support | Web, sharing, mobile | | MKV | Carries everything, multiple tracks, flexible subtitles | Less hardware support | Archives, film collections | | MOV | Native in the Apple ecosystem, editing-friendly | Less widespread than MP4 | Video production, macOS | | AVI | Very old, broad legacy support | Doesn't carry modern codecs well | Old archives | | WEBM | Open, optimized for the web | Only certain codecs | In-browser video |
MP4 and MOV actually share the same underlying structure (the ISO base media file format). That's why MOV → MP4 conversion can usually be done with a remux, meaning without any re-encoding.
MKV is the most flexible container: it carries nearly every codec, an unlimited number of tracks and rich subtitle formats. The cost is less support on hardware players.
AVI is a structure left over from the 1990s and doesn't work well with modern codecs — B-frame (bidirectional prediction frame) support is problematic and it has sync problems with variable bitrate audio.
How video codecs work
One second of 1080p video takes about 150 MB uncompressed. One minute becomes 9 GB. Without compression, video is practically impossible.
Video codecs exploit two kinds of redundancy:
Spatial redundancy (within a frame): in an image, neighboring pixels are usually similar. Thousands of pixels in a patch of sky have nearly the same value. That's reduced with techniques similar to photo compression (block division, frequency transform, quantization).
Temporal redundancy (between frames): consecutive frames are very similar to each other. With a static camera the background doesn't change at all; only moving objects differ. Instead of storing every frame from scratch, the codec stores the difference from the previous frame.
That second mechanism is the real power of video compression, and it gives rise to frame types.
Frame types and GOP structure
I-frame (intra, keyframe): a complete picture on its own. Can be decoded without looking at other frames. Think of it as a photograph. It's the frame type that takes the most space.
P-frame (predicted): stores the difference by looking at previous frames. It says "this block is the same as the block that was there in the previous frame, just shifted 3 pixels right." Takes far less space than an I-frame.
B-frame (bidirectional): looks at both previous and following frames. The most efficient frame type, but it requires decoding frames out of order.
These frames are arranged in groups called GOPs (Group of Pictures). A typical GOP might look like:
I B B P B B P B B P B B I ...
GOP length (the distance between two I-frames) is an important setting:
- Short GOP (frequent keyframes): a bigger file, but precise seeking, easy editing, fast error recovery.
- Long GOP (sparse keyframes): a smaller file, but coarse seeking and difficult editing.
That explains why you can't seek to exactly the second you want in a video: the player jumps to the nearest I-frame, because it can't start from the middle.
The same reason comes up when cutting and merging video. If the cut point lands on an I-frame, no re-encoding is needed; if it doesn't, that GOP has to be re-encoded.
The efficiency gap between codecs
| Codec | Year | Relative efficiency | Hardware support | |---|---|---|---| | MPEG-4 Part 2 (DivX/Xvid) | 1999 | Reference | Older devices | | H.264 (AVC) | 2003 | ~50% better | Nearly universal | | VP9 | 2013 | ~30% better than H.264 | Good on web, medium hardware | | H.265 (HEVC) | 2013 | ~40% better than H.264 | On newer devices | | AV1 | 2018 | ~20% better than H.265 | Limited but growing |
Where does the efficiency gain come from? More flexible block division (H.264 uses fixed 16×16 macroblocks while H.265 uses variable sizes up to 64×64), more prediction modes, better motion estimation and more advanced entropy coding.
The cost is computational load. H.265 encoding is noticeably slower than H.264; AV1 is slower still. On the decoding side, devices without hardware support suffer battery drain and stuttering.
Why is H.264 still the standard? Because practically every device ever made has a hardware decoder for it. Your phone, your television, your browser, your car display all decode H.264 efficiently. That universality is worth more than a 40% size advantage in most scenarios.
Bitrate modes
CBR (constant bitrate): the same data every second. Used for broadcast and live streaming, where predictability matters.
VBR (variable bitrate): data is distributed according to scene complexity. A static dialogue scene gets few bits, a fast-moving action scene gets many. At the same average bitrate it gives noticeably better results than CBR.
CRF (constant rate factor): you set a quality target instead of a bitrate (typically between 0 and 51, lower meaning better quality). The encoder itself adjusts the bitrate needed to hit that quality. The file size isn't known in advance but the quality stays consistent.
For archiving and general use CRF is usually the best approach — every scene gets as much data as it needs. For H.264 the CRF 18-23 range is commonly used; 18 is visually near-lossless and 23 counts as a good balance.
Frame rate and the VFR problem
Frame rate is how many frames get shown per second. Cinema uses 24 fps, television 25 or 30 fps, and 60 fps is used for smooth motion.
Constant frame rate (CFR): frames arrive at equal intervals. Traditional and predictable.
Variable frame rate (VFR): frames don't arrive at equal intervals. Screen recording software and some phone cameras save space by dropping frames when there's no motion.
VFR is a practical source of trouble: many editing and conversion tools assume a constant frame rate and misinterpret the timestamps when processing a VFR source. The result is audio-video drift that grows as the video goes on.
If you have a sync problem in a conversion, that's the first thing to suspect. The fix is forcing a constant frame rate during the conversion.
Why some videos won't open
Things to check in order for diagnosis:
1. No codec support. The most common cause. The device may not be able to decode H.265 or AV1. Fix: re-encode to H.264.
2. No container support. Rarer. Some older devices can't read MKV. Fix: remux to MP4 (if the codecs are compatible).
3. The audio codec isn't supported. The picture comes but the sound doesn't. Codecs like AC3 or DTS don't work on some devices. Fix: convert the audio to AAC.
4. The profile/level is too high. H.264 has profiles of its own (Baseline, Main, High) and some older devices only support the lower ones. High resolution and bitrate can also exceed the limits.
5. The file is corrupted or incomplete. The download may have been cut short.
In summary
A video file is two-layered: the container holds the tracks together, the codec compresses them. Most compatibility problems come from the codec rather than the container, which is why the advice "convert it to MP4" is incomplete on its own — you have to specify the codec inside too. Codecs exploit redundancy between frames, which gives rise to the I/P/B frame structure and the concept of a GOP; seeking precision and ease of cutting depend directly on that. H.265 and AV1 are more efficient, but H.264's universal hardware support is worth more in most scenarios. And variable frame rate is the most common hidden cause of audio-video drift in conversions.
Frequently Asked Questions
Why do two videos with the same extension behave differently?
Because the extension indicates only the container, not the codec inside. Of two MP4 files, one can carry H.264 video and work everywhere while the other carries H.265 and won't open on an older device. Likewise, if an MKV contains AV1, most hardware players struggle. In diagnosis you have to ask 'which codec,' not 'which format.'
What is a keyframe, and why does it matter?
A keyframe (I-frame) is a frame containing a complete picture on its own; it can be decoded without looking at other frames. The frames in between store only the changes. That's why the player jumps to the nearest keyframe when you seek forward — if keyframes are sparse, seeking feels coarse. And if cuts are made at keyframe boundaries, no re-encoding is needed.
If H.265 is so much better than H.264, why doesn't everyone use it?
For three reasons: older devices have no hardware decoder and decoding in software drains battery or causes stuttering, some browsers don't support it, and the patent licensing structure is complicated. H.264, by contrast, has hardware support on practically every device ever made. That's why H.264 is still the safest choice and H.265 is mainly used where saving storage is critical.
Why does variable frame rate (VFR) cause sync problems?
In VFR the frames don't arrive at equal intervals; screen recording software and some phone cameras save space by dropping frames when there's no motion. Many editing and conversion tools assume a constant frame rate and can misinterpret the timestamps of a VFR source. The result is audio-video drift that grows as the video goes on.
Try this out right away with Video Format Dönüştür.
Try Video Format Dönüştür