windows FFmpeg drawtext - 无法从文件加载字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8103808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:27:26  来源:igfitidea点击:

FFmpeg drawtext - Could not load fontface from file

windowsvideoffmpeg

提问by falek.marcin

I've try to add simple text on top of video with FFmpeg using drawtextparameter. Every time i'm going to do this, error is returned:

我尝试使用drawtext参数在带有 FFmpeg 的视频顶部添加简单的文本。每次我要这样做时,都会返回错误:

Could not load fontface from file 'arial.ttf': cannot open resource

无法从文件“arial.ttf”加载字体:无法打开资源

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 have failed. Does anyone have experience with adding text using ffmpeg?

都失败了。有没有人有使用 ffmpeg 添加文本的经验?

FFMPEG version: N-34549-g13b7781 build on Nov 6 2011

回答by Jay

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

字体文件的路径中不能有冒号,因为冒号在 ffmpeg 中充当关键分隔符。我有同样的问题

try:

尝试:

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

回答by adentum

A colon ":" and a backslash "\" have special meaning when specifying the parameters for drawtext. So what you can do is to escape them by converting ":" to "\:" and "\" to "\\". Also you can enclose the path to your font file in single quotes incase the path contains spaces.

在指定 drawtext 的参数时,冒号“:”和反斜杠“\”具有特殊含义。所以你可以做的是通过将“:”转换为“\:”并将“\”转换为“\\”来转义它们。您也可以将字体文件的路径用单引号括起来,以防路径包含空格。

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

回答by cdavidyoung

I was also having trouble with ffmpeg recognizing Windows paths. I finally just put the font Arial.ttf in the same folder as the input file and it worked.

我也遇到了 ffmpeg 识别 Windows 路径的问题。我最后只是将字体 Arial.ttf 放在与输入文件相同的文件夹中并且它起作用了。

[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: [email protected]: box=1: [email protected]'
Error initializing filter 'drawtext' with args 'fontfile=C:/Windows/Fonts/Arial.ttf: text=Test Text:x=100: y=50: fontsize=24: [email protected]: box=1: [email protected]'
Error opening filters!