Ffmpeg Burned-in Subtitles Render In The Wrong Font

- 1 answer

Trying to burn in subtitles to a video in FFMPEG in GothamProBold font. No matter what I do it keeps reverting to Helvetica. From the console, I see that FFMPEG seems to load the font without error. Then switches over to font provider "coretext"

[Parsed_subtitles_0 @ 0x7fed054048c0] Loading font file '/Projects/Fonts/GothaProBol.otf'
[Parsed_subtitles_0 @ 0x7fed054048c0] Using font provider coretext
[Parsed_subtitles_0 @ 0x7fed054048c0] fontselect: (GothaProBol.otf, 400, 0) -> /System/Library/Fonts/Helvetica.ttc, -1, Helvetica

It seems like it has my font loaded, then loads what is likely a system default of Helvetica instead. My guess is that my chosen font isn't actually loading after all.

FFMPEG command (called from python) is as follows:

ffmpeg_cmd = ["ffmpeg", 
              "-i", self.source_video_uri, 
              "-c:v", "prores", "-profile:v", "1", 
              "-c:a", "pcm_s16be", 
              "-vf", f"subtitles={srt_uri}:fontsdir=/Projects/Fonts:force_style='Fontname=GothaProBol.otf'",

Any ideas?

UPDATE: Found this setting in libass header file "ass.h" - which ffmpeg calls when using the subtitle filter. Don't know how to actually set this variable when ffmpeg calls libass, but here it is. Line 182:

 * \brief Default Font provider to load fonts in libass' database
 * NONE don't use any default font provider for font lookup
 * AUTODETECT use the first available font provider
 * CORETEXT force a CoreText based font provider (OS X only)
 * FONTCONFIG force a Fontconfig based font provider
 * libass uses the best shaper available by default.
typedef enum {
} ASS_DefaultFontProvider;

RE: ANSWER BELOW: For the most part, it seems that if your font is installed in /System/Fonts or /Library/Fonts then CoreText can find it. Though in some cases, the naming conventions can be quite particular and non-intuitive. It also can't seem to find all fonts, necessarily.

For example: Gotham Pro Bold, in the /Library/Fonts folder on my system, file named "GothaProBol.otf" is correctly passed to fontname as: GothamPro-Bold or just Gotham Pro. Gotham Pro Bold, GothamPro, Gotham Pro-Bold, GothaProBol, and GothaProBol.otf do NOT work.

For most fonts it seems the preferred convention is {FontName}-{Style/Weight} as displayed in Mac OS's FontBook, not the filename.

That said, I have a novelty 'Game of Thrones.ttf' font in the same folder as Gotham Pro, and I can't get CoreText to connect to it under any of the above naming conventions.



Do not put the file extension in the font name:


In my case I got a file called GothamPro-Bold.otf and the output was like this:

[Parsed_subtitles_0 @ 0x55c809fd73c0] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 2.6.4 (COMPLEX)
[Parsed_subtitles_0 @ 0x55c809fd73c0] Loading font file './fonts/GothamPro-Bold.otf'
[Parsed_subtitles_0 @ 0x55c809fd73c0] Using font provider fontconfig
[Parsed_subtitles_0 @ 0x55c809fd73c0] fontselect: (GothamPro-Bold, 400, 0) -> GothamPro-Bold, 0, GothamPro-Bold