Destabilize Layer

Moderator: Paul Tuersley

Post Reply
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

This script takes a stabilized layer, precomposes it, then adds expressions
that counter the effects of the original stabilization.

Download DestabilizeLayer_v1.jsx.zip

If you are trying to Motion Track an element on to some moving footage,
it is often easier to stabilize that footage first. You can then easily line up
the 'element to be tracked on' over the stabilized footage before applying
the inverse of that stabilization to reintroduce the footage's original
motion.

Here's how you do it:
1. Drop your movie footage into a comp and choose Animation > Stabilize
Motion from the main menu.

2. Stabilize the footage. You can choose to stabilize Position, Rotation and
Scale. When finished, hit Apply in the Tracker Controls and check the
results of the stabilization.

3. With the stabilized layer selected, run the DestabilizeLayer script. You
will now have two comps, one ending with (stab) and one with (destab).

4. Open the (stab) comp and place a still element or solid over the stabilized
area.

5. Finally, in the (destab) comp, you will see this element is now perfectly
(hopefully) tracked on to the movie footage.
Jonas
Posts: 10
Joined: August 12th, 2008, 11:40 am

Hello! I know this is old, but the link is not working. If this is still compatible with AE CC, is there a new location for it?
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Hi Jonas,

I actually do this differently these days. Stabilize the layer, make it a 3D layer, add a camera and parent the camera to the layer. When the camera is off the layer will appear stabilized. When the camera is on it will be non-stabilized. Any other layers you add, as long as you enable their 3D switch, will be locked to the layer you stabilized.

It's a much better solution, but if you prefer I can dig out the old script and try to figure out a way to make it downloadable again.

Paul
Jonas
Posts: 10
Joined: August 12th, 2008, 11:40 am

Thanks Paul, but the new way sounds just fine. Hadn't run across that technique yet bit it makes sense and is more up my alley. No math... for me!
Thanks again,

Chris
Jonas
Posts: 10
Joined: August 12th, 2008, 11:40 am

Hey Paul! The reason I was stabilizing & de-stabilizing was to do a mesh warp on a face, not composite layers with it. The 3D camera technique isn't really working because I am applying the Mesh Warp effect to the stabilized comp so turning the camera on within that comp allows the warp to slip again. I am not sure how to de-satbilize the stabilized comp in this instance.

In this case is your old script still the best bet?
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You could just duplicate the comp with stabilized layer / camera combo. In first one turn off camera, treat as normal 2D stabilized layer. In second comp turn on camera, drag other comp into this comp, make it a 3D layer.

It's really just the same thing anyway. But here's my old script so you have both options:

Code: Select all

// Destabilize Layer V1.0
// created by Paul Tuersley, May 2004

// This script takes a stabilized layer, precomposes it, then adds expressions
// that counter the effects of the original stabilization.

// If you are trying to Motion Track an element on to some moving footage, it is
// often easier to stabilize that footage first. You can then easily line up the
// 'element to be tracked on' over the stabilized footage before applying the
// inverse of that stabilization to reintroduce the footage's original motion.

// Here's how you do it:
// 1. Drop your movie footage into a comp and choose Animation > Stabilize Motion
// from the main menu.

// 2. Stabilize the footage. You can choose to stabilize Position, Rotation and
// Scale. When finished, hit Apply in the Tracker Controls and check the results
// of the stabilization.

// 3. With the stabilized layer selected, run the DestabilizeLayer script. You
// will now have two comps, one ending with (stab) and one with (destab).

// 4. Open the (stab) comp and place a still element or solid over the stabilized
// area.

// 5. Finally, in the (destab) comp, you will see this element is now perfectly
// (hopefully) tracked on to the movie footage.	


// main script

//  MAKE SURE COMP IS SELECTED
var activeItem = app.project.activeItem;
if (activeItem == null || !(activeItem instanceof CompItem)){
	alert("Please select the layer to destabilize and run the script again");
} else {

	// MAKE SURE 1 LAYER IS SELECTED
	var selectedLayers = activeItem.selectedLayers;
	if (activeItem.selectedLayers.length != 1 ) {
		alert("Please select one layer in the active comp and run the script again.");
	} else {
		
		app.beginUndoGroup("Destabilize Layer");

		// MAKE INDEX ARRAY FOR SELECTED LAYER FOR PRECOMPOSE
		var selectedLayerIndex = new Array();
		selectedLayerIndex[0] = selectedLayers[0].index;

		// MAKE NOTE OF STABILIZED LAYERS NAME
		var stabLayerName = selectedLayers[0].name.toString();

		// ADDS STAB TO END OF PRECOMP NAME
		// checks whether comp name is too long to add to, if so then truncates first.
		var new_name = activeItem.name;
		if (new_name.length <= 22) {
			new_name += "  (stab)";
		} else {
			new_name = new_name.substring(0,22) + "  (stab)";
		}

		// PRECOMPOSES THE STABILIZED LAYER
		activeItem.layers.precompose(selectedLayerIndex, new_name);

		// ADDS DESTAB TO END OF PRECOMP'S NAME
		// CHECKS WHETHER COMP NAME IS TOO LONG TO ADD TO, IF SO THEN TRUNCATES FIRST
		if (activeItem.name.length <= 22) {
			activeItem.name += " (destab)";
		} else {
			activeItem.name = activeItem.name.substring(0,22) + " (destab)";
		}

		// COLLAPSE TRANSFORMATIONS ON PRECOMP LAYER
		activeItem.selectedLayers[0].collapseTransformation = true;

		// SHORTCUT FOR LAYER TO DESTABILIZE
		var destab = activeItem.selectedLayers[0];

		// POSITION TO ANCHOR POINT 
		var exprString = "comp(\"" + new_name + "\").layer(\"" + stabLayerName + "\").position;";
		destab.property("Anchor Point").expression = exprString;

		// ANCHOR POINT TO POSITION
		var exprString = "comp(\"" + new_name + "\").layer(\"" + stabLayerName + "\").anchorPoint;";
		destab.property("Position").expression = exprString;

		//INVERT SCALE
		var exprString = "x = (100 / comp(\"" + new_name + "\").layer(\"" + stabLayerName + "\").scale[0]) * 100;"+
			" y = (100 / comp(\"" + new_name + "\").layer(\"" + stabLayerName + "\").scale[1]) * 100;"+
			" [x,y];";
		destab.property("Scale").expression = exprString;

		// INVERT ROTATION
		var exprString = "comp(\"" + new_name + "\").layer(\"" + stabLayerName + "\").rotation * -1;";
		destab.property("rotation").expression = exprString;	

		app.endUndoGroup();	
	}
}
Jonas
Posts: 10
Joined: August 12th, 2008, 11:40 am

Thanks Paul. I played with the camera technique for a while but couldn't come up with that solution. I was close, but no dice. As usual, a brilliantly simple answer! Thanks for the script as well.
Post Reply