Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Creating a script to split a footage into multiple comps?

  • Creating a script to split a footage into multiple comps?

    Posted by Alexis Coco on April 27, 2020 at 4:20 pm

    Hi there,

    I’m working on a script that allows me to cut a long footage into several compositions.

    The idea is that on a 5 minutes footage for example, I get 30 seconds comps with a 10 seconds delay on my footage between each comps. Finally, I’ll have 27 comps of 30 seconds with my footage in them, which starts 10 seconds later each time.

    Unfortunately, I can’t figure out how to create a function that allows me to cut my items at a given interval and then loop it.

    Do you have any ideas?
    Thank you very much!

    Alexis Coco replied 6 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Walter Soyka

    April 27, 2020 at 10:53 pm

    Voila!

    I’m here to teach, so please ask questions for anything you don’t understand.

    // we might make a lot of comps, so let's make sure we can un-make them easily!
    app.beginUndoGroup("Make some comps!");

    // set originalSource to refer to the footage item you want to offset across your comps
    var originalSource = app.project.item(1);

    // how many seconds should each comp be?
    var compDuration = 30;

    // how much time should we offset in each new comp we create?
    var timeOffset = 10;

    // keep creating comps until we've offset the entire duration
    for (var i = 0; i < originalSource.duration / timeOffset; i++) {
    // make the new comp with the same properties as the originalSource, but at our custom duration
    var newComp = app.project.items.addComp("Comp " + (i+1), originalSource.width, originalSource.height, originalSource.pixelAspect, compDuration, originalSource.frameRate);

    // add the originalSource as a new layer in that new comp
    var newLayer = newComp.layers.add(originalSource);

    // pull the start time back according to the total offset for this specific comp, then trim the inPoint back to zero for cleanliness's sake
    newLayer.startTime = -timeOffset* i;
    newLayer.inPoint = 0;

    // delete the comp if the duration of the trimmed footage is less than the duration -- no blank spaces!
    if (newLayer.outPoint < newComp.duration) newComp.remove();
    }

    app.endUndoGroup();

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • Alexis Coco

    April 28, 2020 at 8:33 am

    Hi Walter,

    Thanks a lot for your amazingly fast answer ????

    That’s exactly what i was looking for.
    I was stuck with this:

    newLayer.startTime = -timeOffset* i;
    newLayer.inPoint = 0;

    And that one is the cherry on the cake:
    if (newLayer.outPoint < newComp.duration) newComp.remove();

    Thanks a lot for the help, your code is very clear ????
    So helpful!

    Alexis

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