Skip to main content
Bradley Morris
Participating Frequently
October 9, 2021
Question

Rounding Time-Remapped Frames to Whole Numbers

  • October 9, 2021
  • 1 reply
  • 1835 views

I have applied my time remap, ALT-clicked the stopwatch, then gone Animation/ Keyframe Assistant/ Convert Expression to Keyframes.  However, I need to round these keyframe values up and down to whole numbers.

 

Is there an expression I can run after or along with the time remap which will result in key values of whole numbers?

 

I have tried playing with math.round, math.floor and timeToFrames, but I truly have no idea what I'm doing!  Any help would be greatly appreciated.  Thank you -

 

 

This topic has been closed for replies.

1 reply

Community Expert
October 9, 2021

Time remapping keyframes are based on seconds. If you round each keyframe to a whole number. Are you trying to round to the nearest frame? Changing the time display from timecode to will change how the numbers appear in the timeline, but any time you use an expression to drive time, no matter what the frame rate, if you generate a 2.00 you get 2 seconds if the comp frame rate is 30 or if the frame rate is 120 fps. Enter 2 in and expression and the time will always be 2 seconds.

 

Why do you want to round the keyframes to whole numbers? If you time remapped video footage, frames are going to be blended. If you time remapped a pre-comp that contains any kind of keyframe animation, there are n blended frames. For example, if you add a solid to the timeline and then animate the layer so that it moves 200 frames in 1 second, then you precompose the layer and time remap it you can have the layer move the same 200 frames but make it take 20 seconds and every frame will be perfect and there are no blended or duplicated frames.

 

Please explain your desired design goals a little clearer and we can probably help you figure out how to get exactly what you need. 

 

Bradley Morris
Participating Frequently
October 11, 2021

Hi, Rick -

Thank you for such a considered response.  Let me try to earn a bit more of your expertise by filling in a few details.

 

Yes, time remapping is based on seconds, but ultimately the remap is selecting from a limited number of frames in an image sequence.  What I need to do is round up or down to point to the frame that any given remapped key is actually referencing [barring the use of some artificial interpolation such as frame-blending].  Let me give you a real-world instance that I am currently working with.

 

I have been given a 246 frame sequence with a time remap applied.  If I bake out that curve, the values returned are, as expected, purely mathematical and more often than not yield fractional results expressed in decimals.  And so, for instance, on frame 50, the remapped key has a value of 3.09756 seconds, which, at 30 fps, is 92.9268.  Except that, in the real world, there is no frame 92.9268.  There is a frame 92 and there is a frame 93, but no other frame exists between the two. 

 

All I am trying to do is find a way to round that value up or down before exporting the data out of After Effects.  I have seen an expression that rounds X and Y values [before applying Animation/ Keyframe Assistant/ Convert Expression to Keyframes] when calculating for position.  I need to do basically the same thing, only to frame numbers.

 

I hope this helps clarify my goal!  Thank you in advance for any help you may be able to offer -

bradley

Community Expert
October 11, 2021

By far the easiest way to get to a specific frame at a specific time is to use an Expression Control Slider and multiply the value by the comp frame duration. This works perfectly if the Composition frame rate matches the footage frame rate. Set the slider to Frame 29 and the footage will be at frame 29. All you do is match the frame rate of the comp to the frame rate of the footage (image sequence), enable time remapping, then add an expression control slider to the footage layer, enable Time Remapping (Alt/Option + Ctrl/Cmnd + t), and then add the following expression:

 

 

effect("Frames")("Slider")*thisComp.frameDuration;

 

 

 I named the Slider "Frames" and all you have to do is set the slider keyframes to whole numbers. 

 

If you want all of the in-between frames to also be exactly on the nearest frame you could modify the expression like this to eliminate all blended frames:

 

 

frm = effect("Frames")("Slider");
Math.round(frm) * thisComp.frameDuration;

 

 

 

If your footage frame rate does not match the desired comp frame rate then the easiest fix is to interpret the footage in the Project Panel and make it match the comp's frame rate. That way a comp frame will always match a footage frame.

 

If for some crazy reason you have to keep the original frame rate for the footage and put that footage in a comp with a different frame rate then you need to figure out the frame duration of the original footage and just multiply that number by the slider value.

 

For example, if your footage was 23.976 fps then the frame duration would be 0.04170837504170837. That is pretty close because there are more decimal points in most frame rates, but it would get you to the closest frame if the comp and footage frame rates don't match. If you are time remapping, then the original footage frame rate doesn't make any difference so the simplest solution is to just match the comp and footage frame rate and use the expression control slider.

 

Hope this helps. Using the slider control is by far the easiest solution.