如何使用 ffmpeg 和 python 向视频添加文本
我一直在尝试使用 ffmpeg 将文本添加到 avi,但似乎无法正确执行。
请帮忙:
import subprocess
ffmpeg = "C:\\ffmpeg_10_6_11.exe"
inVid = "C:\\test_in.avi"
outVid = "C:\\test_out.avi"
proc = subprocess.Popen(ffmpeg + " -i " + inVid + " -vf drawtext=fontfile='arial.ttf'|text='test' -y " + outVid , shell=True, stderr=subprocess.PIPE)
proc.wait()
print proc.stderr.read()
I've been trying to add text to an avi with ffmpeg and I can't seem to get it right.
Please help:
import subprocess
ffmpeg = "C:\\ffmpeg_10_6_11.exe"
inVid = "C:\\test_in.avi"
outVid = "C:\\test_out.avi"
proc = subprocess.Popen(ffmpeg + " -i " + inVid + " -vf drawtext=fontfile='arial.ttf'|text='test' -y " + outVid , shell=True, stderr=subprocess.PIPE)
proc.wait()
print proc.stderr.read()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为绘图文本指定参数时,冒号“:”和反斜杠“\”具有特殊含义。所以你可以做的就是通过将“:”转换为“\:”和“\”转换为“\\”来转义它们。
您还可以将字体文件的路径用单引号括起来,以防路径包含空格。
所以你会有
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.
So you will have
HA
原来 C:\Windows\Fonts 等中的双冒号“:”充当了分割,因此当我输入字体的完整路径时 ffmpeg 正在读取我的命令,如下所示
原始命令
ffmpeg 的解释
所以要修复它,您需要消除字体文件路径中的 : 。
我的最终工作代码:
HA
Turns out the double colon ":" in C:\Windows\Fonts etc was acting as a split so when i was inputting the font's full path ffmpeg was reading my command as follows
original command
ffmpeg's interpretation
So to fix it you need to elinate the : in the font file path.
My final working code: