MKV - Matroska Multimedia Container
MKV is the Matroska container, an open format that can hold any number of video, audio and subtitle tracks plus chapters and attachments in a single file.
MKV is short for Matroska, an open container format begun in 2002 by Steve Lhomme and a group of contributors who wanted a video file nobody owned and nothing limited. The name comes from the Russian nesting doll, and it describes the idea well: a Matroska file is a box that can hold whatever you put in it. Where MP4 accepts a defined set of codecs and features, Matroska was written to accept anything, which is why it became the format of choice for film archives, anime with multiple subtitle sets, and Blu-ray discs copied to a hard drive. Its underlying structure has since been published as an internet standard, and Google reused a subset of it to create WebM.
How an MKV file is put together
Matroska is built on EBML, a binary structure that works like a compact version of XML: everything is an element, elements nest inside one another, and each one declares its own length. A file consists of a header, then a segment holding the tracks, an index for seeking and the media itself, split into clusters of small blocks with timestamps.
MKV compresses nothing on its own. The picture inside is usually H.264, HEVC, AV1 or VP9; the sound can be AAC, Opus, FLAC, DTS or Dolby audio, among others. Because the container is indifferent to what it holds, one file can carry a lossless audio track next to a compressed one, several dubs, forced and full subtitle sets in text or bitmap form, chapter marks for scene selection, and attachments: cover art, or the exact font a subtitle track needs in order to look right.
What metadata an MKV file carries
Matroska keeps metadata in two places, and both show up in a report.
The segment information block describes the file itself. It holds the overall title, the duration, a creation date in UTC, a unique identifier for the segment, and two revealing fields: the muxing application and the writing application, which name the library and the program that produced the file, often with their version numbers. Every track then has its own entry giving a name, a language code, the codec, display dimensions, and flags marking a track as default or forced.
Descriptive metadata uses Matroska's tag system, which is more structured than most. Tags are grouped by target, so a tag can apply to the whole file, to one track, to a chapter or to an album-like collection above it, and each tag is a name and a value. The conventional names are written in capitals, and the ones you meet most are title, artist, date released, genre, comment, description, encoder, part number and total parts. A tag can also state which language it is written in, so the same field can appear more than once for different audiences.
What Matroska does not normally carry is camera metadata. There is no EXIF block, no camera model and no GPS field, because MKV files are usually made by converting or copying something else rather than by a camera. The personal traces are of a different kind: the writing application says which program and version you used, the creation date says when, the title and track names very often preserve the name of the original release or the disc, and an attachment can be any file at all, including one somebody left in there.
When to choose MKV
Use MKV when the file is a keeper. It is the best container here for a film with several audio languages, subtitle tracks you want to switch between, and chapters, and it tolerates unusual codecs without complaint.
MP4 is the alternative, and it wins on reach: browsers, phones, televisions and set-top boxes play MP4 without help, while MKV support depends on the device and on many players being installed. A reasonable habit is to archive in MKV and hand out MP4. Moving between the two is often just a remux, copying the streams into a different wrapper with no loss, as long as the codecs inside are ones MP4 accepts.