Skip to main content
Participating Frequently
November 25, 2014
Answered

Change size of video FootageItem in Layer

  • November 25, 2014
  • 1 reply
  • 1164 views

hi,

I'm replacing video footage in a Layer by using the following code (earlier in my code I declared 'layer'):

var targetVideo = 'pathTo/my.mov';              

var myFile = File (targetVideo);

if (myFile.exists) {              

           var importOptions = new ImportOptions(myFile);

           var theImport = app.project.importFile(importOptions);

           layer.replaceSource(theImport,true);                    

}

This replaces the source of the layer and seems to keep property values such as scale and rotation,

which is nice. But my target video is way bigger (higher resolution) than my source video,

and I would like to size it down so it looks the same after replacement while keeping transform properties applied to the source layer.


I can't just resize the layer or the layer.source because it gives me an error:

'Can not change attribute “width” of item “myVideo.mp4” because the item is neither a comp nor a solid.'

I guess I could try to nest the layer inside a comp or solid and then change the size of the parent layer.

Would that be the way to go or is there a simpler way to deal with this?

Thanks!

Jeff.

This topic has been closed for replies.
Correct answer belross

I did some digging in the documentation ( http://download.macromedia.com/pub/developer/aftereffects/scripting/After-Effects-CS6-Scripting-Guide.pdf ) and there is no way to change the width or height of a footageSource item or AVItem if its source is a footageSource. You can only change the width/height of a solid layer/item. This makes sense - normally if you select a solid layer and go to "Layer/Solid Settings..." you can set the dimensions, but you can't ever do the same for a footage item. Think about it - the way you resize footage in your comps is using simple Scale transformations. Therefore, the solution would be to scale the x and y of your new new footage to match the old footage. So something like this:

1. Calculate and save the width and height of your previous footage, taking into account possible scaling.

2. Replace footage.

3. Use Scale transformations on the new footage layer to match the old footage dimensions.

You're gonna need some math to figure out how to get it right, but that should be the gist of it.

1 reply

belrossCorrect answer
Participating Frequently
November 26, 2014

I did some digging in the documentation ( http://download.macromedia.com/pub/developer/aftereffects/scripting/After-Effects-CS6-Scripting-Guide.pdf ) and there is no way to change the width or height of a footageSource item or AVItem if its source is a footageSource. You can only change the width/height of a solid layer/item. This makes sense - normally if you select a solid layer and go to "Layer/Solid Settings..." you can set the dimensions, but you can't ever do the same for a footage item. Think about it - the way you resize footage in your comps is using simple Scale transformations. Therefore, the solution would be to scale the x and y of your new new footage to match the old footage. So something like this:

1. Calculate and save the width and height of your previous footage, taking into account possible scaling.

2. Replace footage.

3. Use Scale transformations on the new footage layer to match the old footage dimensions.

You're gonna need some math to figure out how to get it right, but that should be the gist of it.

JeffW.Author
Participating Frequently
November 27, 2014

yes, that seems to work, thanks!

Next thing I ran into was what to do when the layer has Scale keyframes.

This is how I adjust all of them by looping through them and set the one by one (in this example assuming

that the target video is 3x the scale of the source.

var scale = layer.scale; // Set the scale variable to the scale property of the layer object

var numKeys = scale.numKeys;//the number of keyframes                                                 

if(numKeys > 0) {

     for (var k= 1; k< numKeys + 1; k++) {//has keyframes, set scale per keyframe

          $.writeln("keyValue: " , scale.keyValue(k));

          layer.scale.setValueAtKey(k, scale.keyValue(k)/3)

     }

}

else {

    layer.scale.setValue(layer.scale.setValue(layer.scale.value/3));//no keyframes, simply set scale

}

                         }

All other keyframed transform properties stay intact, which makes sense too.

UQg
Legend
November 27, 2014

It would probably be easier (in particular if you need to change the scale again) to precompose the footage. (The precomp would be of the final size, and the footage inside it rescaled once and for all with no keyframe).

Then in your original comp scale values are the normal ones.