FFMPEG fade in/out expressions
I’ve been playing with FFMPEG lately mulling over a plugin for Appcelerator Titanium and figured we’ll need a text rendering with nice fading in/out effect. There’s text drawing filter in FFMPEG, but not a function to easily fade it, so I came up with a couple of expressions of my own. I’m working with alpha channel here, but it can easily be applied to other properties.
Fading in
alpha='if(lt(t,t1),0,(t-t1)/t2)'
t1
- start time (in seconds),t2
- length (in seconds).
Fading out
alpha='if(lt(t,t1),1,(t2-(t-t1))/t2)'
t1
- start time (in seconds),t2
- length (in seconds).
Fading in and out
alpha='if(lt(t,t1),0,if(lt(t,t1+t2),(t-t1)/t2,if(lt(t,t1+t2+t3),1,if(lt(t,t1+t2+t3+t4),(t4-(t-t1-t2-t3))/t4,0))))'
t1
- fade in start time (in seconds),t2
- fade in length (in seconds),t3
- time to keep fully opaque (in seconds),t4
- fade out length (in seconds).
If you happen to know a better way or shorter expressions, please let me know.