ffmpeg-geq-expr — procedural expression filters
Context: $ARGUMENTS
Power-user creative filters where you hand-write a math expression and ffmpeg evaluates it per-pixel (geq), per-sample (aeval), per-pair (lut2), or per-metric (drawgraph). Grammar is the same everywhere: see references/expressions.md.
Quick start
- Custom per-pixel effect: → Step 1 → pick
geq - Custom per-sample audio effect: → Step 1 → pick
aeval - Blend/combine two videos pixel-by-pixel with math: → Step 1 → pick
lut2 - Real-time metric graph burned into video: → Step 1 → pick
drawgraph - SVG overlay driven by frame metadata: → Step 1 → pick
drawvg - Light-on-dark persistence / phosphor trails: → Step 1 → pick
lagfun - Feedback-loop picture-in-picture: → Step 1 → pick
feedback - Shuffle frame order: → Step 1 → pick
random
When to use
- You need a per-pixel/per-sample effect that no named filter ships with (gradients, plasma, custom noise, chromatic aberration, vignettes).
- You want to wire filter metadata (
signalstats,ebur128,blockdetect) into a visible QC graph. - You want to combine two aligned inputs with arbitrary math, not
blend's fixed modes. - You want a one-off creative look without writing a C filter.
Do NOT use for things with a dedicated filter — geq is typically 10–100× slower than a native filter. If vignette, lut3d, colorchannelmixer, curves, etc. can do it, use those.
Step 1 — Pick the right filter
| Need | Filter | Domain |
|---|---|---|
| Per-pixel math on one video | geq | spatial (X,Y) + temporal (T,N) |
| Per-sample math on audio | aeval | per-sample per-channel |
| Two-video pixel math | lut2 | pairs of samples (x, y) from inputs |
| Graph metadata values | drawgraph | per-frame scalar from metadata keys |
| SVG / VGS vector overlay | drawvg | per-frame VGS script |
| Frame-order shuffle | random | temporal only |
| Feedback picture-in-picture | feedback | spatial box + time |
| Dark-decay afterimage | lagfun | per-pixel with decay |
Step 2 — Write the expression
Grammar highlights (full table in references/expressions.md):
- Built-in constants:
PI,E,PHI,TAU. - Functions:
sin,cos,tan,asin,acos,atan,atan2,exp,log,sqrt,hypot(a,b),pow(a,b)ora^b,mod(a,b),abs,floor,ceil,round,trunc,clip(v,a,b),between(v,a,b),if(c,t,e),ifnot(c,e),gt(a,b),lt(a,b),gte,lte,eq(a,b),not(x),random(seed),st(N,v)store,ld(N)load (26 slots, N=0..25),print(v)to stderr. - Operators:
+ - * / %,^power,&& || !logic,? :ternary is NOT supported (useif(c,t,e)).
geq per-plane YUV:
geq=lum='X+T*10':cb=128:cr=128 # moving luminance ramp, neutral chroma
geq=lum='255*(X/W)':cb='128+64*sin(T)':cr='128+64*cos(T)'
geq RGB (requires planar RGB pixfmt):
format=gbrp,geq=r='255*X/W':g='255*Y/H':b=0 # diagonal RG gradient
format=gbrp,geq=r='b(X,Y)':g=g:b='r(X,Y)' # BGR channel swap
Vignette via geq (hand-rolled):
format=gbrp,geq=r='r(X,Y)*clip(1-pow((X-W/2)/(W/2),2)-pow((Y-H/2)/(H/2),2),0,1)':g='g(X,Y)*clip(1-pow((X-W/2)/(W/2),2)-pow((Y-H/2)/(H/2),2),0,1)':b='b(X,Y)*clip(1-pow((X-W/2)/(W/2),2)-pow((Y-H/2)/(H/2),2),0,1)'
aeval (per-sample):
aeval=val(0)*0.5|val(1)*0.5:channel_layout=stereo # halve volume (note | between exprs)
aeval=val(ch)*sin(2*PI*5*t):c=same # 5 Hz tremolo
aevalsrc (synth):
aevalsrc='sin(2*PI*440*t)':channel_layout=mono:sample_rate=48000:duration=2
lut2 (two inputs, same size/pixfmt):
lut2=c0='(x+y)/2':c1='(x+y)/2':c2='(x+y)/2' # pixel average blend
drawgraph (metadata chart):
signalstats,drawgraph=m1=lavfi.signalstats.YAVG:fg1=0xff00ff:min=0:max=255:size=1280x200
drawvg (SVG/VGS overlay):
drawvg=cfg='<svg><rect x=20 y=20 width=200 height=60 fill="red"/></svg>'
random (frame order):
random=frames=30:seed=42
feedback (recursive PiP):
feedback=x=10:y=10:w=100:h=100
lagfun (dark decay / afterimage):
lagfun=decay=0.9
Step 3 — Run and debug
Always test on 2 seconds first:
ffmpeg -i in.mp4 -t 2 -vf "<expr-filter>" -y out_test.mp4
See parse errors: -loglevel debug prints tokens as they parse. A silent output or black frames without stderr output almost always means a typo or an operator ffmpeg's parser rejected.
Drop print() into any expression to dump a value per evaluation to stderr:
geq=lum='print(T)':cb=128:cr=128
Use the helper:
uv run ${CLAUDE_SKILL_DIR}/scripts/expr.py geq --input in.mp4 --output out.mp4 --lum 'X+T*10'
Available scripts
scripts/expr.py— subcommands:geq,aeval,lut2,drawgraph,feedback,lagfun. All support--dry-runand--verbose. Autodetects RGB vs YUV forgeqbased on which flags you pass.