ffmpeg burned-in subtitles render in the wrong font

Question:

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, 
              "-y",
              "-c:v", "prores", "-profile:v", "1", 
              "-c:a", "pcm_s16be", 
              "-vf", f"subtitles={srt_uri}:fontsdir=/Projects/Fonts:force_style='Fontname=GothaProBol.otf'",
              f"{self.source_video_uri}_render.mov"]

subprocess.call(ffmpeg_cmd)

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_FONTPROVIDER_NONE       = 0,
    ASS_FONTPROVIDER_AUTODETECT = 1,
    ASS_FONTPROVIDER_CORETEXT,
    ASS_FONTPROVIDER_FONTCONFIG,
    ASS_FONTPROVIDER_DIRECTWRITE,
} 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.

Asked By: dv151

||

Answers:

Do not put the file extension in the font name:

force_style='fontname=GothamPro-Bold'

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
Answered By: Hernán Alarcón

I got the custom fonts working in FFMPEG subtitles filter.
(I’m using a Mac and FFMPEG-PYTHON which is just a wrapper around FFMPEG).

I also have the font files in a folder local to my project.(./fonts) and changing the font file name or using the font name shown in Mac’s Font-Book doesn’t work.

So here is how I got it working…

  1. Open the font file in Font Forge you can download it here – FontForge.

  2. Click on the Elements tab and then Font Info

  3. You can see the font name on the top
    Font Info

  4. Use the font name exactly as you see it as the FFMPEG force_style args
    fontsdir='./fonts',force_style='FontName=HelveticaRoundedLTStd-BdCn,PrimaryColour=0x7FFFD4,Fontsize= 26

Here are my terminal logs showing that it’s loading the custom font.

Terminal Logs

Hope this helps

Answered By: NavinDev

I’ve been trying to solve the same problem all evening, finally figured it out.

OP said that ‘Game of Thrones.ttf’ didn’t work but ‘GothaProBol.otf’ did.

So I used an online tool to convert my custom font from .ttf to .otf

Then copied my custom font into /Library/Fonts/fontname.otf

Then used the POSTSCRIPT-NAME from Font Book and it worked beautifully 🙂

ffmpeg -i input.mp4 -vf "subtitles=subtitle.ass:force_style='Fontname=CUSTOMfontBlack-Regular'" output.mp4
Answered By: Marcus
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.