5

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

2 回答 2

6

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

所以你会有

ffmpeg -i C:\Test\rec\vid_1321909320.avi -vf drawtext=fontfile='C\:\\Windows\\Fonts\\arial.ttf':text=test vid_1321909320.flv
于 2013-01-25T16:58:37.483 回答
5

结果发现 C:\Windows\Fonts 等中的双冒号“:”充当了拆分,所以当我输入字体的完整路径时,ffmpeg 正在读取我的命令,如下所示

原始命令

" -vf drawtext=fontfile='C:\\Windows\\fonts\\arial.ttf'|text='test' "

ffmpeg的解释

-vf drawtext=  # command

fontfile='C    # C is the font file because the : comes after it signalling the next key

arial.ttf'     # is the next key after fontfile = C (because the C is followed by a : signalling the next key)

:text          # is the value the key "arial.tff" is pointing to

='test'        # is some arb piece of information put in by that silly user

因此,要修复它,您需要删除字体文件路径中的 : 。

我的最终工作代码:

import subprocess

ffmpeg = "C:\\ffmpeg_10_6_11.exe"
inVid = "C:\\test_in.avi"
outVid = "C:\\test_out.avi"

subprocess.Popen(ffmpeg + " -i " + inVid + ''' -vf drawtext=fontfile=/Windows/Fonts/arial.ttf:text=test ''' + outVid , shell=True)
于 2011-11-21T13:58:28.593 回答