FFmpeg drawtext - Failed to load font from file

I am trying to add plain text on top of a video using FFmpeg using the drawtext parameter. Every time I am going to do this, an error is returned:

Failed to load font from file 'arial.ttf': cannot open resource

To indicate the location of the font, I used the following methods:

ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile=arial.ttf:text=test -sameq vid_1321909320.flv ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile=C:\Windows\Fonts\arial.ttf:text=test -sameq vid_1321909320.flv 

All failed. Does anyone have experience adding text with ffmpeg?

 FFMPEG version: N-34549-g13b7781 build on Nov 6 2011 
+6
source share
4 answers

You cannot have a colon in the path of your font file, since the colon acts as the key sepperator in ffmpeg. I had the same problem .

to try:

 ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile=/Windows/Fonts/arial.ttf:text=test -sameq vid_1321909320.flv 
+11
source

The colon ":" and the backslash "\" have special meaning when specifying options for drawtext. Therefore, you can avoid them by translating ":" to "\" and "\" to "\\". You can also enclose the path to your font file in single quotes if the path contains spaces.

So you will have

 ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile='C\:\\Windows\\Fonts\\arial.ttf':text=test vid_1321909320.flv 
+10
source

I also had problems with ffmpeg recognizing windows paths. I finally just put the font Arial.ttf in the same folder as the input file, and it worked.

 [drawtext @ 03C66EA0] Key '/Windows/Fonts/Arial.ttf: text' not found. [drawtext @ 03C66E00] Error parsing options string: 'fontfile=C:/Windows/Fonts/Arial.ttf: text=Test Text:x=100: y=50: fontsize=24: fontcolor=yellow@0.2 : box=1: boxcolor=red@0.2 ' Error initializing filter 'drawtext' with args 'fontfile=C:/Windows/Fonts/Arial.ttf: text=Test Text:x=100: y=50: fontsize=24: fontcolor=yellow@0.2 : box=1: boxcolor=red@0.2 ' Error opening filters! 
+3
source

Try putting quotes around the parameter:

 ffmpeg -i C:\Test\rec\vid_1321909320.avi \ -vf drawtext="fontfile=C:\Windows\Fonts\arial.ttf:text=test" \ -sameq vid_1321909320.flv 
0
source

Source: https://habr.com/ru/post/901338/


All Articles