How to Extract Attachments from MKV with FFmpeg
This guide explains how to extract attached files, such as subtitle fonts, images, or documentation, from an MKV (Matroska) video container using the FFmpeg command-line tool. You will learn how to inspect the contents of an MKV file to locate attachments and run the precise commands needed to extract either all attachments at once or specific individual files.
Step 1: List the Attachments in the MKV File
Before extracting, you should inspect the MKV container to see what attachments are inside and identify their stream indexes or filenames. Run the following command in your terminal:
ffmpeg -i input.mkvLook at the output details. Near the bottom, you will see the stream
listings. Attachments are labeled as Attachment and look
similar to this:
Stream #0:3: Attachment: ttf
Metadata:
filename : Arial.ttf
mimetype : application/x-truetype-font
Take note of the filename and the attachment index (e.g.,
0:3 or the relative attachment index t:0,
t:1, etc.).
Step 2: Extract All Attachments at Once
The easiest way to get all fonts and files out of the MKV container is to dump them all simultaneously. FFmpeg allows you to do this using their original filenames.
Run the following command:
ffmpeg -dump_attachment:t "" -i input.mkv -f null --dump_attachment:t "": Instructs FFmpeg to extract all attachments of typet(attachments) using their original embedded filenames.-i input.mkv: Specifies your input file.-f null -: Prevents FFmpeg from trying to render or output a dummy video file, making the process instant.
Step 3: Extract a Specific Attachment
If you only want to extract a single file (for example, the first font stream) and rename it, you can specify the attachment index.
Run this command:
ffmpeg -dump_attachment:t:0 "extracted_font.ttf" -i input.mkv -f null --dump_attachment:t:0: Extracts only the first attachment (index0). If you wanted the second attachment, you would uset:1."extracted_font.ttf": The name you want to give the extracted file.