在 Android 上使用 FFMPEG 库在图像上显示文本
朋友们,美好的一天。 我正在尝试使用此 ffmpeg 命令在图像上添加文本,
String exe = " -i /storage/emulated/0/Download/test1.jpg -vf drawtext=text='Test Text':fontcolor=white:fontsize=75:x=1002:y=100: " + file.getAbsolutePath();
但不幸的是我遇到了此错误,
Input #0, image2, from '/storage/emulated/0/Download/test1.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 8264 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 960x1280, 25 fps, 25 tbr, 25 tbn
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[Parsed_drawtext_0 @ 0xa38921b0] Cannot find a valid font for the family Sans
[AVFilterGraph @ 0xedd90500] Error initializing filter 'drawtext'[AVFilterGraph @ 0xedd90500] with args 'text=Test Text:fontcolor=white:fontsize=75:x=1002:y=100:'[AVFilterGraph @ 0xedd90500]
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!
有人有与我相同的错误吗?谢谢你!
Good day fellows.
I am trying to add a text over an image using this ffmpeg command
String exe = " -i /storage/emulated/0/Download/test1.jpg -vf drawtext=text='Test Text':fontcolor=white:fontsize=75:x=1002:y=100: " + file.getAbsolutePath();
But unfortunately I meet this error,
Input #0, image2, from '/storage/emulated/0/Download/test1.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 8264 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 960x1280, 25 fps, 25 tbr, 25 tbn
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[Parsed_drawtext_0 @ 0xa38921b0] Cannot find a valid font for the family Sans
[AVFilterGraph @ 0xedd90500] Error initializing filter 'drawtext'[AVFilterGraph @ 0xedd90500] with args 'text=Test Text:fontcolor=white:fontsize=75:x=1002:y=100:'[AVFilterGraph @ 0xedd90500]
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!
Does someone had the same error as I have? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您需要关注的错误消息(FFmpeg 的错误日志有时会产生误导):
发生这种情况是因为您没有指定字体,并且在您的系统上找不到默认字体“Sans”。因此,您需要明确指定一个。
这里是Android 字体资源参考的链接,
和 FFmpeg
drawtext
文档中的第一个示例说明如何指定字体文件。(我不是 Android 开发人员,所以希望您可以从这些链接中找到答案。)
This is the error message that you need to focus on (FFmpeg's error logs are sometimes misleading):
And this happened because you did not specify the font, and the default font "Sans" couldn't be found on your system. So, you need to specify one explicitly.
Here is a link to the Android font resources reference,
and the first example in FFmpeg
drawtext
documentation illustrates how to specify a font file.(I'm not an Android dev, so hopefully you can figure it out from these links.)
我在 Android 上使用 Canvas 而不是使用 ffmpeg 库找到了一个非常简单且更快的解决方案。
这是我的代码解决方案:
我希望这个解决方案对其他人有用。
I found a very simple and faster solution to this problem using Canvas on Android instead of using ffmpeg library.
Here is my code solution:
I hope this solution will be useful to someone else.