What Is MKV Format (Matroska Video File)?
Matroska Multimedia Container is a free and open container video format that allows you to store an unlimited number of video, audio, image or subtitle tracks in a single file.
MKV is a universal format for storing multimedia content such as movies and TV shows. Although it is similar to other containers such as AVI, MP4, and Advanced Systems Format (ASF), its specifications are fully open and its implementation consists mostly of open source software.
MKV is supported by a non-profit organization called Association Loi 1901. It is a royalty-free standard provided under the GNU L-GPL license. MKV analysis and playback libraries are provided under the BSD license for commercial enterprise use.
The Matroska file extension is .mkv for video (which may also contain subtitles or audio), .mk3d for stereoscopic video, .mka for audio-only files, and .mka for subtitles only.
In this article:
- MKV Format: History and Goals
- MKV File Format Technical Deep Dive
- MKV vs. MP4
- Automated Video Format Conversion with Cloudinary
MKV Format: History and Goals
Launched in December 2002, the Matroska project split from the Multimedia Container Format (MCF) after a disagreement between Steve Lhomme and Lasse Kärkkäinen, the lead developer of MCF, regarding the use of Extensible Binary Meta Language (EBML). Lhomme founded Matroska and many developers moved to the new project in response to the MCF lead developer’s break from coding.
The developers of Matroska emphasized the advantages of using EBML rather than a different binary format. These include making the format more future-proof and easier to extend to accommodate changing goals and new developments. The MKV format’s design considers extensibility and longevity, unlike other formats like AVI.
Matroska team members have openly discussed the project’s long-term goals on hydrogenaudio.org and doom9.org. The project aims to create a modern, extensible, flexible container format that works across multimedia platforms. It also seeks to provide strong streaming support, specialized file creation and editing tools, development support libraries to extend Matroska support to applications, and EBML-based menus.
The Matroska team collaborates with third-party hardware manufacturers to embed Matroska support in various multimedia devices. The project also encourages operating systems to offer native support for Matroska.
MKV File Format Technical Deep Dive
Matroska introduces several constraints to the EBML header’s specification:
- The document type (docType) must be Matroska.
- The maximum ID length (EBMLMaxIDLength) is 4.
- The maximum size (EBMLMaxSizeLength) must be from 1 to 8.
The top-level elements must all be coded in four octets, according to the following principles:
- Language codes – versions 1-3 of Matroska use language codes with the three bibliographic ISO-639-2 form letters (i.e., “eng” for English) and an optional country code (i.e., “eng-ca” for Canadian English). From version 4 and up, Matroska supports both ISO 639-2 and BCP 47 MAY for language codes, although the latter is the recommended option.
- Physical types – these mean different things for video and audio files. For instance, a ChapterPhysicalEquiv of 60 means DVD, VHS, and laserdisc for video. However, it means CD (12, 10, and 7 inches), tape, minidisc, and DAT for audio.
- Block structure—the block header includes information about the type of lacing, timestamps, track number, etc.
- Lacing – this mechanism saves space when storing the data for small data use cases like individual frames.
- Simple block structure – based on the block structure, this structure adds “discardable” and “keyframe” flags.
Matroska documents must comprise at least one EBML document of the Matroska document type. Every EBML document starts with an EBML header, followed by an EBML root element defined as a segment – various top-level elements can occur within a segment.
EBML involves a system of “elements” for composing a document. Matroska defines the following as top-level elements in a Matroska file:
- EBML document – the file’s wrapper.
- EBML header – contains the file’s header information, such as the document type, etc.
- Segment – the top element containing the rest of the top-level elements.
- Seek head – defines the position of the segments of different top-level elements.
- Info – provides general information about the segment.
- Tracks – an information element describing various tracks.
- Chapters – an element defining basic menu and partition information.
- Cluster – contains the block structure.
- Cues – an element containing all the segment’s local entries.
- Attachments – an element containing any attached files.
- Tags – an element containing metadata to describe tracks, editions, chapters, attachments, or the overall segment.
MKV vs MP4
MP4 stands for MPEG-4 Part 14. It is part of the Motion Picture Experts Group’s audio and video file standards. Here are the key differences between MKV and MP4:
- License—MKV is a free standard, while MP4 (defined in the ISO/IEC 14496-14 standard) is a patent-protected format that uses DRM to restrict copying.
- Format support—MKV can store an unlimited number of multimedia content such as video, audio, images, subtitle tracks, etc. It is commonly used for movies and TV shows and supports almost all video/audio encoding formats. MP4 supports only specific audio and video formats (for example, MPEG-2/4 (HE)-AAC for audio and H.264/MPEG-4 AVC for video). MP4 also supports some compression formats that are not supported by MKV, such as Apple Lossless and Opus.
- Encoding—both MKV and MP4 can encode to the HEVC/H.265 video codec format, supporting UHD resolutions 4K/2160p and 8K/4320p. However, MKV supports some codecs that are not allowed in MP4. Learn more in our guide to video codecs.
- Audio support—MKV supports Free Lossless Audio Codec (FLAC) audio while MP4 does not. This is an audio encoding format used for lossless compression of digital audio that is superior to many other audio formats. MP4 supports lossless audio via Apple Lossless Audio Codec (ALAC), which is considered less efficient than FLAC.
- File size—MKV usually has a larger file size than MP4 video because it supports additional features, multiple audio tracks, and subtitle tracks.
How to choose:
- Prefer MP4 if you need a highly compatible format that is widely supported by mobile devices. It is a better choice if you need to download to transmit video content over the Internet.
- Prefer MKV if you need high-definition video and don’t mind a large file size, and if you need to support one of the codecs that MKV supports and MP4 does not.
Automated Video Format Conversion With Cloudinary
Cloudinary offers a versatile, effective, and efficient solution for managing media, replete with dynamic, automated optimization and delivery features. For example, setting the fetch_format parameter to auto (f_auto in URLs) causes Cloudinary to automatically select the format and codec based on the requesting browser. Chrome users would most likely receive a VP9-encoded WebM file; Safari users, an HEVC-encoded MP4 file. If a browser does not support either of those formats, Cloudinary delivers the video as an H.264-encoded MP4 file, which works in almost all browsers.
Interested? Have a try for free by first signing up for a free Cloudinary account.