Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trim comp by avoiding music track layers

  • Trim comp by avoiding music track layers

    Posted by Avinash Ramanath on May 2, 2017 at 7:21 am

    Hi 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 extension

    killDeadSpace(slateComp, false);

    var totalDuration = 0;
    for(i = 0; i < slateComp.numLayers; i++) {
    currLayer = slateComp.layers[i + 1];
    totalDuration += currLayer.source.duration;
    }
    slateComp.duration = totalDuration;

    Avinash Ramanath replied 6 years, 9 months ago 2 Members · 6 Replies
  • 6 Replies
  • Steve Sierra

    May 2, 2017 at 8:55 am

    Hi,

    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 !

  • Avinash Ramanath

    May 2, 2017 at 10:23 am

    Hi Steve,
    No it’s not working.

  • Steve Sierra

    May 2, 2017 at 10:39 am

    Did 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 pm

    Thanks 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 am

    Hi,
    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 &lt; 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 &lt;= 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 pm

    Hi,
    Can you please make the above code work, even if the layers stacking order is from bottom to top.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy