我有代码:
import subprocess , os
ffmpeg = "C:\\ffmpeg_10_6_11.exe"
inVid = "C:\\test_in.avi"
outVid = "C:\\test_out.avi"
if os.path.exists( outVid ):
os.remove( outVid )
proc = subprocess.Popen(ffmpeg + " -i " + inVid + ''' -vf drawtext=fontfile=/Windows/Fonts/arial.ttf:text="onLine1 onLine2 onLine3":fontcolor=white:fontsize=20 -y ''' + outVid , shell=True, stderr=subprocess.PIPE)
proc.wait()
print proc.stderr.read()
os.startfile( outVid )
将文本写入视频文件。但我想写出多行文字,而不只是把它全部放在一行上。
请帮助。感谢
答案 0 :(得分:16)
这个答案对你来说可能有点晚了,但你可以使用[in]标签在一个文件上指定多个drawtexts,并使用逗号列出每个drawtext。如果您通过各自的定位方法定位每个drawtext,则允许您使用多行。在您的示例中,命令行看起来像这样(将第一行放在屏幕中间,并将每个后续行放置25个像素):
ffmpeg -i test_in.avi -vf "[in]drawtext=fontsize=20:fontcolor=White:fontfile='/Windows/Fonts/arial.ttf':text='onLine1':x=(w)/2:y=(h)/2, drawtext=fontsize=20:fontcolor=White:fontfile='/Windows/Fonts/arial.ttf':text='onLine2':x=(w)/2:y=((h)/2)+25, drawtext=fontsize=20:fontcolor=White:fontfile='/Windows/Fonts/arial.ttf':text='onLine3':x=(w)/2:y=((h)/2)+50[out]" -y test_out.avi
答案 1 :(得分:12)
查看ffmpeg
(vs_drawtext.c
)中的源代码:
static inline int is_newline(uint32_t c)
{
return c == '\n' || c == '\r' || c == '\f' || c == '\v';
}
因此,您可以尝试在文字行中插入\f
或\v
字符对应^L
或^K
个字符。例如:
-filter_complex "[in] drawtext=fontsize=40:fontcolor=white:fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf:x=(w-tw)/2:y=(h-th)/2:box=1:boxcolor=black@0.5:text='two^Llines'[out]"
^L
是实际的Ctrl-L字符,显然不是^
和L
。
答案 2 :(得分:5)
我已经设法通过指定'textfile'参数并将我的文本放入此文件中从命令行开始工作。
有关更多帮助,请参阅http://ffmpeg.org/libavfilter.html#drawtext。在Windows上使用ffmpeg build N-35057-g2c44aed,但重要的是你有最新版本的libavfilter。
答案 3 :(得分:3)
我在命令中添加了新行,ffmpeg正确处理了它。
ffmpeg -i input.avi -vf "[in]drawtext=fontsize=20:text='hello
world':x=(w)/2:y=(h)/2:fontcolor=white[out]" -y out.mp4
不需要Ctrl + L,需要Ctrl + K黑客!
即。我刚刚在“你好”之后按了Enter键。
您可以编辑脚本文件,甚至可以在bash命令行中编辑。
答案 4 :(得分:0)
TEXT = $(printf“ $ 1”)
在shell脚本中
将您的文本作为包含换行符的shell脚本参数