Activity › Forums › Adobe After Effects Expressions › Trim comp by avoiding music track layers
-
Trim comp by avoiding music track layers
-
Avinash Ramanath
May 2, 2017 at 7:21 amHi All, need your help.
I have the below function to stack layers in a comp and trims itself. Can you help in modifying this so that it ignores music tracks with .mp3 and .wav extensionkillDeadSpace(slateComp, false);
var totalDuration = 0;
for(i = 0; i < slateComp.numLayers; i++) {
currLayer = slateComp.layers[i + 1];
totalDuration += currLayer.source.duration;
}
slateComp.duration = totalDuration; -
Steve Sierra
May 2, 2017 at 8:55 amHi,
I’m not sure this is the most efficiant way, but you could maybe use this. You have to be at the Item level :
var currItem = currLayer.source;
if(currItem.hasAudio == true && currItem.hasVideo == false){
}else{//———————-Your code here—————
};
I can’t test this, I have a project rendering… and I think “.hasAudio” doesn’t exist for CS6, and that’s what I’m using.
Hope it helps anyway,Cheers !
-
Steve Sierra
May 2, 2017 at 10:39 amDid you do it like this ?
killDeadSpace(slateComp, false);
var totalDuration = 0;
for(i = 0; i < slateComp.numLayers; i++) {
var currLayer = slateComp.layers[i + 1];
var currItem = currLayer.source;
if(currItem.hasAudio == true && currItem.hasVideo == false){
}else{
totalDuration += currLayer.source.duration;
}
slateComp.duration = totalDuration;Still can’t test 😉
-
Avinash Ramanath
May 2, 2017 at 2:39 pmThanks Steve,
It was getting complicated to recognise the source of the file hence iam referring to the layer by name as “music”. I will post the working code here in some time. Thanks -
Avinash Ramanath
May 4, 2017 at 4:57 amHi,
Here is the working code.function killDeadSpace(cItem, preserveOverlap) {
if(preserveOverlap == true) {for(i = cItem.layers.length; i > 1; i--) {
var curLayer = cItem.layers[i];
if(curLayer.name == 'Music') continue; // ignoring this layer
var prevLayer = cItem.layers[i - 1];
var deadSpace = (curLayer.inPoint) - (prevLayer.outPoint);if(deadSpace > 0) {
var inBefore = curLayer.inPoint;
var diff = curLayer.inPoint - curLayer.startTime;
curLayer.startTime = prevLayer.outPoint - diff;
var inAfter = curLayer.inPoint;
var amountMoved = inBefore - inAfter;var j = curLayer.index;
while(j < cItem.layers.length) {
//cItem.layers[j + 1].label = 12;
cItem.layers[j + 1].startTime = cItem.layers[j + 1].startTime - amountMoved;
j++;
};
}
else {continue;
}
}
}
else {
for(i = 2; i <= cItem.layers.length; i++) {var curLayer = cItem.layers[i];
if(curLayer.name == 'Music') continue; // ignoring this layer
var prevLayer = cItem.layers[i - 1]
var diff = curLayer.inPoint - curLayer.startTime;
curLayer.startTime = prevLayer.outPoint - diff - 0; // time to overlap
}
}
} -
Avinash Ramanath
May 4, 2017 at 12:25 pmHi,
Can you please make the above code work, even if the layers stacking order is from bottom to top.
Reply to this Discussion! Login or Sign Up
Log in to reply.