[FFmpeg-user] Command line calesthetics

steward at stewardware.com steward at stewardware.com
Sat Jul 23 22:48:21 EEST 2016


 

I have a command line that draws text at random locations, fading in and
out over a time period. 

Here is how the X and Y values are calculated: 


"x='st(0,ceil(t/{$this->SNPERIOD}));if(gt(ld(0),ld(1)),st(1,ld(0));st(2,rand(0,w-text_w)));ld(2)'";


"y='st(0,ceil(t/{$this->SNPERIOD}));if(gt(ld(0),ld(1)),st(1,ld(0));st(2,rand(0,h-text_h)));ld(2)'";

This works. But now I want to ensure X,Y are never dead centre.
I want to constrain them to the outer portion of the frame.

I so I write this:

"x='st(0,ceil(t/{$this->SNPERIOD}));if(gt(ld(0),ld(1)),st(1,ld(0));st(2,rand(0,w-text_w)));st(5,ceil(w/2));if(gt(ld(2),ld(5)),st(2,rand(ld(5),w-text_w)),st(2,rand(0,ld(5)-text_w)));ld(2)'";

"y='st(0,ceil(t/{$this->SNPERIOD}));if(gt(ld(0),ld(1)),st(1,ld(0));st(2,rand(0,h-text_h)));st(6,ceil(h/2));if(gt(ld(2),ld(6)),st(2,rand(ld(6),h-text_h)),st(2,rand(0,ld(6)-text_h)));ld(2)'";

The original logic chose an X value between 0 and (w-text-w), the left
and right margins.
I still do that, but then I also find the centre (V5) use that value to
choose a new random value between the left and right hand side. Left is
between 0 and V5-text_w, right is between V5 and w=text_w.

That seems to do the trick. The X,Y cords are never dead centre now.
They move around the edges. Great!

But. Now I have broken the timing.
It used to fade in, hold for SNPERIOD seconds, then fade out.
Now it just pops around very quickly.

Naturally, this is the one part of the command line I was unable to
unravel.
Pulling apart the X cord logic:

st(0,ceil(t/{$this->SNPERIOD})); V0 = TOTALTIME / DISPLAY PERIOD
if(gt(ld(0),ld(1)),st(1,ld(0)); IF V0>V1 THEN V1=V0
st(2,rand(0,w-text_w))); V2 = A RANDOM NUMBER BETWEEN 0 AND RIGHT MARGIN
st(5, ceil(w/2)); V5 = mid-frame
IF V2>V5 THEN V2=RANDOM V5...MAXRIGHT ELSE V2=RANDOM 0...MAXLEFT
if(gt(ld(2),ld(5)), st(2,rand(ld(5),w-text_w)), st(2,
rand(0,ld(5)-text_w)) ))
ld(2); RETURN VALUE (X CORD) IS IN V2

The second line baffles me. It looks like V1 (the variable defined by
st(1...) and ld(1) is used before it has a value.
I fail to grasp how exactly this keeps X at the same value for SNPERIOD
values of T.

T is the timecode: 1....600 for a ten minute clip.
SNPERIOD is 20: hold the x,y for 20 seconds.

So V0 is used like a modulus, it causes a cycle from 1 to 20 (or 0 to 19
whatever).

...then...whatever it is... I don't know ;) Is there someone in the
house who has seen this kind of thing before?

I wish I knew what to ask !

How is the logic that holds it in place for 20 seconds working?
How can it be the value of ld(1) is used before it is set?

I think I am reading this "procedurally" and need a new viewpoint.....

 


More information about the ffmpeg-user mailing list