Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

video - ffmpeg - how does moving overlay / text command work?

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..

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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’
the number of input frame, starting from 0

‘t’
timestamp expressed in seconds, NAN if the input timestamp is unknown

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...