solved: FFMPEG fontconfig woes on Windows

Hey future self: you forgot how to set up fontconfig for FFMPEG on Windows again? No worries older Stib, here’s how you did it last time (and also the time before that, but then you forgot and had to go searching for it).

For those who came into this conversation late, FFMPEG can do a lot more than convert video formats. I’ve been using it to add a clapper image to audio files so I can upload them to YouTube. The ffmpeg command I’ve been using creates a solid background, burns in the timecode and adds a text descriptor. But to get the drawtext filter to work I had to jump through a couple of hoops, mostly involving fontconfig.

Fontconfig is FOSS software that (I think) tells programs how to use fonts, it’s more of a linuxy thing than a windowsy thing, so it doesn’t necessarily work out of the box. In particular, FFMPEG’s text drawing filter drawtext needs to be told where to find things, because, um, it couldn’t just look in c:\windows\fonts for some reason?

Here’s what you need to do:

  1. fonts.confdownload the attached fonts.conf file. It’s a slightly updated version of one that’s floating around,  courtesy Keith Packard, but with redundant bits removed. Nothing fancy. If you want a seriously fun challenge, why not try and make your own, by reading the fontconfig docs. Or, you could try smacking yourself in the head with a skillet.
  2. Make a new folder in the FFMPEG install folder called fonts. Put the fonts.conf file you just downloaded in there.
  3. Now you need to set some environment variables. If this isn’t something you do much of have a look at this page, it walks you through it, but if you edit your $path etc more than once a year I highly recommend you install the free Rapid Environment Editor.
    Create three new environment variables:
    FC_CONFIG_DIR with the value path\to\folder\from\step2
    FONTCONFIG_PATH with the value path\to\folder\from\step2
    FONTCONFIG_FILE with the value “path\to\folder\from\step2\fonts.conf”
    where “path\to\folder\from\step2” is, obviously, the path to the folder you created in step 2. I’m nostalgic for linux so I put ffmpeg in a folder I created called c:\usr\local\bin, so the values look like “c:\usr\local\bin\fonts.conf” and so on. Note that the last variable has the name of the fonts.conf file at the end.

Now you should be good to go. You may have to refresh your shell for it all to kick in. If you’re interested, the ffmpeg command to take a wav file and add a clapper with timecode looks like this:

ffmpeg -f lavfi -i color=color=gray:size=1024x720 -i input.wav -vf drawtext=fontfile="SourceSansPro-Regular.ttf":fontsize=56:timecode='0\\:00\\:00\\:00':r=25:x=100:y=100,drawtext=fontfile="SourceSansPro-Regular.ttf":fontsize=36:text="this is some text":x=100:y=200 -preset veryfast -ar 48k -tune "stillimage" output.mp4

I probably could have used filtercomplex, but I’m irrationally scared of it.

Leave a Reply

Your email address will not be published. Required fields are marked *