Add video (via path) into After Effects - ExtendScript

New Here ,
Nov 04, 2017 Nov 04, 2017

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

1.3K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Nov 10, 2017 Nov 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);

 

...

Likes

Translate

Translate
Enthusiast ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

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();

};

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

LATEST

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;

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines