ffmpeg drawtext fontfile error "Cannot find a valid font for family Sans"
Solution 1
2019 Windows builds seem to have changed syntax or something again; here's what works for me today:
-vf "drawtext=fontfile=C\\:/Windows/fonts/consola.ttf:fontsize=72:fontcolor='white':timecode='00\:00\:00\:00':rate=25:text='TCR\:':boxcolor=0x000000AA:box=1:x=860-text_w/2:y=960"
In my case, I'm running FFmpeg from PWD, not C:
, so I have to specify font path C:\
with escaped colon and forward-slash for folder/file path.
Solution 2
Omit double quotes ("
) around the whole filter, use them only for the path to font file and omit spaces after :
:
ffmpeg -i in.mp4 -vf drawtext=fontfile="E\:\\ffmpegTool\\bin\\arialbd.ttf":fontsize=30:fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\\\\:n+1}:box=1 -y out.mp4
Also, your path to the font file is suspicious - try using the default Windows font path
c:\Windows\Fonts\
,
so your command will be
ffmpeg -i in.mp4 -vf drawtext=fontfile="c\:\\Windows\\Fonts\\arialbd.ttf":fontsize=30:fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\\\\:n+1}:box=1 -y out.mp4
Related videos on Youtube
Moore
Designer by training. I'm interested in learning how to code.
Updated on September 18, 2022Comments
-
Moore almost 2 years
I'm using ffmpeg to burn frame number into video. I suspect the error has something to do with file path.
Here's my command
ffmpeg -i in.mp4 -vf "drawtext=fontfile='E\:\\ffmpegTool\\bin\\arialbd.ttf':fontsize=30: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\\\\:n+1}: box=1" -y out.mp4
I've tried this, this and this. They didn't work
Here's the error
ffmpeg version N-85091-g23ae3cc Copyright (c) 2000-2017 the FFmpeg developers built with gcc 6.3.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 57.100 / 55. 57.100 libavcodec 57. 88.100 / 57. 88.100 libavformat 57. 70.100 / 57. 70.100 libavdevice 57. 5.100 / 57. 5.100 libavfilter 6. 81.100 / 6. 81.100 libswscale 4. 5.100 / 4. 5.100 libswresample 2. 6.100 / 2. 6.100 libpostproc 54. 4.100 / 54. 4.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'E:\ffmpegTool\bin\00872.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42mp41 creation_time : 2017-04-01T08:35:15.000000Z Duration: 00:00:52.31, start: 0.000000, bitrate: 11442 kb/s Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 11130 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default) Metadata: creation_time : 2017-04-01T08:35:15.000000Z handler_name : Alias Data Handler encoder : AVC Coding Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default) Metadata: creation_time : 2017-04-01T08:35:15.000000Z handler_name : Alias Data Handler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help Fontconfig error: Cannot load default config file [Parsed_drawtext_0 @ 00000000010ab340] Cannot find a valid font for the family Sans [AVFilterGraph @ 00000000052c9280] Error initializing filter 'drawtext' with args 'fontfile=E\:\\ffmpegTool\\bin\\arialbd.ttf:fontsize=30: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\:n+1}: box=1' Error reinitializing filters! Failed to inject frame into filter network: No such file or directory Error while processing the decoded data for stream #0:0 Conversion failed!
Appreciate the help.
-
Moore about 7 yearsIt didn't work :( maybe it's the
Fontconfig error: Cannot load default config file
? -
MarianD about 7 yearsNo, default config file is *nix specific - it is the file
fonts.conf
(in the default directory/etc/fonts/
). You are using Windows - probably you wrote incorrect path. I edited my answer, see it. -
Moore about 7 yearsApparently it's the
fontcolor
that keeps making the error. I omitted one by one and this is the working codeffmpeg -i in.mp4 -vf drawtext=fontsize=40:x=(w-text_w)/2:y=(h-text_h)/2:fontfile='C\:\\Windows\\Fonts\\Arial.ttf':text=%{n}:box=1 -y out.mp4
("
) didn't work. but ('
) did. How very strange it's thefontcolor
... -
MarianD about 7 yearsIt seems as something impossible (in spite of that
black
is the defaultfontcolor
). Did you try some other colors or the notationfontcolor=0x000000
? -
Moore about 7 yearsYes you're right. It seems it's the part
text=%{expr\\\\\:n+1}
that caused something wrong. I forgot I also omitted that part at the same time.fontcolor
works as expected. Thanks! -
Moore about 7 yearsIt'd be great to know why
text=%{expr\\\\\:n+1}
Do you have an idea? -
MarianD about 7 yearsYou have odd number of backslashes. Try adding or removing one of them (or removing more of them). Other problem is that Windows command line itself interprets
%
, so you have to use it in a pair:%%{expr ....
-
Moore about 7 yearsYes. It seems to be the backslashes. I think
%
is fine though. It's part of ffmpeg filter syntax