Creating consistent fade in and outs on something like subtitles in a video can become rather tedious over time especially if you are changing the the duration of those layers at any point. Using the expressions functionality within after effects you can easily automate these fades with a little bit of code.

Simply copy and paste the code below onto the opacity property of the layer. You will need to alt+click the little stop watch on the opacity layer (command+click on mac… I assume?) and then paste the expression into the expression editor.

To learn more about expression check out Adobe’s Learn Expression Basics Page, anyway without further delay here is the code.

// Automatic Fade in and out for after effects by Francois Marais,

dur = outPoint - inPoint;
// Specify your fade times
fadeInTime = 0.6; // Total Seconds
fadeOutTime = 0.6;
// Specify your opacity preferences
startOpacity = 0;
endOpacity = 100;

fadeIn = linear(time,inPoint,inPoint+fadeInTime,startOpacity, endOpacity);
fadeOut = linear(time,outPoint-fadeOutTime,outPoint-thisComp.frameDuration,endOpacity, startOpacity);

(time < (dur/2+inPoint))? fadeIn : fadeOut

Update: The code can be compressed into a single line expression. I feel the above version is easier to read, understand and customise, and when someone is googling solutions the more expanded versions are better received. Below is the shorter example, special thanks to the guys on Reddit.

// Automatic Fade in and out for after effects
Math.min(linear(time,inPoint,inPoint + .5,0,100),linear(time,outPoint - .5,outPoint,100,0));

I hope this helped someone, somewhere feel free to share, customise and let me know what you ended up doing with it.

All the best, Francois.

Leave a comment

Leave a Reply