Extract Fonts from MKV Using FFmpeg
MKV containers often store embedded attachments, such as custom TrueType (TTF) or OpenType (OTF) fonts, to ensure subtitles render correctly during playback. This guide provides a quick and direct tutorial on how to identify these attached fonts and extract them from an MKV file using the FFmpeg command-line tool.
Step 1: Identify the Attached Fonts
Before extracting, you need to check which fonts are embedded in the MKV container. Run the following command in your terminal to list all streams and attachments within the file:
ffmpeg -i input.mkvLook through the output for lines labeled Attachment. They will look similar to this:
Stream #0:3: Attachment: ttf
Metadata:
filename : Arial-Bold.ttf
mimetype : application/x-truetype-font
Note the stream index (e.g., 0:3) or the filename if you
wish to extract a specific font.
Step 2: Extract All Fonts at Once
The easiest way to retrieve all embedded fonts from the MKV container
is to dump all attachments at once. Use the
-dump_attachment:t option with an empty string to
automatically save every font attachment under its original
filename:
ffmpeg -dump_attachment:t "" -i input.mkvThis command will extract all font files and save them directly into your current working directory.
Step 3: Extract a Specific Font
If you only want to extract a single specific font, you can target it
using its filename. Use the following command, replacing
Arial-Bold.ttf with the actual filename of the font you
want to extract:
ffmpeg -dump_attachment:t "Arial-Bold.ttf" -i input.mkvAlternatively, you can extract a font by its stream index. For
example, to extract the first attachment stream (index 0) and save it as
output_font.ttf, use:
ffmpeg -dump_attachment:t:0 output_font.ttf -i input.mkv