A video file is two things at once. There is the container: the file format that holds the picture, the sound and the subtitles together and keeps them in step. And there are the codecs: the methods used to compress the picture and the sound that sit inside it. MKV and AVI are containers. So are MP4 and MOV. H.264, DivX and AAC are codecs. The extension on a file tells you which container it is and almost nothing about what is inside, which is why one .mkv plays on your TV and the next one does not.
A video file is a box with things in it
Think of a film on your computer as a parcel. Inside are several separate items: a stream of pictures, a stream of sound, perhaps a second soundtrack in another language, perhaps subtitles. Each item has been packed down by its own method. The parcel itself is just the box, the packing list and the instructions for putting everything back together in the right order.
The two words get mixed up constantly, so it is worth pinning them down:
- A codec decides how the picture or sound is squeezed, and therefore how good it looks and how big it is. We cover those in a separate lesson: all about codecs.
- A container decides how the squeezed streams are arranged in a file: what can be included, how the streams stay in step, and how a player finds its way around.
“Is this an MKV or an H.264?” is like asking whether something is a cardboard box or a pair of shoes. It is very often both.
What a container actually does
Every container format, from 1992’s AVI to today’s MKV, has the same five jobs. How well it does each one is what separates them.
- Hold several streams in one file. At minimum a picture and a soundtrack; in a capable container, any number of each, plus subtitles.
- Interleave them. The streams are not stored one after the other. If they were, a player would have to read the whole picture before it reached the first second of sound. Instead the file is cut into small pieces and shuffled together like a deck of cards: a little video, a little audio, a little video. Whatever the player needs next is always close by.
- Keep them in step. Each piece carries, or implies, a time: “show this frame at 00:04:12.480”. That is what keeps lips and voices together.
- Provide an index. A table that says where in the file each moment lives, so that dragging the slider to the 40-minute mark does not mean reading 40 minutes of data to find it.
- Describe the contents. Which codec each stream uses, the picture size and shape, the frame rate, the language of each soundtrack, the title, the chapter points.
What a container does not do
It does not affect quality. A container never touches the picture or the sound; it only wraps them. The same H.264 stream is bit-for-bit identical in an MKV and in an MP4. If someone tells you MKV “looks better” than MP4, what they have noticed is a difference in the codec or its settings.
And renaming a file does not change its container. Changing .mkv to .mp4 in the file name changes the label on the box, nothing more. Some players ignore the name and read the file anyway, which makes it look as though renaming worked. The proper way is further down, and it is nearly as quick.
AVI: the 1992 original
AVI stands for Audio Video Interleave. Microsoft released it in November 1992 as part of Video for Windows, when a video clip on a PC was a stamp-sized window playing from a CD-ROM. It is built on RIFF, the same simple wrapper Microsoft and IBM had designed a year earlier for WAV audio. If you have read what is inside a WAV file, an AVI will look familiar: labelled chunks, each one announcing its name and its length.
| Chunk | What it holds |
|---|---|
RIFF … AVI | “This is an AVI, and it is this long.” The same opening as a WAV, with a different name. |
hdrl › avih | The main header: picture width and height, the number of streams, the total number of frames, and how many millionths of a second each frame lasts. |
strl (one per stream) | A stream header saying whether it is video or audio, and a four-letter code naming the codec: MJPG, dvsd, DIVX, XVID, HFYU. |
movi | The picture and sound themselves, interleaved in small chunks. 00dc is a compressed video frame from stream 0; 01wb is a piece of audio from stream 1. |
idx1 | The index, at the very end: where every chunk is, and which video frames a player can jump straight to. |
That four-letter code is called a FourCC, and it is the whole of AVI’s codec system. The container does not know or care what the code means. Windows simply looks for an installed codec that claims it. If one is there, the video plays. If not, you get the error that defined a decade of PC video: sound, a black rectangle, and a hunt for the right codec to install.
For its time AVI was a fine design, and its simplicity is why it lasted. But it was built for the video of 1992, and video moved on. Its limits are worth knowing because they explain most of the odd behaviour of old files:
- No timestamps. An AVI does not record when each frame should appear. It records one frame rate for the whole file, and frame number 1,000 is simply shown 1,000 frame-lengths after the start. That is fine for a camcorder tape at a steady 25 frames a second. It cannot properly describe video whose frame rate varies, which is what phones and screen recorders produce.
- Frames must be stored in the order they are shown. Modern codecs get much of their efficiency by storing frames out of order (the codecs lesson explains why). AVI has no way to say “decode this one now but show it later”, so those codecs need workarounds that players handle inconsistently. This is why H.264 in an AVI is asking for trouble, and why H.265 and AV1 are effectively never put in one.
- A 2 GB ceiling in the original format. Sizes are 32-bit numbers, and many programs stopped at 2 GB. An extension called OpenDML, adopted in 1996, strings extra RIFF sections together to lift the limit, and almost every large AVI you meet today uses it.
- Nowhere to put the extras. No subtitles, no chapters, and no dependable way to label a soundtrack’s language or the intended shape of the picture. Subtitles for an AVI travel as a separate
.srtfile with the same name. - Awkward with modern audio. AVI expects sound at a constant bitrate. Variable-bitrate MP3 and AAC can be forced in, with occasional sync problems as the price.
Where you still meet AVI
- Digital cameras from the 2000s. Most compact cameras of that era shot their video clips as Motion JPEG in an AVI.
- Transfers from MiniDV camcorder tapes. The DV data copied off the tape over FireWire was traditionally saved as “DV-AVI”, at about 13 GB an hour.
- Downloads and discs from the DivX and Xvid years. Roughly 2000 to 2010: a film squeezed to fit a 700 MB CD, playable on any DVD player with a DivX badge.
- Lossless tape captures. VirtualDub, still the standard tool for capturing VHS without throwing anything away, writes AVI. The lossless codecs it uses store every frame whole and in order, which is exactly the kind of video AVI handles well.
- Exports from older CCTV systems, dashcams and screen recorders.
MKV: the box that takes anything
MKV is the file extension of Matroska, an open container format that began in December 2002. The name comes from matryoshka, the Russian nesting dolls, and it is a fair description: a Matroska file is a set of labelled elements nested inside other elements.
Where AVI was designed around the video of its day, Matroska was designed around not knowing what was coming. Its foundation is a scheme called EBML, which works like a binary version of XML: every element in the file begins with an ID and its own length. A player that meets an element it does not recognise reads the length and steps over it. That one decision is why a format from 2002 could later take on high dynamic range, 3D, and codecs that did not exist when it was written, without breaking a single old file or old player.
| Element | What it holds |
|---|---|
| EBML header | “This is a Matroska file”, and which version a player needs to read it. |
| Segment info | The title, the duration, the timestamp precision, and the program that wrote the file. |
| Tracks | One entry per stream: video, audio or subtitle; its language; its codec, as a plain ID such as V_MPEG4/ISO/AVC (H.264) or A_FLAC; the picture size and the shape it should be displayed at. |
| Clusters | The picture and sound, in blocks that each carry their own timestamp. A cluster covers a few seconds at most. |
| Cues | The seek index: which cluster holds which moment. |
| Chapters, tags, attachments | Chapter points, descriptive tags, and attached files such as cover art or the fonts a subtitle track needs. |
What that buys you in practice:
- Almost any codec. Old or new, lossy or lossless: H.264, H.265, AV1, MPEG-2, DV, FFV1 for the picture; AAC, Dolby Digital, DTS, FLAC, Opus or plain PCM for the sound.
- As many tracks as you like, each labelled. Several soundtracks and subtitle tracks, each tagged with a language and a name, with one marked as the default.
- Subtitles inside the file. Plain text, styled text with its fonts attached, or the picture-based subtitles copied from a DVD or Blu-ray.
- Every frame individually timestamped. Variable frame rates and out-of-order frames are simply not a problem.
- The picture shape is recorded separately from the pixel count. This matters for anything from tape. A PAL capture is 720 × 576 pixels but is meant to be shown at 4:3. In an MKV that instruction is a field in the container, which is why step 6 of our VHS guide can fix a wrongly shaped capture in seconds without touching the video.
- It survives an interrupted recording. More on that below. For capturing anything in real time, this is the feature that matters most.
- It is open. No licence, no fees, and since October 2024 a published internet standard (RFC 9559).
The price of all that flexibility is patchier support at the consumer end:
- Apple’s own apps do not open it. At the time of writing, QuickTime Player and the Photos app on an iPhone or Mac will not play an MKV. A third-party player such as VLC will. Windows 10 and 11, Android, and most smart TVs and media boxes play MKV without help.
- Websites, messaging apps and several video editors want MP4.
- “Plays MKV” on a TV’s box promises less than it sounds. Because an MKV can hold nearly anything, a device that reads the container may still be unable to decode what is inside.
One relative is worth knowing. WebM, which Google introduced in 2010 for web video, is Matroska with a short guest list: the same structure, but only royalty-free codecs allowed (VP8, VP9 or AV1 video; Vorbis or Opus audio).
MP4, because you will meet it everywhere
No account of containers is complete without the one on every phone. MP4 was standardised in the early 2000s as part of MPEG-4, and it is built directly on the file format Apple created for QuickTime in 1991, which is why .mov and .mp4 files are near-twins inside.
MP4 sits between the other two. It has proper timestamps, chapters and multiple tracks, so none of AVI’s structural problems. But it keeps a much shorter list of codecs than MKV: in practice H.264, H.265 or AV1 for the picture, and AAC for the sound. That narrowness is its strength. A device that says it plays MP4 nearly always plays what is actually inside one, so MP4 is the format that works when you send a video to someone and have no idea what they will open it on.
Its weak point is the way it is written. An MP4 keeps its entire index, and the description of every stream, in one block. While a recording is in progress that block cannot be finished, so it is written at the very end. If the recording never reaches the end, the block is never written.
This is the reason recording software long recommended MKV, and the reason newer versions offer a “fragmented” or “hybrid” MP4 that writes its index in instalments. It is also why our VHS guide records to MKV and makes the MP4 afterwards.
Side by side
| AVI | MKV | MP4 | |
|---|---|---|---|
| Introduced | 1992 | 2002 | 2001–2003 |
| From | Microsoft | The open Matroska project | The MPEG standards group, on Apple’s QuickTime design |
| Codecs accepted | Older ones well, modern ones badly | Almost anything | A short modern list |
| Timestamps | None: one fixed frame rate | On every block | On every frame |
| Soundtracks | More than one possible, unlabelled | Any number, labelled | Several, labelled |
| Subtitles and chapters | No | Yes, most formats | Limited |
| Records the picture shape | Not dependably | Yes | Yes |
| After an interrupted recording | Usually repairable | Plays up to the cut | Unreadable, unless fragmented |
| Plays on | Computers; older DVD players | Computers, Android, most TVs; not Apple’s own apps | Everything |
| Best for | Lossless capture, and files that already exist | Capturing, keeping, and anything with extra tracks | Sharing and playing anywhere |
The codecs you will commonly find inside
Since the extension will not tell you, here is what is usually in the box. Each of these gets a proper explanation in the codecs lesson; this is the field guide.
Video
| Codec | Also called | Usually found in | What it is |
|---|---|---|---|
| H.264 | AVC, MPEG-4 Part 10 | MP4, MKV, MOV | The universal one. Phones, cameras, Blu-ray, web video. If in doubt, it is this. |
| H.265 | HEVC | MP4, MKV, MOV | H.264’s successor: about half the size for the same picture. 4K streaming, recent phones. |
| AV1 | MP4, MKV, WebM | The newest in wide use, and royalty-free. Streaming services and YouTube. | |
| VP9 | WebM, MKV | Google’s royalty-free codec before AV1. Most of YouTube for years. | |
| MPEG-4 Part 2 | DivX, Xvid | AVI | The codec of the 2000s download. Nearly every film-length AVI is this. |
| MPEG-2 | H.262 | DVD files (.vob), .mpg, .ts, MKV | DVD and broadcast television. |
| DV | AVI, MOV | MiniDV camcorder tapes. Large files, every frame complete. | |
| Motion JPEG | MJPEG | AVI, MOV | Each frame a separate JPEG. Older digital cameras and capture devices. |
| Lossless codecs | HuffYUV, Lagarith, UT Video, FFV1 | AVI, MKV | Nothing discarded. Tape capture and archives; very large files. |
Audio
| Codec | Usually found in | What it is |
|---|---|---|
| AAC | MP4, MKV, MOV | The usual partner of H.264. MP3’s more efficient successor. |
| MP3 | AVI, MKV | The usual partner of DivX and Xvid in an AVI. |
| AC-3 (Dolby Digital) | DVD files, MKV, MP4, .ts | 5.1 surround from DVD and broadcast TV. |
| DTS | MKV | Surround from DVD and Blu-ray. A common reason for “picture but no sound”. |
| Opus, Vorbis | WebM, MKV | The royalty-free pair that travel with VP9 and AV1. |
| PCM | AVI, MOV, MKV | Uncompressed, exactly as in a WAV. Camcorder tapes and lossless captures. |
| FLAC | MKV | Lossless and about half the size of PCM. |
What fits in which box
| AVI | MKV | MP4 | |
|---|---|---|---|
| H.264 video | Awkward | Yes | Yes |
| H.265 or AV1 video | No | Yes | Yes |
| DivX or Xvid video | Yes | Yes | Yes |
| DV video | Yes | Yes | No |
| Lossless video (HuffYUV, FFV1) | Yes | Yes | No |
| AAC audio | Awkward | Yes | Yes |
| MP3 or AC-3 audio | Yes | Yes | Yes |
| DTS audio | Yes | Yes | Awkward |
| FLAC audio | No | Yes | Awkward |
| Uncompressed PCM audio | Yes | Yes | Awkward |
| Text subtitles (SRT, ASS) | No | Yes | Awkward |
| DVD and Blu-ray subtitles | No | Yes | Awkward |
“Awkward” means it can be done, but through a workaround or a rarely supported corner of the format, and players often trip on the result. The MKV column is the point of the table.
The rest of the family
| Container | Extensions | Where you meet it |
|---|---|---|
| QuickTime | .mov | MP4’s parent. iPhone footage and professional editing. |
| WebM | .webm | A restricted Matroska for the web. |
| MPEG transport stream | .ts, .m2ts, .mts | Broadcast television, Blu-ray discs and AVCHD camcorders. Built for transmission: it is cut into small fixed-size packets so a receiver can join halfway through and ride over errors. |
| MPEG program stream | .mpg, .vob | DVDs. The .vob files on a DVD are MPEG-2 video with AC-3 sound. |
| ASF | .wmv, .asf | Microsoft’s replacement for AVI. Windows Media files of the 2000s. |
| Flash Video | .flv | Web video before about 2012. |
| MXF | .mxf | Broadcast and cinema. Professional cameras. |
When a file will not play
Once you separate the box from the contents, most playback problems sort themselves into one of two kinds.
- The player cannot read the container. Nothing happens at all, or the file is refused outright. An MKV on an iPhone’s built-in player is the usual example.
- The player reads the container but cannot decode something inside. This is the more common one, and it produces the stranger symptoms: a picture with no sound, sound with a black screen, or a file that plays on the laptop but stutters on the TV.
So the first step is always to look inside. Three free ways:
- VLC. Open the file and choose Tools › Codec Information (on a Mac, Window › Media Information).
- MediaInfo. A small free program that lists everything about a file: container, each stream, codec, bitrate, picture shape.
- FFmpeg’s
ffprobe. In a terminal,ffprobe "tape.mkv"prints a line per stream.
Input #0, matroska,webm, from 'tape.mkv':
Stream #0:0: Video: h264 (High), yuv420p, 720x576 [SAR 16:15 DAR 4:3], 25 fps
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo
That (trimmed) output reads: a Matroska container, holding H.264 video at 720 × 576 to be displayed at 4:3, and stereo AAC sound. Now you know which half of the problem you have.
Changing the box without touching the contents
Because the container and the streams are separate things, you can lift the streams out of one container and place them in another without decoding or re-compressing anything. This is called remuxing (from multiplexing, the engineering word for interleaving). It is the single most useful thing to know about containers.
With FFmpeg (free; winget install Gyan.FFmpeg on Windows, brew install ffmpeg on a Mac), a remux is one line. The -c copy part is the instruction to copy every stream as it is:
ffmpeg -i "holiday.avi" -c copy "holiday.mkv"
Going from MKV to MP4 works the same way, provided the codecs inside are ones MP4 accepts. H.264 with AAC is fine:
ffmpeg -i "clip.mkv" -c copy -movflags +faststart "clip.mp4"
(+faststart moves that all-important index from the end of the MP4 to the front, so a web browser can begin playing before the whole file has downloaded.) If FFmpeg objects, it is telling you something inside the MKV has no place in an MP4, usually a subtitle track or a DTS soundtrack, and that one stream needs converting or leaving behind.
If you would rather not use a terminal, MKVToolNix is the free graphical tool for building and editing MKV files: drag a file in, tick the tracks to keep, add a subtitle file, save.
The rule that follows is the same one we gave for audio: remux freely, re-encode reluctantly. A remux can be repeated forever. A re-encode with a lossy codec is a photocopy of a photocopy.
Which one to use
- Recording or capturing anything in real time: MKV. A crash, a flat battery or a full disk costs you the last few seconds, not the whole recording.
- Keeping: MKV. It holds whatever codec you chose, records the picture shape properly, takes extra soundtracks and subtitles, and is an open standard that will be readable for as long as anyone reads video files.
- Sharing, or playing on a device you do not control: MP4, with H.264 video and AAC sound. Make it from the MKV, and keep the MKV.
- AVI: only when a tool requires it. Lossless capture in VirtualDub is the usual case. Do not choose it for anything new otherwise.
- Old AVI files: leave them alone, or remux them. They are not decaying. If you want everything in one modern format,
-c copyinto MKV preserves them exactly. Check the new file plays from start to finish before you delete anything, and never re-encode an old file just to modernise it.
And whatever the extension says, look inside before you judge a file. A large, clean MKV and a small, blocky one are both “an MKV”.
The practical lesson
A container choice is really a decision about what happens to a recording later: whether it survives a bad capture, whether it remembers its own shape, and whether it can be turned into something else without loss. Capture into a container that forgives mistakes, keep that file, and make the convenient copy from it.
That is how we deliver our own VHS transfers: H.264 video with AAC audio in a Matroska (.mkv) container.
Common questions
What is a video container?
Is MKV better quality than MP4 or AVI?
Can I convert AVI to MKV without losing quality?
ffmpeg -i input.avi -c copy output.mkv. It takes seconds rather than hours. Keep the original until you have checked the new file plays properly.Can I just rename a .mkv file to .mp4?
Why won’t my TV play an MKV file?
Is AVI obsolete? Should I convert my old AVI files?
-c copy. AVI is still created on purpose in a few places, mainly lossless tape capture with VirtualDub and transfers from DV camcorder tapes.