Page 1 of 1

Quantize Keyframes

Posted: April 1st, 2008, 8:26 am
by ahettinger
I screwed the pooch by working in 29.97 in one comp and 30 in another. When I copied some layers over, their keyframes got shifted ever so slightly and it's really screwing me up. Now I have about 1000000 keyframes that I'm selecting one by one trying to line them up with the frames because they're like a small fraction of a frame off center.

Can someone with more scriptastic skills tell me how to make a script that will do this, or clue me in if there's one already out there? I already googled this to death.

Thanks!

Re: Quantize Keyframes

Posted: April 1st, 2008, 1:42 pm
by Dan Ebberts
Here's a simple example. It assumes that you want to quantize the opacity keyframes of the first layer in the active comp:

Code: Select all

var myComp = app.project.activeItem;
var myProperty = myComp.layer(1).property("opacity");
var myValue, myTime;

for (var i = myProperty.numKeys; i > 0; i --){
  myValue = myProperty.keyValue(i);
  myTime = Math.round(myProperty.keyTime(i)/myComp.frameDuration)*myComp.frameDuration;
  myProperty.removeKey(i);
  myProperty.setValueAtTime(myTime,myValue);
}

Dan

Re: Quantize Keyframes

Posted: April 4th, 2008, 1:26 pm
by ahettinger
Thanks this is great!