Skip to main content
jamesc12645275
Participant
November 4, 2017
Answered

Add video (via path) into After Effects - ExtendScript

  • November 4, 2017
  • 2 replies
  • 2001 views

What command to add video to After Effects?

For example, the file "C:/Users/jamesc/video.mp4" needs to be added into my AE.

How do I add it in as a resource and then put it into the composition?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Alex White

Here you go.

The following function will import your footage and add it to an opened composition.

var file = "C:/Users/jamesc/video.mp4";

function importFootage(file) {

    var myComp = app.project.activeItem; // your opened composition

    if (!myComp || !(myComp instanceof CompItem)) {

        alert("Please, open composition");

        return false;

    }

    app.beginUndoGroup("Import file");

    var importOpts = new ImportOptions(File(file));

    var importFootage = app.project.importFile(importOpts);

   

    var myFootage = myComp.layers.add(importFootage); // add footage to your composition

    app.endUndoGroup();

};

2 replies

Alex White
Alex WhiteCorrect answer
Legend
November 10, 2017

Here you go.

The following function will import your footage and add it to an opened composition.

var file = "C:/Users/jamesc/video.mp4";

function importFootage(file) {

    var myComp = app.project.activeItem; // your opened composition

    if (!myComp || !(myComp instanceof CompItem)) {

        alert("Please, open composition");

        return false;

    }

    app.beginUndoGroup("Import file");

    var importOpts = new ImportOptions(File(file));

    var importFootage = app.project.importFile(importOpts);

   

    var myFootage = myComp.layers.add(importFootage); // add footage to your composition

    app.endUndoGroup();

};

guntramp26642460
Inspiring
January 13, 2022

I think you can fetch the composition like this if you do not want to work with the currently active one:

/**
* Returns e.g. a composition from the bins.
* If there are more files with the same name,
* the first one will be returned and others will be ignored.
* @param string name The name of the item to retrieve
*/
getFolderItemByName: function getFolderItemByName(name) {
var project = app.project;
for (var index = 1; index <= project.numItems; index++) {
var folderItem = project.item(index);
if (folderItem && folderItem.name === name) {
return folderItem;
}
}
return null;
},


Or if you want to bring a composition to the active state, you can set it:

composition.selected = true;