ffmpeg - 移动覆盖/文本命令如何工作? [英] ffmpeg - how does moving overlay / text command work?
问题描述
在 Ffmpeg 中,您可以创建移动文本:
In Ffmpeg you can create moving text:
ffmpeg -y -t 10 -s qcif -f rawvideo -pix_fmt rgb24 -s 1280x720 -i /dev/zero -g 1 -r 24 -vf drawtext="fontfile=~/fonts/Trebuchet_MS.ttf:text='thing crawls':fontsize=155:fontcolor=red:y=h-20*t" wow.mpg
所以这会给我一个黑色的框架,东西爬行"从下往上慢慢移动..
So this will give me a black frame with "thing crawls" slowly going from bottom up..
如果我知道视频的长度(20 秒)并且想要创建东西坠落",它从时间 0 的屏幕顶部开始,一直到屏幕底部直到 00:00:20、我该怎么做?
If I know the length of the video (20 seconds) and want to, for example create "thing falls" that starts at the top of the screen at time 0 and goes to the bottom of the screen until 00:00:20, how do I do that?
我也可以创建文本从上到下开始但停在屏幕中间的情况吗?
Also can I create the situation where the text will start going from top to bottom, but stop at the middle of the screen?
推荐答案
FFmpeg 文档给出使用 drawtext 过滤器时必须使用的变量的完整列表,但对于移动文本,有一些特别有趣:
The FFmpeg docs give a full listing of the variables that you have to work with when using the drawtext filter, but for mobile text there are a few of particular interest:
‘n’
输入帧数,从0开始
‘n’
the number of input frame, starting from 0
‘t’
时间戳以秒表示,如果输入时间戳未知,则为 NAN
‘t’
timestamp expressed in seconds, NAN if the input timestamp is unknown
通过这些,您可以根据已经看到的帧数设置文本位置.这就是您示例中的 y=h-20*t
表达式所做的.随着 t
的增加,随着 h-20*t
的减少,文本会越来越靠近视频的顶部.
With these, you can set the text position in relation to how many frames have already been seen. That's what the y=h-20*t
expression in your example is doing. As t
increases, the text moves closer to the top of the video as h-20*t
decreases.
为了让你的例子东西倒下",你需要一个像 20*t
这样的术语.因为y
位置从视频顶部的0开始,随着t
的增加,它会向下移动屏幕.
To make your example "thing falls", you'd want a term like 20*t
instead. Because the y
position starts from 0 at the top of the video, as t
increases, it will move down the screen.
对于停在屏幕中间的文本,您可能会做一些花哨的数学运算,或者只使用 FFmpeg 的 丰富的逻辑功能.类似 y=t*20*lte(t*20,h/2) + h/2*gt(t*20,h/2)
之类的东西,它在 t* 的同时移动文本20
小于高度的一半,一旦 t*20
大于一半,则将 y
位置保持在 h/2
高度.
For text that stops in the middle of the screen, you could probably do some fancy math, or just use FFmpeg's rich set of logical functions. Something like y=t*20*lte(t*20,h/2) + h/2*gt(t*20,h/2)
which moves the text while t*20
is less than half the height, then keeps the y
position at h/2
once t*20
is greater than half the height.
这篇关于ffmpeg - 移动覆盖/文本命令如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!