Drawing graph with `geq’

doc

(ffmpeg-utils)3. Expression Evaluation, https://ffmpeg.org/ffmpeg-filters.html#geq

It is metadata that drawgraph and adrawgraph target. The expressions that can be used for drawtext are very limited. So, for example, when using a complex expression for overlay, there is no easy way to visually confirm the correctness of the expression.

The method introduced here is the so-called “last resort”. If you can visualize the expression you want to use with other tools (eg python’s matplotlib, MS Excel, etc), basically you should use that. Conversely, there are only a few cases that can only be realized with this approach. That is when ffmpeg’s own expression is included, The most typical examples are st and ld.

Watch on youtube.com
00:00:45
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='(1 + sin(X / (10 * PI))) / 2'

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720
,format=rgb24
,geq='r=255:g=255*not(${onl}):b=255*not(${onl})'
,vflip
,loop=-1:size=2,trim=0:30
" ${pref}.mp4
00:01:15
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='(1 + sin(X / (10 * PI))) / 2'

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip
,loop=-1:size=2,trim=0:30
" ${pref}.mp4
00:01:45
#! /bin/sh
pref="`basename $0 .sh`"
#
X="(T*100)"

# expression you want to evaluate
target_expr='(1 + sin(X / (10 * PI))) / 2'

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(T*100)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((T*100)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720:d=30
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip

" ${pref}.mp4
00:02:15
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='(1 + sin(X / (10 * PI))) / 2'

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X - T*100)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X - T*100)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720:d=30
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip

" ${pref}.mp4
00:02:45
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='(1 + sin(X / (10 * PI))) / 2'

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(Y, ${Y})"

#
ffmpeg -y -filter_complex "
color=s=1280x720
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip
,loop=-1:size=2,trim=0:30
" ${pref}.mp4
00:03:15
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='(st(0, X) - 0.5 * ld(0)) / 640'  # identical to "(X - 0.5 * X) / 640"

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip
,loop=-1:size=2,trim=0:30
" ${pref}.mp4
00:03:45
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='st(0, X) * ld(0) / pow(1280, 2)'  # identical to "X * X / pow(1280, 2)"

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip
,loop=-1:size=2,trim=0:30
" ${pref}.mp4
00:04:15
#! /bin/sh
pref="`basename $0 .sh`"
#
X="X"

# expression you want to evaluate
target_expr='st(0, X - 640) * ld(0) / pow(640, 2)'  # identical to "(X - 640) * (X - 640) / pow(640, 2)"

#
tmpl="H * (${target_expr})"  # scale to image height
Y="`echo \"${tmpl}\" | sed 's@X@(X)@g'`"
Y_b="`echo \"${tmpl}\" | sed 's@X@(((X)) - 1)@g'`"

# expression for judgement whether if (X, Y) is on the curve.
onl="eq(X, floor(${X})) * lte(abs(Y - (${Y})), max(3, abs(${Y} - ${Y_b})))"

#
ffmpeg -y -filter_complex "
color=s=1280x720
,format=rgb24
,geq='r=255*not(${onl}):g=255*not(${onl}):b=255'
,vflip
,loop=-1:size=2,trim=0:30
" ${pref}.mp4