I have a .ass file that I want to mux into a video that requires additional fonts.
There seems to be no option to copy the attachments from one file to another, so I dumped them all using
ffmpeg -dump_attachment:t "" -i input.mkv
But how do I get them into the new file correctly?
I have tried the following:
ffmpeg -i input.mkv -c copy -attach "fontastique.ttf" -metadata:s: mimetype=application/x-truetype-font -attach "Franchise - Extra.ttf" -metadata:s: mimetype=application/x-truetype-font -attach "Painfresco-Italic.ttf" -metadata:s: mimetype=application/x-truetype-font -attach "Painfresco-Regular.ttf" -metadata:s: mimetype=application/x-truetype-font -attach "SETFIRETOTHERAIN.TTF" -metadata:s: mimetype=application/x-truetype-font -attach "Volter__28Goldfish.ttf" -metadata:s: mimetype=application/x-truetype-font output.mkv
the fonts seem to be attached, but all streams, including video/audio/subtitles, will then show up with a set mimetype of the fonts.
Stream #0:1: Audio: aac, 44100 Hz, stereo, fltp (default) (forced)
Metadata:
MIMETYPE : application/x-truetype-font
Stream #0:2: Subtitle: ssa (default) (forced)
Metadata:
MIMETYPE : application/x-truetype-font
Codec 0x18000 is not in the full list.
Stream #0:3: Attachment: unknown_codec
Metadata:
filename : fontastique.ttf
mimetype : application/x-truetype-font
...etc...
The subtitles cannot find the font because it still appears as default font of the player, not the attached ones.
The documentations example says
ffmpeg -i INPUT -attach DejaVuSans.ttf -metadata:s:2 mimetype=application/x-truetype-font out.mkv
but I have no idea what -metadata:s:2 means, I thought it tells it what stream to attach it to, but using -metadata:s:2
, 2 being the subtitles stream, fails with
Could not write header for output file #0 (incorrect codec parameters ?): Error number -22 occurred
How do I correctly copy or attach multiple fonts to a MKV container to be used by a .ass subtitle stream?
Best Answer
First, you actually can copy fonts with
ffmpeg
. The-map
option overrides some defaults and selects all streams from the input. Example:Also see the FFmpeg Map documentation for more info.
For attaching fonts to an existing video, the
-metadata:s:2
option is indeed selecting stream 2, but if you look at yourmkvinfo
output you'll see that attachments are their own stream. They are not "attached" to the subtitle stream. So in the example in your question you would want-metadata:s:3
. And additional attachments should use corresponding stream specifiers.