FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var?

Questions involving a Windows version of FFmpeg.
FFmpeg2019
Posts: 7
Joined: Fri Oct 18, 2019 6:56 am

FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var?

Post by FFmpeg2019 » Fri Oct 18, 2019 7:42 am

I have a ffmpeg code:

ffmpeg -i input.mp4 -vf drawtext=text=hello:fontsize=18:x=rand(0,640):y=rand(0,480),\
drawtext=world:fontcolor=white:fontsize=fontsize+0.1: x=16+?:y=? output.mp4


And have 3 questions:

1. How to let the "fontsize+0.1" work?

2. The two "?" how to get the first drawtext's x,y values? let the two strings become one string like this: hello world.

3. how to create a var?

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by pandy » Tue Oct 22, 2019 4:50 pm

It is not clear to me what is behind your questions - i blame my poor English for this - if i misunderstood your questions my apologies.

If your gaol is to place those values manually and you are using commandline (dos/windows) then perhaps something like this:

Code: Select all

@setlocal
@set fontsize=18
@set qmrk=2
ffmpeg -i input.mp4 -vf drawtext=text=hello:fontsize=%fontsize%:x=rand(0,640):y=rand(0,480),\
drawtext=world:fontcolor=white:fontsize=%fontsize%+0.1:x=16+%qmrk%:y=%qmrk% output.mp4
PS not sure about fontsize variable type (integer? float?)

FFmpeg2019
Posts: 7
Joined: Fri Oct 18, 2019 6:56 am

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by FFmpeg2019 » Tue Oct 22, 2019 6:24 pm

Thanks for your reply.
I want to auto let the two "?" get the first drawtext's x,y values, connection the string.
And change the second drawtext's fontsize every frame.
The fontsize variable type integer.
As this link you can see, the text in the video but the string don't connection. I want to the text show like this: "What are you doing".
https://youtu.be/ErSkFM2RJPg

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by pandy » Tue Oct 22, 2019 8:08 pm

IMHO you should be familiar with ffmpeg syntax and variables offered by overlay and ffmpeg (expression evaluation)

https://ffmpeg.org/ffmpeg-filters.html#overlay-1
https://ffmpeg.org/ffmpeg-utils.html#Ex ... Evaluation

FFmpeg2019
Posts: 7
Joined: Fri Oct 18, 2019 6:56 am

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by FFmpeg2019 » Tue Oct 22, 2019 8:26 pm

Thanks for your reply.
Yes, i don't know anything of syntax and variables, unkonw which commands need to use?
The video is i upload, i can do as the video show only.
But that's not what I want.
The string cann't connection, and the fontsize not smooth change.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by pandy » Wed Oct 23, 2019 6:13 pm

All i can help is something like this:

Code: Select all

@set filename=%1
@ffplay -loop -1 -hide_banner -loglevel 8 -an -sn -i "%filename%" -vf "drawtext=fontfile=Orbitron.ttf:fontsize=120:[email protected]:text='watermark':x=if(eq(mod(n\,60)\,0)\,rand(0\,(w-text_w))\,x):y=if(eq(mod(n\,60)\,0)\,rand(0\,(h-text_h))\,y):enable=lt(mod(n\,60)\,55),zscale=f=spline36:r=full:w=iw/2:h=-2"
To improve smoothness you may think about subpixel rendering i.e. increase size of incoming video twice and at the end of filter chain reduce by 2 - your accuracy will be half pixel, if you need higher accuracy then increase video size 4 times and reduce by 4 at the end then your accuracy will be like 1/4 of pixel.

IMHO ffmpeg may be not the best tool to do such things - perhaps you should try different tool, something more complex?
Some real video editor?

FFmpeg2019
Posts: 7
Joined: Fri Oct 18, 2019 6:56 am

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by FFmpeg2019 » Wed Oct 23, 2019 7:25 pm

hey, thank you.
but do you have a video show it?

1. The text "What" color=purple,
2. The text "are" color=blue,
3. The text "you" color=green,
4. The text "doing" color=pink.

And connection them like this: "What are you doing".

5. The fontsize change every frame,
6. The apha change every frame,
7. The x,y values change every frame.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by pandy » Thu Oct 24, 2019 7:57 pm

filter complex, split on 4 , separate draw text, later stack video, or create 4 layers, create alpha mask, overlay on top of video - be creative as you searching to simulate Video NLE on top of ffmpeg...

FFmpeg2019
Posts: 7
Joined: Fri Oct 18, 2019 6:56 am

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by FFmpeg2019 » Fri Oct 25, 2019 5:27 am

Hi, thank for your reply.

But do you know my question? I'm ask how to connection the string.

for example:

ffplay -an -i input.mp4 -vf \
"drawtext=fontfile=Orbitron.ttf:fontsize=120:text='What':fontcolor=purple:x=if(eq(mod(n\,60)\,0)\,rand(0\,w)\,x-0.3):y=if(eq(mod(n\,60)\,0)\,rand(0\,h)\,y-0.2), \
drawtext=fontfile=Orbitron.ttf:fontsize=120:=text=' are':fontcolor=blue:x=if(eq(mod(n\,60)\,0)\,rand(0\,w)\,x-0.3):y=if(eq(mod(n\,60)\,0)\,rand(0\,h)\,y-0.2), \
drawtext=fontfile=Orbitron.ttf:fontsize=120:=text=' you':fontcolor=green:x=if(eq(mod(n\,60)\,0)\,rand(0\,w)\,x-0.3):y=if(eq(mod(n\,60)\,0)\,rand(0\,h)\,y-0.2), \
drawtext=fontfile=Orbitron.ttf:fontsize=120:=text=' doing':fontcolor=pink:x=if(eq(mod(n\,60)\,0)\,rand(0\,w)\,x-0.3):y=if(eq(mod(n\,60)\,0)\,rand(0\,h)\,y-0.2)"

The four text's x,y values are random for each other. (as my video show, the youtube link i give you)
The text ' are' , ' you', ' doing' must to follow 'What'.
So, how to set the three text ' are' , ' you', ' doing' x,y values?

I want to connection them in one line as this: What are you doing

I don't know how to let the four text together.
And the overlay seem cann't help me anything. If you can do it, how about show the video for me? please, thanks.

pandy
Posts: 255
Joined: Mon Feb 24, 2014 1:46 pm

Re: FFmpeg how to get the first drawtext's x,y value to the second's, and change the fontsize value, how to create a var

Post by pandy » Fri Oct 25, 2019 4:35 pm

Script is static - ffmpeg has limited ability to pass/import variables from static script where variable is evaluated only once at the script start... perhaps some application able to control ffmpeg will work OK (trough ffmpeg API). This was my point - consider to use more appropriate application... you can't change hammer in cordless drill... both are very useful tools but not interchangeable (at least this is not easy).

Post Reply
'