Inspect MKV Container Structure Using FFprobe
This guide explains how to analyze the internal architecture of a
Matroska (MKV) multimedia container using ffprobe, the
powerful media analysis tool included with FFmpeg. You will learn the
essential command-line flags required to reveal container-level
metadata, stream configurations, individual frame and packet
allocations, chapters, and track-specific properties in human-readable
and machine-parsable formats.
Basic Container and Stream Information
To get a complete overview of the streams (video, audio, subtitles) and general container metadata inside an MKV file, run:
ffprobe -v error -show_format -show_streams input.mkv-v error: Suppresses redundant FFmpeg build information and logs, displaying only parsing errors and the requested output.-show_format: Displays container-level attributes, including duration, file size, bit rate, and global tags.-show_streams: Lists technical parameters for each track, such as codecs, frame rates, pixel formats, channel layouts, and stream indices.
Filtering by Stream Type
MKV files often contain multiple tracks, such as alternate audio
tracks or multilingual subtitles. Use -select_streams to
inspect a specific stream type:
Video only:
ffprobe -v error -select_streams v -show_streams input.mkvAudio only:
ffprobe -v error -select_streams a -show_streams input.mkvSubtitles only:
ffprobe -v error -select_streams s -show_streams input.mkv
Inspecting Packets and Frames
To examine the low-level data structure of an MKV container, inspect the packets (demuxed data chunks) and frames (decoded presentation units).
Packet Inspection
Viewing packet data reveals how video and audio samples are interleaved throughout the container:
ffprobe -v error -show_packets -select_streams v:0 -read_intervals "%10" input.mkv-show_packets: Outputs PTS (Presentation Time Stamp), DTS (Decoding Time Stamp), packet size, duration, and stream mapping.-read_intervals "%10": Restricts analysis to the first 10 seconds to prevent huge terminal logs.
Frame-by-Frame Analysis
To analyze keyframe placement and frame types (I, P, B frames) in the video track:
ffprobe -v error -select_streams v:0 -show_frames -show_entries frame=pict_type,pts_time,key_frame,pkt_size -read_intervals "%5" input.mkv-show_entries: Narrows the output to essential attributes, minimizing clutter.
Extracting Chapters and Attachments
MKV containers natively support embedded chapters and attachments (such as font files for subtitles).
Viewing Chapters
ffprobe -v error -show_chapters input.mkvThis lists chapter IDs, start and end timestamps, and embedded chapter title tags.
Checking for Attachments
MKV attachments are recognized by ffprobe as distinct
streams with a codec type of attachment:
ffprobe -v error -select_streams t -show_streams input.mkvFormatting the Output
By default, ffprobe prints data in an
[INI]-style key-value format. You can change this structure
into common interchange formats for scripting or automated
processing.
JSON format:
ffprobe -v error -show_format -show_streams -of json input.mkvXML format:
ffprobe -v error -show_format -show_streams -of xml input.mkvFlat format (ideal for
grepand shell parsing):ffprobe -v error -show_format -show_streams -of flat input.mkv