(ffmpeg-utils)3. Expression Evaluation (2)¶
On this page, I’m going to write an expression that isn’t built into ffmpeg but can be written using it. However, there is no clear policy for collection, so what will be gathered here will be unorganized.
sinc(x)¶
unnormalized sinc function:
normalized sinc function:
[me@host: ~]$ # use sinc function as amplitude
[me@host: ~]$ ffplay -f lavfi "
> aevalsrc='
> st(0, 4 - mod(t * PI, 8)) ;
> 0.5 * (sin(ld(0)) / ld(0)) * sin(220 * 2 * PI * t)'"
[me@host: ~]$ # use sinc function as frequency
[me@host: ~]$ ffplay -f lavfi "
> aevalsrc='
> st(0, 4 - mod(t * PI, 8)) ;
> 0.5 * sin(220 * (sin(ld(0)) / ld(0)) * 2 * PI * t)'"
expm1(x), log1p(x), cosm1(x)¶
expm1(x)
calculates \(\exp(x) - 1\), log1p(x)
calculates expm1(x)
’s inverse \(\log_{e}(1 + x)\),
and cosm1(x)
calculates \(\cos(x) - 1\):
Note
Note that this direct evaluation may differ from the result of the dedicated function that your favorite language provides. For example, ‘expm1’ which is provided by a modern standard C library avoids the loss of precision for small x.
lcm(x, y)¶
The least common multiple of x and y:
[me@host: ~]$ # the least common multiple of 64 and 36 is 576.
[me@host: ~]$ ffplay -vf "scale=-1:'abs(64) / gcd(64, 36) * abs(36)'" video.mkv
- see also
dim(x, y)¶
Dim returns the maximum of x - y or 0:
[me@host: ~]$ ffplay -vf "pad='1280:720:max(0,(ow-iw))/2:max(0,(oh-ih))/2'" video.mkv
Window functions¶
It’s unlikely that you’ll use the window function in a filter graph for its intended purpose, but you might expect just the shape of the graph, for example to generate sound waveforms.
bartlett(n, M)¶
[me@host: ~]$ # use bartlett function as amplitude (M=11)
[me@host: ~]$ ffplay -f lavfi "
> aevalsrc='
> st(0, 2 / (11 - 1)) ;
> st(1, 1 / ld(0)) ;
> 0.5 * (ld(0) * (ld(1) - abs(t - ld(1)))) * sin(440 * 2 * PI * t)':d=10" -autoexit
hanning(n, M)¶
[me@host: ~]$ # use hanning function as amplitude (M=11)
[me@host: ~]$ ffplay -f lavfi "
> aevalsrc='
> 0.5 * (
> 0.5 - 0.5 * cos(2 * PI * t / (11 - 1))
> ) * sin(440 * 2 * PI * t)':d=10" -autoexit
hamming(n, M)¶
[me@host: ~]$ # use hamming function as amplitude (M=11)
[me@host: ~]$ ffplay -f lavfi "
> aevalsrc='
> 0.5 * (
> 0.54 - 0.46 * cos(2 * PI * t / (11 - 1))
> ) * sin(440 * 2 * PI * t)':d=10" -autoexit
blackman(n, M)¶
[me@host: ~]$ # use blackman function as amplitude (M=11)
[me@host: ~]$ ffplay -f lavfi "
> aevalsrc='
> st(0, 2 * PI * t / 11) ;
> 0.5 * (
> 0.42 - 0.5 * cos(ld(0)) + 0.08 * cos(2 * ld(0))
> ) * sin(440 * 2 * PI * t)':d=10" -autoexit