[FFmpeg-user] Command line calesthetics #2
steward at stewardware.com
steward at stewardware.com
Sat Jul 23 23:17:34 EEST 2016
Here is a different way of asking the question.
To understand what the line is doing, I convert it to php.
In the first case (calculating opacity) it becomes obvious once you see
the output.
In the second case (generating a consistent random X value for N
seconds...it makes no sense to me.
/****
# fade in - display - fade out - no display
# alpha varies according to the function:
# t0 = t % period
# alpha(t) = (t0 / text_fading_time) * max_alpha if (lt(t0,
text_fading_time))
# = max_alpha if (between(t0, text_fading_time, text_fading_time +
text_display_time))
# = (2*text_fading_time + display_time - t0)/text_fading_time *
max_alpha if (between(t0, text_fading_time + text_display_time, 2 *
text_fading_time + text_display_time)
# = 0 if (gt(t0), 2 * text_fading_time + text_display_time)
#$TDP=30; // Text Display Period
#$TDT=20; // Text Display Time
#$TFT=10; // Text Fading Time
* */
for($t=0; $t<60; $t++)
{
$t0 = ($t % $TDP);
if ( $t0 < $TFT){
$ALPHA = ($t0/$TFT)*$MA; $X='A';
}
elseif( $t0 >= $TFT AND $t0 <= $TFT+$TDT){
$ALPHA = $MA; $X='B';
}
elseif( $t0 >= $TFT+$TDT AND $t0 <= 2*$TFT+$TDT){
$ALPHA = (2*$TFT+$TDT-$t0)/$TFT *$MA; $X='C';
}
else{
$ALPHA=0; $X='D';
}
// if(A,A, if(B,B, if(C,C,D) )
echo "$t $t0 $X $ALPHAn";
}
//die();
//$RANDXEXPR =
"x='st(0,ceil(t/$SNPERIOD));if(gt(ld(0),ld(1)),st(1,ld(0));st(2,rand(0,w-text_w)));ld(2)'";
// if(gt(ld(0),ld(1)),st(1,ld(0));
$V1=0; $VW=640 // video width
for($t=0; $t<120; $t++)
{
$V0 = ($t % $TDP);
if ( $V0 > $V1){
$V1 = $V0;
}
$V2 = RAND(0,$VW);
echo "$t 0=$V0 1=$V1 2=$V2n";
}
die();
0 0 A 0
1 1 A 50 opacity is ramping up to 250
2 2 A 100
3 3 A 150
4 4 A 200
5 5 B 250 exit B so hold the opacity for 20 secs
6 6 B 250
7 7 B 250
8 8 B 250
9 9 B 250
10 10 B 250
11 11 B 250
12 12 B 250
13 13 B 250
14 14 B 250
15 15 B 250
16 16 C 200 text fading now
17 17 C 150
18 18 C 100
19 19 C 50
20 0 A 0
21 1 A 50 ... 20 seconds, the cycle begins again
22 2 A 100
23 3 A 150
24 4 A 200
25 5 B 250
26 6 B 250
27 7 B 250
28 8 B 250
29 9 B 250
30 10 B 250
31 11 B 250
32 12 B 250
33 13 B 250
34 14 B 250
35 15 B 250
36 16 C 200
37 17 C 150
38 18 C 100
39 19 C 50
40 0 A 0
41 1 A 50
42 2 A 100
43 3 A 150
44 4 A 200
45 5 B 250
46 6 B 250
47 7 B 250
48 8 B 250
49 9 B 250
50 10 B 250
51 11 B 250
52 12 B 250
53 13 B 250
54 14 B 250
55 15 B 250
56 16 C 200
57 17 C 150
58 18 C 100
59 19 C 50
Here I am lost. Where is the cycle. How do we ever return anything but
V2 ?
0 0=0 1=0 2=416
1 0=1 1=1 2=351
2 0=2 1=2 2=364
3 0=3 1=3 2=255
4 0=4 1=4 2=423
5 0=5 1=5 2=340
6 0=6 1=6 2=57
7 0=7 1=7 2=342
8 0=8 1=8 2=220
9 0=9 1=9 2=170
10 0=10 1=10 2=231
11 0=11 1=11 2=182
12 0=12 1=12 2=431
13 0=13 1=13 2=345
14 0=14 1=14 2=2
15 0=15 1=15 2=212
16 0=16 1=16 2=203
17 0=17 1=17 2=424
18 0=18 1=18 2=332
19 0=19 1=19 2=321
20 0=0 1=19 2=296
21 0=1 1=19 2=473
22 0=2 1=19 2=601
23 0=3 1=19 2=342
24 0=4 1=19 2=166
25 0=5 1=19 2=310
26 0=6 1=19 2=594
27 0=7 1=19 2=352
28 0=8 1=19 2=343
29 0=9 1=19 2=355
30 0=10 1=19 2=208
31 0=11 1=19 2=119
32 0=12 1=19 2=65
33 0=13 1=19 2=573
34 0=14 1=19 2=374
35 0=15 1=19 2=489
36 0=16 1=19 2=272
37 0=17 1=19 2=432
38 0=18 1=19 2=191
39 0=19 1=19 2=492
40 0=0 1=19 2=603
41 0=1 1=19 2=422
42 0=2 1=19 2=34
43 0=3 1=19 2=393
44 0=4 1=19 2=126
45 0=5 1=19 2=36
46 0=6 1=19 2=606
47 0=7 1=19 2=330
48 0=8 1=19 2=460
49 0=9 1=19 2=297
50 0=10 1=19 2=11
51 0=11 1=19 2=116
52 0=12 1=19 2=130
53 0=13 1=19 2=613
54 0=14 1=19 2=459
55 0=15 1=19 2=296
56 0=16 1=19 2=282
57 0=17 1=19 2=412
58 0=18 1=19 2=8
59 0=19 1=19 2=626
60 0=0 1=19 2=127
61 0=1 1=19 2=216
62 0=2 1=19 2=105
63 0=3 1=19 2=193
64 0=4 1=19 2=148
65 0=5 1=19 2=480
66 0=6 1=19 2=41
67 0=7 1=19 2=421
68 0=8 1=19 2=271
69 0=9 1=19 2=233
70 0=10 1=19 2=272
71 0=11 1=19 2=234
72 0=12 1=19 2=14
73 0=13 1=19 2=307
74 0=14 1=19 2=627
75 0=15 1=19 2=141
76 0=16 1=19 2=343
77 0=17 1=19 2=592
78 0=18 1=19 2=472
79 0=19 1=19 2=163
80 0=0 1=19 2=249
81 0=1 1=19 2=483
82 0=2 1=19 2=280
83 0=3 1=19 2=379
84 0=4 1=19 2=455
85 0=5 1=19 2=98
86 0=6 1=19 2=34
87 0=7 1=19 2=97
88 0=8 1=19 2=511
89 0=9 1=19 2=42
90 0=10 1=19 2=83
91 0=11 1=19 2=639
92 0=12 1=19 2=259
93 0=13 1=19 2=188
94 0=14 1=19 2=191
95 0=15 1=19 2=407
96 0=16 1=19 2=27
97 0=17 1=19 2=233
98 0=18 1=19 2=187
99 0=19 1=19 2=299
100 0=0 1=19 2=466
101 0=1 1=19 2=460
102 0=2 1=19 2=534
103 0=3 1=19 2=481
104 0=4 1=19 2=127
105 0=5 1=19 2=520
106 0=6 1=19 2=622
107 0=7 1=19 2=470
108 0=8 1=19 2=472
109 0=9 1=19 2=454
110 0=10 1=19 2=634
111 0=11 1=19 2=81
112 0=12 1=19 2=296
113 0=13 1=19 2=274
114 0=14 1=19 2=460
115 0=15 1=19 2=111
116 0=16 1=19 2=372
117 0=17 1=19 2=495
118 0=18 1=19 2=209
119 0=19 1=19 2=243
On 2016-07-23 12:48, steward at stewardware.com wrote:
> 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.....
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user [1]
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
Links:
------
[1] http://ffmpeg.org/mailman/listinfo/ffmpeg-user
More information about the ffmpeg-user
mailing list