Stretch to Layer Length

Keyframed animation rescales itself to fill the trimmed layer — 2 seconds or 20, same keyframes.

Expression Code
// Stretch to Layer Length
// Apply to any property that has keyframes
out = value;
if (numKeys >= 2) {
progress = clamp((time - inPoint) / (outPoint - inPoint), 0, 1);
t0 = key(1).time;
t1 = key(numKeys).time;
out = valueAtTime(t0 + progress * (t1 - t0));
}
out;
Keyframe your animation as normal, then apply this to the same property. The span from the first to the last keyframe is remapped across the layer's trimmed length, so dragging the layer's in or out point retimes the whole animation proportionally. With fewer than two keyframes it leaves the value untouched.
Back to Easing & Timing