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.

A container holding four streams A file named holiday-1994.mkv drawn as a box. Inside are four separate streams: video compressed with H.264, two audio tracks compressed with AAC, and a subtitle track in SRT text format. A fifth strip holds chapters, the title, cover art and the seek index. holiday-1994.mkv the container Video codec: H.264 Audio, English codec: AAC Audio, commentary codec: AAC Subtitles, English format: SRT chapters · title · cover art · seek index
One file, several streams. The container is the outer box. Each stream inside was compressed by its own codec, and the container records which one so the player knows how to unpack it.

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.

  1. Hold several streams in one file. At minimum a picture and a soundtrack; in a capable container, any number of each, plus subtitles.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
Interleaved streams inside a file A strip representing the file from start to end, divided into small pieces. Wide pieces of video alternate with narrow pieces of audio and the occasional very narrow subtitle piece, so the three streams are mixed together all the way along. start of file end of file video frames audio subtitles
Interleaving. The streams are dealt into the file in small alternating pieces, so the sound that belongs with a picture is always stored right beside it. “AVI” is short for Audio Video Interleave: the technique is the format’s name.

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.

ChunkWhat it holds
RIFF … AVI “This is an AVI, and it is this long.” The same opening as a WAV, with a different name.
hdrl › avihThe 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.
moviThe 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.
idx1The 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 .srt file 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.

ElementWhat it holds
EBML header“This is a Matroska file”, and which version a player needs to read it.
Segment infoThe title, the duration, the timestamp precision, and the program that wrote the file.
TracksOne 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.
ClustersThe picture and sound, in blocks that each carry their own timestamp. A cluster covers a few seconds at most.
CuesThe seek index: which cluster holds which moment.
Chapters, tags, attachmentsChapter 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.

What an interrupted recording leaves behind in AVI, MKV and MP4 Three files drawn as strips, each cut off at the same point before the end. The AVI has its header and most of its picture and sound, but the index at the end was never written; it can usually be repaired. The MKV is made of self-contained blocks, so everything up to the cut plays. The MP4 has its picture and sound but its index, which was to be written last, is missing entirely, and the file cannot be read without repair tools. recording interrupted here AVI header picture + sound index Index never written: usually repairable. MKV header index Self-contained blocks: plays up to the cut. MP4 picture + sound index No index at all: unreadable without repair tools.
A power cut, two hours into a tape. Dashed parts were never written. An MKV describes its streams at the start and timestamps every block as it goes, so what was recorded still plays. A plain MP4 keeps both the description and the index for the end, and without them the data is just bytes.

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

AVIMKVMP4
Introduced199220022001–2003
FromMicrosoftThe open Matroska projectThe MPEG standards group, on Apple’s QuickTime design
Codecs acceptedOlder ones well, modern ones badlyAlmost anythingA short modern list
TimestampsNone: one fixed frame rateOn every blockOn every frame
SoundtracksMore than one possible, unlabelledAny number, labelledSeveral, labelled
Subtitles and chaptersNoYes, most formatsLimited
Records the picture shapeNot dependablyYesYes
After an interrupted recordingUsually repairablePlays up to the cutUnreadable, unless fragmented
Plays onComputers; older DVD playersComputers, Android, most TVs; not Apple’s own appsEverything
Best forLossless capture, and files that already existCapturing, keeping, and anything with extra tracksSharing 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

CodecAlso calledUsually found inWhat it is
H.264AVC, MPEG-4 Part 10MP4, MKV, MOVThe universal one. Phones, cameras, Blu-ray, web video. If in doubt, it is this.
H.265HEVCMP4, MKV, MOVH.264’s successor: about half the size for the same picture. 4K streaming, recent phones.
AV1MP4, MKV, WebMThe newest in wide use, and royalty-free. Streaming services and YouTube.
VP9WebM, MKVGoogle’s royalty-free codec before AV1. Most of YouTube for years.
MPEG-4 Part 2DivX, XvidAVIThe codec of the 2000s download. Nearly every film-length AVI is this.
MPEG-2H.262DVD files (.vob), .mpg, .ts, MKVDVD and broadcast television.
DVAVI, MOVMiniDV camcorder tapes. Large files, every frame complete.
Motion JPEGMJPEGAVI, MOVEach frame a separate JPEG. Older digital cameras and capture devices.
Lossless codecsHuffYUV, Lagarith, UT Video, FFV1AVI, MKVNothing discarded. Tape capture and archives; very large files.

Audio

CodecUsually found inWhat it is
AACMP4, MKV, MOVThe usual partner of H.264. MP3’s more efficient successor.
MP3AVI, MKVThe usual partner of DivX and Xvid in an AVI.
AC-3 (Dolby Digital)DVD files, MKV, MP4, .ts5.1 surround from DVD and broadcast TV.
DTSMKVSurround from DVD and Blu-ray. A common reason for “picture but no sound”.
Opus, VorbisWebM, MKVThe royalty-free pair that travel with VP9 and AV1.
PCMAVI, MOV, MKVUncompressed, exactly as in a WAV. Camcorder tapes and lossless captures.
FLACMKVLossless and about half the size of PCM.

What fits in which box

AVIMKVMP4
H.264 videoAwkwardYesYes
H.265 or AV1 videoNoYesYes
DivX or Xvid videoYesYesYes
DV videoYesYesNo
Lossless video (HuffYUV, FFV1)YesYesNo
AAC audioAwkwardYesYes
MP3 or AC-3 audioYesYesYes
DTS audioYesYesAwkward
FLAC audioNoYesAwkward
Uncompressed PCM audioYesYesAwkward
Text subtitles (SRT, ASS)NoYesAwkward
DVD and Blu-ray subtitlesNoYesAwkward

“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

ContainerExtensionsWhere you meet it
QuickTime.movMP4’s parent. iPhone footage and professional editing.
WebM.webmA restricted Matroska for the web.
MPEG transport stream.ts, .m2ts, .mtsBroadcast 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, .vobDVDs. The .vob files on a DVD are MPEG-2 video with AC-3 sound.
ASF.wmv, .asfMicrosoft’s replacement for AVI. Windows Media files of the 2000s.
Flash Video.flvWeb video before about 2012.
MXF.mxfBroadcast 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.

Remuxing compared with converting A file named tape.avi holds DV video and PCM audio. One arrow leads to tape.mkv, which holds exactly the same DV video and PCM audio: a remux, in which nothing changes. A second arrow leads to tape.mp4, which holds H.264 video and AAC audio: a conversion, in which both streams were re-encoded with some loss. tape.avi DV video PCM audio tape.mkv DV video PCM audio tape.mp4 H.264 video AAC audio Remux nothing changes Convert re-encoded: lossy
Two very different operations. A remux moves the same streams into a new box: seconds of work, and not one bit of picture or sound altered. A conversion decodes the streams and compresses them again with different codecs: slow, and each lossy pass costs a little quality.

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 copy into 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.

Media transfer service Or do it yourself

Common questions

What is a video container?
The file format that holds a video’s separate streams together: the picture, one or more soundtracks, subtitles, chapter points and descriptive information. It keeps the streams in step with timestamps and carries an index so a player can jump to any moment. MKV, AVI, MP4 and MOV are containers. The container compresses nothing itself; that is the job of the codecs inside it.
Is MKV better quality than MP4 or AVI?
No. Quality is decided by the codec and its settings, not by the container. The same H.264 stream is bit-for-bit identical in an MKV and an MP4. MKV is the more capable box: almost any codec, any number of tracks, chapters, and it survives an interrupted recording. It does not make the picture better.
Can I convert AVI to MKV without losing quality?
Yes. Moving the streams to a new container without re-encoding is called remuxing, and it alters nothing: 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?
No. Renaming changes the label, not the structure. Some players ignore the extension and read the file anyway, which makes it look as though it worked, but the file is still Matroska and anything that insists on a real MP4 will reject it. Remux it instead.
Why won’t my TV play an MKV file?
Either the TV cannot read the Matroska container at all, or it reads the container and cannot decode one of the codecs inside. The second is more common: a TV that plays MKVs with H.264 video may refuse one with H.265 or AV1, or play the picture in silence because the sound is DTS. Look inside the file with MediaInfo or VLC, then remux to MP4 or convert only the stream the TV cannot handle.
Is AVI obsolete? Should I convert my old AVI files?
Outdated, but not dead, and old AVIs do not need rescuing. VLC and most players still open them. Do not re-encode them; that costs quality. If you want a modern container, remux to MKV with -c copy. AVI is still created on purpose in a few places, mainly lossless tape capture with VirtualDub and transfers from DV camcorder tapes.
Why does my video have a picture but no sound?
Almost always because the player can decode the video codec but not the audio codec. They are separate streams, and a device can support one without the other. Surround formats such as DTS and Dolby TrueHD are the usual culprits on TVs, phones and tablets. Playing the file in VLC, which brings its own decoders, will normally confirm it.
What is the difference between MKV and WebM?
WebM is Matroska with a short guest list. It uses the same structure but allows only royalty-free codecs: VP8, VP9 or AV1 for the picture, Vorbis or Opus for the sound. Every WebM is a valid Matroska file; most MKVs are not valid WebM, because they hold codecs such as H.264 or AAC.
Why is an MKV sometimes bigger than the same video as an MP4?
Because it is not the same video. The container itself adds a negligible amount, well under one per cent. If two versions of a film differ in size, they differ in what is inside: a higher bitrate, a different codec, a lossless soundtrack, or three extra audio tracks. Look inside both and the reason will be obvious.

Keep learning

Data & encoding All about codecs What goes inside the box: how an hour of video shrinks from 75 GB to one, and which codec is which. Data & encoding WAV, FLAC and MP3 The audio side of the same story: lossless, lossy, and the wrapper AVI borrowed. Storage & media Convert VHS tapes to digital yourself Containers in practice: capture to MKV, fix the picture shape, make an MP4 to share.