ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Setting the TimeRemap value of 2 Keyframes

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sascha Koeth
Setting the TimeRemap value of 2 Keyframes
on Feb 19, 2020 at 10:57:45 pm


I am trying to find the correct syntax to set the TimeRemap value of 2 Keyframes. At the moment I have the following expressions placed onto the Time Remap property of a videoclip layer where I have placed two keyframes manually before: (See expressions box)

The idea is to set the time remap value to 1 second at the start of the composition and to set the value to 2 seconds at the end of the composition. So the videoclip allways shows the section between 1 sec and 2 sec no matter how long the comp is.

AE tells me "key(1).setValueAtTime" is not a function. So I guess i did forget something or have the order of strings wrongly.

I am aware of the fact that normaly you would firstly check if there are any keyframes at all and those kind of things, but as this is done in a closed setup where I always know that the 2 keyframes are there I would love to keep the expression as short and simple as possible.

Any helping ideas anybody?



key(1).setValueAtTime(0, 1);
key(2).setValueAtTime(thisComp.duration, 2);

HAYWOOD Digital Studio

Return to posts index

Dan Ebberts
Re: Setting the TimeRemap value of 2 Keyframes
on Feb 20, 2020 at 12:46:18 am

I'm not exactly sure what you're up to here, but setValueAtTime() is used in scripting, not expressions. And in scripting, you would use it to create keyframes, not to manipulate existing keyframes. With a time remapping expression, all you can do is manipulate the resulting remapped time.


Return to posts index

Sascha Koeth
Re: Setting the TimeRemap value of 2 Keyframes
on Feb 20, 2020 at 3:45:00 pm

Hi Dan,

thanks for the info! You are right. I have grabbed the section out of a script reference and not an expression reference. But I actually found 2 solutions for my problem that "magically" work. But maybe you can tell me why they actaully work, as it´s not clear to me:

linear(time, key(1), key(2), 1, 2)

When I use this expression it doesn´t seam to matter where I actually put the keyframes. The expression always uses the complete comp length as the "source range". How does the expression "know" that it should put the keys at the beginning and end of the comp to define the source range?


Same question with this solution with the inPoint outPoint solution. As the time ramped layers outpoint is NOT the comps end point how does the expression "knows" that instead of using the layers outPoint (which outPoint normaly stands for, right?) it should use the comps "outPoint"?



HAYWOOD Digital Studio

Return to posts index

Sascha Koeth
Re: Setting the TimeRemap value of 2 Keyframes
on Feb 20, 2020 at 7:07:51 pm

After some further investigation I gathered some more Info about my Issue that might be interesting for others having the same problem:

Can I set/change a keyframe with expressions:
No, but you can read their values into variables and then change the variables which in the end change the property. It´s important to understand this seamingly irritating difference to build working expressions. Keyframes and all their "values" are read-only to begin with. Any expression can only overwrite/modify the values they take from them as they bring those modified values back into the property, not actually change the keyframe you see in the timeline. It's inherent in how AE evaluates property streams:

Property base value --> Keyframe value --> Expression result (Including expression manuipulating effects like expression slider controls) --> Changed property value.

So the keyframe value can only be the base for changing the property value with expressions. Think of it as: You have to first convert the key().time or key().value or key.index into an expression variable. For example mytimevariable = key().time Then handle the expression variable as the "editable keyframe" and forget the actual keyframe on the layer in the timeline, as you can NOT change its value or its position on the timeline (time) or add new keyframes with expressions. Your new variable IS your keyframe from there on and that is editable and can be returned to the property as a value.

Puh. After I wrapped my head around this a lot of things made more sense.

In my current case I concluded I did not need the time remapping keyframe values at all but only the "time" property coming from the comps timeline progress and using that to manipulate the time value of the layer which I could adress through the time remap property:

invar = framesToTime(parseInt(thisComp.layer("MainVideoInPoint").text.sourceText));
outvar = framesToTime(parseInt(thisComp.layer("MainVideoOutPoint").text.sourceText));
linear(time, 0, thisComp.duration - framesToTime(1), invar, outvar);

I am using two textlayers to set the in and out boundries of the part of the original clip that get´s shown within my comp.

Interesting side note: thisComp.duration does not equal the time of the last frame of the comp. You have to subtract a frame. Which probably has something to do with the Comp starting at frame 0.

So thanks a lot! Problem solved!

HAYWOOD Digital Studio

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 All Rights Reserved