Skip to content

Instantly share code, notes, and snippets.

@eliemichel
Created August 8, 2020 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliemichel/1efebe3d52efdb82add8d94672d32a54 to your computer and use it in GitHub Desktop.
Save eliemichel/1efebe3d52efdb82add8d94672d32a54 to your computer and use it in GitHub Desktop.
Temporal Stabilization for AfterEffects
// Select the layer to apply remapping to
// (the rush or any edited version of the rush as long as
// the in/out timings match the original)
var layer = app.project.activeItem.selectedLayers[0];
var timeRemapping = layer.property("ADBE Time Remapping");
// Remove previous keys
while (timeRemapping.numKeys > 0) {
timeRemapping.removeKey(1);
}
// Add new keys
layer.timeRemapEnabled = true;
timeRemapping.setValuesAtTimes(correctedTimes, times);
// Select a layer that has an animated scale
// (e.g. a layer on which a tracking with scaling enabled has been applied)
var layer = app.project.activeItem.selectedLayers[0];
var transform = layer.property("ADBE Transform Group");
var scaleProperty = transform.property("ADBE Scale");
var times = [];
var scales = [];
for (var i = 1 ; i <= scaleProperty.numKeys ; ++i) {
times.push(scaleProperty.keyTime(i));
scales.push(scaleProperty.keyValue(i)[0]);
}
// process remapping
var minTime = Math.min.apply(null, times);
var maxTime = Math.max.apply(null, times);
var minScale = Math.min.apply(null, scales);
var maxScale = Math.max.apply(null, scales);
var slope = (maxScale - minScale) / (maxTime - minTime);
var correctedTimes = Array(times.length);
correctedTimes[0] = times[0];
for (var i = 1 ; i < times.length ; ++i) {
correctedTimes[i] = correctedTimes[i - 1] + Math.max(scales[i] - scales[i - 1], 0.001) / slope;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment