如何使用ffmpeg和python添加文本到视频 [英] How to add text to a video with ffmpeg and python

查看:1019
本文介绍了如何使用ffmpeg和python添加文本到视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用ffmpeg将文本添加到avi,我似乎无法正确。

I've been trying to add text to an avi with ffmpeg and I can't seem to get it right.

请帮助:

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()


推荐答案

在指定drawtext的参数时,冒号:和反斜杠\具有特殊的含义。那么你可以做的是通过将:转换为\:和\转换为\\来转义它们。
此外,您可以使用单引号将路径添加到字体文件中,路径中包含空格。

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.

所以你将有

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

这篇关于如何使用ffmpeg和python添加文本到视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆