Tip: After Effects expression to fade out audio
Hello! A quick tip on how to fade audio with Templater via an expression. Since Templater can dynamically swap a wide variety of media sources of varying lengths, you can’t count on keyframes to be able to accommodate the variation of durations for consistent fade-outs of audio tracks. Here’s a sample of how to do that. Apply this expression to the Audio Levels.
fadeTime = 30; //frames for fade audio.audioLevelsMin = -48; audio.audioLevelsMax = audio.audioLevels; layerDuration = outPoint - inPoint; singleFrame = thisComp.frameDuration; animateOut = linear(time, (outPoint - framesToTime(fadeTime+1)), (outPoint-singleFrame), audio.audioLevelsMax, audio.audioLevelsMin); [animateOut,animateOut];
In this example, the expression takes the audio level you’ve set and fades to -48 db over 30 frames (assuming 30fps composition, that is 1 second).
This post is deleted!
@jon I tried this expression to AE 2023 and it does not fade the audio.
There are no any error messages either, but I did not see this would have done anything.
Could you please confirm this expression is working on AE 2023?
@videohoney I just tested in AE 2023 and it still appears to be working. Are you applying the expression to the Audio Levels property? Is it the only expression on that property for that layer?
@jon Thank you for checking.
Yes, the expression is applied to the Audio Levels property, and it is only expression.
Here is a screenshot:
The audio does not fade at the end.
I do not know what I am doing wrong.
From the screenshot you posted, it appears that the work area/overall comp length might be cutting the audio layer off before it can get to the end, where the fade-out occurs. Would it be possible to adjust the duration of the “render” comp to ensure it’s long enough to get to the end of the audio file?
It might also be helpful to apply Templater to the layer and then check the “Comp Starts at In Point” and “Comp Ends at Out Point” options under the “Time” section. This should ensure that the comp is resized to fit the whole duration of the clip into the timeline.
If that doesn’t work, let us know, and we’ll see where we need to go from there. Additionally, please feel free to get in touch with us at firstname.lastname@example.org if you’d like to move this discussion to a more direct setting.
@videohoney did Jeff’s suggestion help? From the screenshot, the expression is likely working, but you have to shorten the length of the audio track (or extend the length of the comp) for the fade to work correctly. Also, the
audio.audioLevelson the first line of your expression shouldn’t be included.
@Jon Sorry for the late reply.
Yes, I got everything working with Jeff’s advice and your tips.
Big thanks for the help.