Matroska (.mkv, .webm, .mka, .mk3d)
Background & Context
-
- Registered MIME types: video/x-matroska
- Multimedia container format.
- Can contain multiple video, audio and subtitle tracks.
- Designed to be flexible, extensible and cross-platform.
- Supports a variety of video and audio codecs.
- Extended MCF and EBML and is the base for WebM.
- An open format initially released in 2002.
Import & Export
- Export["file.mkv",expr,elements] exports by treating expr as corresponding to the specified elements.
- Import["file.mkv"] imports a Matroska file and returns a Video object.
- Import["file.mkv",elem] imports the specified elements.
- The import format can be specified with Import["file","Matroska"] or Import["file",{"Matroska",elem,…}].
- Export["file.mkv",expr] exports expr to the Matroska format.
- The following expressions can be exported to a Matroska:
-
video an arbitrary Video object AnimatedImage[…] frames of an AnimatedImage object Manipulate[…] frames generated from a Manipulate expression {expr1,expr2,…} a list of images, graphics or rasterized expressions - When exporting a list of arbitrary expressions, each expression is rasterized and has the same raster size as its displayed form.
- The duration of the Matroska video is determined from the number of frames and the specified frame rate.
- If bookmarks are set in the Manipulate object, Export will create a Matroska file by interpolating between the bookmarks while preserving the speed and duration of the Manipulate.
- Export["file.mkv",{elem1expr1,elem2expr2,…},"Rules"] uses rules to specify the elements to be exported.
- Supported video encoders are listed in $VideoEncoders.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - Video representation elements:
-
"ImageList" frames represented as a list of images "Video" video file represented as a Video object "VideoData" array of raw bitmap data for each frame "VideoStream" a handle to the video file as a VideoStream object - Import by default uses the "Video" element for the Matroska format.
- A video file may contain multiple video, audio or subtitle tracks. Elements that return the number of tracks:
-
"AudioTrackCount" number of audio tracks "SubtitleTrackCount" number of subtitle tracks "VideoTrackCount" number of video tracks - Video metadata elements:
-
"BitDepth" bits used to represent each color channel in the file "ColorSpace" color encoding used in the file "FrameCount" number of frames in the file "FrameDurations" list of display durations given for each frame "FrameRate" number of frames to be displayed per second "ImageSize" raster dimensions "VideoEncoding" video codec used in the file - Audio-related elements:
-
"Audio" in-core Audio object "AudioChannels" number of audio channels "AudioData" array of audio samples "AudioEncoding" audio codec used in the file "AudioFile" out-of-core Audio object "BitRate" number of bits per second "SampleRate" number of audio samples per second - Subtitle-related elements:
-
"RawSubtitle" subtitle data imported as a raw string "SubtitleRules" returned as a list of styled text in the form of {int1text1,int2text2,…} "SubtitleString" returned as a single string of concatenated subtitle texts "SubtitleStringRules" returned as a list of plaintext in the form of {int1string1,int2string2,…} "SubtitleEncoding" subtitle codec used in the file - Additional metadata elements:
-
"ExactDurations" an association of exact durations for all video, audio and subtitle tracks "ExactTimeBoundaries" an association of exact start and end times for all video, audio and subtitle tracks "Duration" approximate duration of the video given in seconds "MetaInformation" metadata interpreted as quantities, locations, dates, numbers, etc. "RawMetaInformation" uninterpreted metadata as strings and numbers "Summary" summary of the file "TrackStartTimes" an association of start times for each track - $VideoDecoders and $AudioDecoders give a list of decoders available on your computer system.
Export Elements
- Export["file.mkv",{elem1->expr1,…},"Rules"] uses rules to specify the elements to be exported.
- Available Export elements:
-
"Audio" an audio track "Frames" video frames provided as a list, a Manipulate or an AnimatedImage object
Options
- General Import options:
-
AudioTrackSelection 1 audio tracks of interest "ImageTopOrientation" Automatic orientation of the video as stored in the file RasterSize Automatic raster dimensions SubtitleTrackSelection 1 subtitle tracks of interest VideoTrackSelection 1 video tracks of interest - Import options for the "Audio" element:
-
"AudioChannels" Automatic number of audio channels SampleRate Automatic samples per second for each channel - General Export options:
-
AudioEncoding Automatic audio encoding for file Background Automatic background color BitRate Automatic approximate bit rate to use CompressionLevel Automatic compression level to use FrameRate Automatic number of frames shown per second IncludeMetaInformation All whether to export metadata MetaInformation Automatic metadata to export RasterSize Automatic pixel dimensions SampleRate Automatic audio samples per second for each channel SubtitleEncoding Automatic subtitle encoding for file VideoEncoding Automatic video encoding for file VideoTransparency False whether to export the transparency channel - Export options for the "Video" and "VideoStream" elements:
-
AudioTrackSelection All audio tracks of interest SubtitleTrackSelection All subtitle tracks of interest VideoTrackSelection All video tracks of interest - Export options when exporting Manipulate expressions:
-
"AnimationDuration" Automatic total animation duration "ControlAppearance" Automatic how Manipulate control elements are rendered in the exported file - The following settings can be given for "ControlAppearance":
-
Automatic captures user controls exactly as seen in the notebook interface, using the style elements of the local computer system "Generic" renders graphical controls in a generic style None excludes control elements when exporting an animation - $VideoEncoders and $AudioEncoders give a list of encoders available on your computer system.
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Import a Matroska file as a Video object:
https://wolfram.com/xid/0bp2r40yui98-nw3d9f
Import a video property such as duration:
https://wolfram.com/xid/0bp2r40yui98-lm2of0
Import a summary of a video file:
https://wolfram.com/xid/0bp2r40yui98-p0h8ry
Export a Video object to an MP4:
https://wolfram.com/xid/0bp2r40yui98-xmj01x
Scope (6)Survey of the scope of standard use cases
Import (2)
Export (4)
Export a list of images to Matroska:
https://wolfram.com/xid/0bp2r40yui98-lt8vx4
https://wolfram.com/xid/0bp2r40yui98-b446dt
Get three frames from the video:
https://wolfram.com/xid/0bp2r40yui98-u64no
Export a Manipulate to Matroska:
https://wolfram.com/xid/0bp2r40yui98-2hez7z
https://wolfram.com/xid/0bp2r40yui98-qqfv4i
https://wolfram.com/xid/0bp2r40yui98-begsw1
Export an AnimatedImage object:
https://wolfram.com/xid/0bp2r40yui98-4edufw
https://wolfram.com/xid/0bp2r40yui98-uohjya
Export a Manipulate with audio:
https://wolfram.com/xid/0bp2r40yui98-wcboh4
https://wolfram.com/xid/0bp2r40yui98-ozqghu
https://wolfram.com/xid/0bp2r40yui98-m9dyij
https://wolfram.com/xid/0bp2r40yui98-53o9lp
Import Elements (32)
Available Elements (1)
Video Elements (3)
"Video" (1)
Import as a Video object:
https://wolfram.com/xid/0bp2r40yui98-zf5pe6
This is the default import element:
https://wolfram.com/xid/0bp2r40yui98-gm1sw0
"VideoData" (1)
Import video data corresponding to specified frames:
https://wolfram.com/xid/0bp2r40yui98-b7d8y
Convert video data stored in a NumericArray object to an image:
https://wolfram.com/xid/0bp2r40yui98-byez1j
"VideoStream" (1)
Import as a VideoStream object:
https://wolfram.com/xid/0bp2r40yui98-duhuu9
https://wolfram.com/xid/0bp2r40yui98-j7wwev
Get the current frame from the stream:
https://wolfram.com/xid/0bp2r40yui98-kpicqc
Number of Tracks (3)
"AudioTrackCount" (1)
"SubtitleTrackCount" (1)
Metadata Elements (7)
"Duration" (2)
"ExactDurations" (2)
https://wolfram.com/xid/0bp2r40yui98-2fzw6o
Import the approximate duration of the video:
https://wolfram.com/xid/0bp2r40yui98-53a15d
Computing an approximate duration is typically much faster than exact durations:
https://wolfram.com/xid/0bp2r40yui98-o3o5zh
"MetaInformation" (1)
"RawMetaInformation" (1)
Video Tracks (7)
"BitDepth" (1)
"ColorSpace" (1)
"FrameCount" (1)
"FrameDurations" (1)
"FrameRate" (1)
"RasterSize" (1)
"VideoEncoding" (1)
https://wolfram.com/xid/0bp2r40yui98-mg77er
Supported decoders for Matroska on each platform can be extracted using $VideoDecoders:
https://wolfram.com/xid/0bp2r40yui98-hpp4b8
Audio Tracks (6)
"Audio" (1)
"AudioChannels" (1)
"AudioData" (1)
Import audio data from a Matroska file as a NumericArray:
https://wolfram.com/xid/0bp2r40yui98-cyc22v
Convert audio data stored to an Audio object:
https://wolfram.com/xid/0bp2r40yui98-jkb79x
"AudioEncoding" (1)
https://wolfram.com/xid/0bp2r40yui98-hyhef1
Available audio decoders can be extracted from $AudioDecoders:
https://wolfram.com/xid/0bp2r40yui98-cv0bz4
"BitRate" (1)
Subtitle Tracks (5)
"RawSubtitle" (1)
Get raw subtitles from a Matroska file:
https://wolfram.com/xid/0bp2r40yui98-ccwe5s
None is returned if subtitles are not present.
"SubtitleEncoding" (1)
https://wolfram.com/xid/0bp2r40yui98-i5bypm
Available subtitle encodings can be extracted using $SubtitleDecoders:
https://wolfram.com/xid/0bp2r40yui98-km9br2
"SubtitleRules" (1)
Get subtitles as a list of styled text:
https://wolfram.com/xid/0bp2r40yui98-kcmd0w
None is returned if subtitles are not present.
"SubtitleString" (1)
Get subtitles as a single string:
https://wolfram.com/xid/0bp2r40yui98-t123b
None is returned if subtitles are not present.
"SubtitleStringRules" (1)
Get subtitles as a list of plaintext:
https://wolfram.com/xid/0bp2r40yui98-e7zasd
None is returned if subtitles are not present.
Import Options (7)
"AudioChannels" (1)
AudioTrackSelection (1)
By default, Import extracts data only from the first audio track:
https://wolfram.com/xid/0bp2r40yui98-cybc0a
Use the AudioTrackSelection option to extract data from specified audio tracks:
https://wolfram.com/xid/0bp2r40yui98-h24db6
"ImageTopOrientation" (1)
RasterSize (1)
SampleRate (1)
SubtitleTrackSelection (1)
By default, Import extracts data only from the first subtitle track:
https://wolfram.com/xid/0bp2r40yui98-fr79bh
Use the SubtitleTrackSelection option to extract data from specified subtitle tracks:
https://wolfram.com/xid/0bp2r40yui98-3f5qe
VideoTrackSelection (1)
By default, Import extracts data only from the first video track:
https://wolfram.com/xid/0bp2r40yui98-evblh
Use the VideoTrackSelection option to extract data from specified video tracks:
https://wolfram.com/xid/0bp2r40yui98-od1vxh
Export Options (22)
"AnimationDuration" (1)
Specify the duration of exported Manipulate expressions:
https://wolfram.com/xid/0bp2r40yui98-etizxi
https://wolfram.com/xid/0bp2r40yui98-bt15mr
https://wolfram.com/xid/0bp2r40yui98-kgwhn
AudioEncoding (1)
AudioTrackSelection (1)
By default, all audio tracks are exported:
https://wolfram.com/xid/0bp2r40yui98-f2mrz3
https://wolfram.com/xid/0bp2r40yui98-c7yo0n
Specify the audio tracks to export:
https://wolfram.com/xid/0bp2r40yui98-46ob0
https://wolfram.com/xid/0bp2r40yui98-fl023r
https://wolfram.com/xid/0bp2r40yui98-ouhq31
https://wolfram.com/xid/0bp2r40yui98-o0uhd
Background (1)
By default, a white background is used for transparent graphics and images and also when images of different sizes are padded before export:
https://wolfram.com/xid/0bp2r40yui98-h4y8r
https://wolfram.com/xid/0bp2r40yui98-4le0h
https://wolfram.com/xid/0bp2r40yui98-1eg6w
https://wolfram.com/xid/0bp2r40yui98-h4jcu7
https://wolfram.com/xid/0bp2r40yui98-nvl1zs
BitRate (4)
By default, automatic bit rate is used when exporting to video files:
https://wolfram.com/xid/0bp2r40yui98-e55jv1
Check an overall approximate bit rate:
https://wolfram.com/xid/0bp2r40yui98-mr55n8
Suggest an approximate bit rate:
https://wolfram.com/xid/0bp2r40yui98-8htjmu
Check the approximate bit rate that might slightly differ from the suggested one:
https://wolfram.com/xid/0bp2r40yui98-5w73bu
Separately specify the approximate video and audio bit rates:
https://wolfram.com/xid/0bp2r40yui98-bfev7k
Check an overall approximate bit rate:
https://wolfram.com/xid/0bp2r40yui98-doe7wx
Smaller bit rate results in smaller file size but also lowers the quality of the generated video:
https://wolfram.com/xid/0bp2r40yui98-obp03
CompressionLevel (2)
Use the CompressionLevel option to control the file size and the quality of generated video:
https://wolfram.com/xid/0bp2r40yui98-d4h7rv
When BitRate for both video and audio is specified, the value of CompressionLevel is ignored:
https://wolfram.com/xid/0bp2r40yui98-dvsckh
https://wolfram.com/xid/0bp2r40yui98-utkek
"ControlAppearance" (1)
An animation exported with the default setting "ControlAppearance"Automatic will look different depending on the computer system on which it was created:
https://wolfram.com/xid/0bp2r40yui98-w0feb
https://wolfram.com/xid/0bp2r40yui98-i1j2wt
https://wolfram.com/xid/0bp2r40yui98-ld44so
With "ControlAppearance"None, no user controls are included in the exported video:
https://wolfram.com/xid/0bp2r40yui98-760tl
https://wolfram.com/xid/0bp2r40yui98-cppidl
FrameRate (1)
By default, the frame rate is preserved when exporting Video or VideoStream objects:
https://wolfram.com/xid/0bp2r40yui98-d0mezo
https://wolfram.com/xid/0bp2r40yui98-e7fguw
https://wolfram.com/xid/0bp2r40yui98-i560cy
Specify a different frame rate:
https://wolfram.com/xid/0bp2r40yui98-pv2ke
https://wolfram.com/xid/0bp2r40yui98-gd9m3c
IncludeMetaInformation (1)
MetaInformation (2)
By default, all supported metadata from the input video file are exported:
https://wolfram.com/xid/0bp2r40yui98-ijo7b
https://wolfram.com/xid/0bp2r40yui98-dxbyyg
Compare with the metadata from the original file:
https://wolfram.com/xid/0bp2r40yui98-ead9t
Matroska supports free form key-value metadata pairs:
https://wolfram.com/xid/0bp2r40yui98-4w2e1n
https://wolfram.com/xid/0bp2r40yui98-buruiz
https://wolfram.com/xid/0bp2r40yui98-uv6hv
RasterSize (1)
By default, the raster size is preserved when exporting Video or VideoStream objects:
https://wolfram.com/xid/0bp2r40yui98-ctda03
https://wolfram.com/xid/0bp2r40yui98-iceu9b
https://wolfram.com/xid/0bp2r40yui98-b7v3vu
Specify a different raster size:
https://wolfram.com/xid/0bp2r40yui98-by1sp5
https://wolfram.com/xid/0bp2r40yui98-clccgc
SampleRate (1)
By default, the sample rate is preserved when exporting Video, VideoStream or Audio objects:
https://wolfram.com/xid/0bp2r40yui98-d4o650
https://wolfram.com/xid/0bp2r40yui98-ddtbyi
https://wolfram.com/xid/0bp2r40yui98-fnrnbr
Specify a different sample rate:
https://wolfram.com/xid/0bp2r40yui98-emyhsv
https://wolfram.com/xid/0bp2r40yui98-bxlfo6
SubtitleEncoding (1)
SubtitleTrackSelection (1)
By default, all subtitle tracks are exported:
https://wolfram.com/xid/0bp2r40yui98-f76cc8
https://wolfram.com/xid/0bp2r40yui98-b3cv5y
Use the subtitle tracks to export:
https://wolfram.com/xid/0bp2r40yui98-jt3go0
https://wolfram.com/xid/0bp2r40yui98-s6opr
https://wolfram.com/xid/0bp2r40yui98-pn5xkg
https://wolfram.com/xid/0bp2r40yui98-mmruhi
VideoEncoding (1)
VideoTrackSelection (1)
By default, all video tracks are exported:
https://wolfram.com/xid/0bp2r40yui98-ejwe4x
https://wolfram.com/xid/0bp2r40yui98-d4w12b
Specify the video tracks to export:
https://wolfram.com/xid/0bp2r40yui98-onwqh
https://wolfram.com/xid/0bp2r40yui98-hkv3lx
https://wolfram.com/xid/0bp2r40yui98-qt8vp
https://wolfram.com/xid/0bp2r40yui98-gid3px
VideoTransparency (1)
Generate a video with an alpha channel:
https://wolfram.com/xid/0bp2r40yui98-dx5jo9
https://wolfram.com/xid/0bp2r40yui98-bm9km
By default, Export removes the transparency:
https://wolfram.com/xid/0bp2r40yui98-e2yqyn
https://wolfram.com/xid/0bp2r40yui98-c83m3l
Export a video with an alpha channel:
https://wolfram.com/xid/0bp2r40yui98-fidv3g
https://wolfram.com/xid/0bp2r40yui98-is0di0