ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using expression to loop layer and trim Work Area?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Xavier Paredes
Using expression to loop layer and trim Work Area?
on Aug 21, 2018 at 3:26:05 am
Last Edited By Xavier Paredes on Aug 21, 2018 at 3:28:30 am

I have about 300 short videos of varying lengths ranging from 00:00:00:07 (7 frames) to 00:00:33:02 (33 seconds and 2 frames). I have to loop most of them because they are too short.

I have done some research and found that I can use expressions to do looping. For example, the expression below will loop the layer 10 times.

Also, by design the expression will freeze the video that's past the last loop, therefore, I will need to trim the work area at the location of the last frame of the last loop. What would be the easiest/quickest way to do this?

Is it possible to perhaps add something to the expression so that a marker is added to that last frame of the last loop so I can quickly find it and do the trim?

Lastly, is there a way to add something to the expression that can automatically trim the work area? I don't think so but I figured I'd ask.

Any other techniques would be appreciated since I have so many videos to deal with and my carpal is acting up. : )

Thank you for any help.

nLoops = 10;
if (numKeys > 1){
loopDur = key(numKeys).time - key(1).time;
n = Math.floor((time - key(1).time)/loopDur);
if (n &lt; nLoops){
t = (time - key(1).time)%loopDur;
valueAtTime(key(1).time + t);
}else{
valueAtTime(key(numKeys).time);
}
}else
value;


Xavier


Return to posts index

Scott McGee
Re: Using expression to loop layer and trim Work Area?
on Aug 21, 2018 at 7:57:32 am

You can do it with a script, otherwise you have to manually trim. Expressions don't trim your Comp.

So you could implement your expression into said script. Add a text box for time length, so it's a bit more dynamic. Hit the submit button and that will trim your activeComp and add the expression to your layer.

I do something similar for idents I used to make that ranged between 2-15 seconds.

If you want to trim the layer and not the comp. I guess you could add an opacity expression to switch itself off, but again if that's the case. Manually or script is the only way.


Return to posts index

Xavier Paredes
Re: Using expression to loop layer and trim Work Area?
on Aug 21, 2018 at 12:46:23 pm

Hi Scott,

Thank you for your reply. You wouldn't happen to have the script that you used to trim the comp handy would you?

I don't know how to script unfortunately :/

Xavier


Return to posts index


Xavier Paredes
Re: Using expression to loop layer and trim Work Area?
on Aug 21, 2018 at 12:53:53 pm

Forgot to ask, how would the script know where to trim the comp? Would it be able to use the marker I was hoping to be able to create with the expression (please see my original post)?

Xavier


Return to posts index

Scott McGee
Re: Using expression to loop layer and trim Work Area?
on Aug 21, 2018 at 4:30:21 pm

I'd have to dig it out as I don't work for that company anymore, but there is no reason why you couldn't use it to do it based on a marker, but I did mine based on seconds.

Unless Someone answers before hand I will come back to you maybe later on or tomorrow


Return to posts index

Scott McGee
Re: Using expression to loop layer and trim Work Area?
on Aug 22, 2018 at 8:49:41 am

I've updated it to include frames.

There might be an easier way to add frames and seconds, but I've bodged it this way and it works fine.

var win = new Window ("palette","Comp Duration",undefined);

var title = win.add('statictext',undefined,"Seconds");
var myTextSec = win.add('edittext',[100,120,150,140],0);
var title2 = win.add('statictext',undefined,"frames");
var myTextFrames = win.add('edittext',[100,120,150,140],0);
var btn = win.add('button',undefined,"Submit");

btn.onClick = function(){
var myComp = app.project.activeItem;
var text1 = myTextSec.text;
var text2 = myTextFrames.text;
myComp.duration = text1;
myComp.duration += text2*myComp.frameDuration;// set duration
}

win.show();


All it's doing is changing the comp based on seconds, then changing it a second time to add the frames separately. If someone can offer a way to change it in one line cool. Otherwise this will work fine for you.


Return to posts index


Scott McGee
Re: Using expression to loop layer and trim Work Area?
on Aug 22, 2018 at 9:47:06 am

Forgot to mention that if you want to update comp length based on the outPoint of a selected layer.

var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers[0];
myComp.duration = myLayer.outPoint;

or you can do it based on cursor of time

var myComp=app.project.activeItem;
myComp.duration = myComp.time;

So these are a few other options available to you.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]