<p>This YouTube tutorial explains how to do this:</p>
<p><strong><a href="https://www.youtube.com/watch?v=nUcBPjlFSTI" rel="nofollow noreferrer">After Effects Quick Tip - How to Add Auto Opacity To Layers and Footage
</a></strong></p>
<ol>
<li>Add an expression to the layer's <code>Opacity</code> property by alt-clicking the stopwatch.</li>
<li>Paste this expression into the box:</li>
</ol>
<pre><code>fadeDuration = .5;
Math.min(linear(time,inPoint,inPoint + fadeDuration, 0, 100), linear(time,outPoint - fadeDuration,outPoint,100,0))
</code></pre>
<p>The layer will now fade in for half a second, and then fade out for half a second based on its in and out points.</p>
<p>If want to specify the length in <strong>frames</strong> instead of <strong>seconds</strong>, change the first line of the expression to be this:</p>
<pre><code>fadeDuration = thisComp.frameDuration * 5;
</code></pre>
<p>Now the layer will fade in and fade out over a period of <strong>5</strong> frames.</p>

CC BY-SA 4.0
2021-02-14T07:22:36.897Z
2021-02-14T07:22:36.897Z
Allen Ellis
<p>I want to get the time / duration of the layer, when I stretch or lengthen the layer to produce an effect, for example I want the opacity of a layer to go to 0% 5 frames before the end of the layer, and if I lengthen or I cut that layer that those 5 frames are the same at the end of the layer, regardless of the length of the layer</p>

<after-effects><after-effects-expressions>
Detect duration of layer
manuel-ae
# Detect duration of layer

(Asked by: username_0 on 2021-02-10)

I want to get the time / duration of the layer, when I stretch or lengthen the layer to produce an effect, for example I want the opacity of a layer to go to 0% 5 frames before the end of the layer, and if I lengthen or I cut that layer that those 5 frames are the same at the end of the layer, regardless of the length of the layer

**Tags:** after-effects, after-effects-expressions


---

## 1 answers

### Answer by username_1 on 2021-02-14. Score: 0

This YouTube tutorial explains how to do this:
After Effects Quick Tip - How to Add Auto Opacity To Layers and Footage


Add an expression to the layer's Opacity property by alt-clicking the stopwatch.
Paste this expression into the box:

fadeDuration = .5;
Math.min(linear(time,inPoint,inPoint + fadeDuration, 0, 100), linear(time,outPoint - fadeDuration,outPoint,100,0))

The layer will now fade in for half a second, and then fade out for half a second based on its in and out points.
If want to specify the length in frames instead of seconds, change the first line of the expression to be this:
fadeDuration = thisComp.frameDuration * 5;

Now the layer will fade in and fade out over a period of 5 frames.


---

