FFmpeg 在多行上绘制文本
我有代码:
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 )
将文本写入视频文件。但我想写出多行文本,而不是只将其全部写在一行上。
我怎样才能做到这一点?
I have the code:
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 )
to write text to a video file. But I want to write out many lines of text instead of just having it all on the one line.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 [in] 标签在一个文件上指定多个绘图文本,并使用逗号列出每个绘图文本。如果您通过各自的定位方法来定位每个绘图文本,则这允许您使用多条线。在您的示例中,命令行将如下所示(将第一行放在屏幕中间,并将后续的每一行向下 25 像素):
You can specify multiple drawtexts on one file by using the [in] tag and listing each drawtext using commas. This allows you to use multiple lines if you orient each drawtext through their respective positioning methods. In your example, the command line would look something like this (puts the first line in the middle of the screen, and puts each subsequent line 25 pixels down):
查看
ffmpeg
(vs_drawtext.c
)中的源代码:因此您可以尝试插入
\f
或\v
在文本行中对应于^L
或^K
字符。例如:^L
是实际的 Ctrl-L 字符,而不是^
和L
显然。Looking at the source code in
ffmpeg
(vs_drawtext.c
):so you can try inserting
\f
or\v
in your text line which correspond to^L
or^K
characters. For example:^L
being the actual Ctrl-L character and not^
andL
obviously.我简单地在命令中添加了新行,并且 ffmpeg 正确处理了它。
不需要 Ctrl+L、Ctrl+K 黑客!
即我只是在“hello”之后按 Enter。
您可以编辑脚本文件甚至在 bash 命令行中进行操作。
I simple added new lines inside command and ffmpeg handled it properly.
No Ctrl+L, Ctrl+K hacks are needed!
I.e. I just pressed Enter after 'hello'.
You can do it editing script file or even in bash command line.
我已经通过指定“textfile”参数并将我的文本放入此文件中,设法从命令行使其正常工作。
请参阅 http://ffmpeg.org/libavfilter.html#drawtext 获取更多帮助。在 Windows 上使用 ffmpeg 构建 N-35057-g2c44aed,但重要的是您拥有最新版本的 libavfilter。
I have managed to get this to work from the command line by specifying the 'textfile' parameter and putting my text into this file.
See http://ffmpeg.org/libavfilter.html#drawtext for more help. Using ffmpeg build N-35057-g2c44aed on windows, but the important thing is that you have recent version of the libavfilter.
只需将文本分割成一定长度的行(20个字符,您可以根据需要设置),然后再传递给
ffmpeg
。Just split the text into lines of a certain length (20 characters, you can set according to your need) before passing to
ffmpeg
.在 shell 脚本中
使用文本作为 shell 脚本参数,包括换行符
In a shell script
With your text as your shell script argument including new line characters