Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Identifying a Video or image ExtendScript

  • Identifying a Video or image ExtendScript

  • Avinash Ramanath

    September 21, 2018 at 1:11 pm

    Hello,
    Am trying to import a video file or image and move it to a folder called “Videos”. But am unable to do so. Could you please have a look.

    var myPath = "/Users/avinashramanath/Desktop/Video/1.mp4";

    newFootageItem = app.project.importFile(new ImportOptions(new File(myPath)));

    var compFolder = app.project.items.addFolder("Videos");
    for(var i = 1; i <= app.project.numItems; i++) {
    if(app.project.item(i).hasVideo == true && item.hasAudio == true && item.duration != 0)

    app.project.item(i).parentFolder = compFolder ;
    }

  • James Ronan

    September 21, 2018 at 2:19 pm

    If that’s all you want to do, you don’t need to loop through all the items in the project:


    var myPath = "/Users/avinashramanath/Desktop/Video/1.mp4";

    newFootageItem = app.project.importFile(new ImportOptions(new File(myPath)));

    var compFolder = app.project.items.addFolder("Videos");
    newFootageItem.parentFolder = compFolder ;

  • Avinash Ramanath

    September 21, 2018 at 2:43 pm

    Yes thanks James. That worked. But I’m still wondering how to identify a video file or an image file via scripting.
    For example a comp can be identified by instanceof CompItem.

  • Avinash Ramanath

    September 21, 2018 at 3:55 pm

    Could you please tell me why the below code is omitting files with odd number names. Am very new to scripting and figuring out a lot of things

    {
    var targetFolder = File("/Users/avinashramanath/Desktop/Video");

    if (targetFolder) {

    var files = targetFolder.getFiles();

    for (var i = 0; i < files.length; i++)

    {

    try {

    var importOptions = new ImportOptions (files[i]);

    app.project.importFile (importOptions);

    } catch (error) { /*alert(error.toString());*/}

    }

    }
    }

    {
    var compFolder = app.project.items.addFolder("Assets");

    for(var i = 1; i <= app.project.numItems; i++)
    {

    if(app.project.item(i) instanceof FootageItem)

    app.project.item(i).parentFolder = compFolder;

    }
    }

  • James Ronan

    September 22, 2018 at 8:18 am

    Here is a basic example of determining whether it’s an image or video:
    It didn’t omit odd file names for me.

    var targetFolder = File("/Users/avinashramanath/Desktop/Video");
    var compFolder = app.project.items.addFolder("Assets");

    if (targetFolder) {

    var files = targetFolder.getFiles();

    for (var i = 0; i <= files.length; i++) {

    try {

    var importOptions = new ImportOptions(files[i]);
    var newItem = app.project.importFile(importOptions);

    if (newItem instanceof FootageItem && !newItem.mainSource.isStill) { // Check if Video or image

    newItem.parentFolder = compFolder;

    }

    } catch (error) { /*alert(error.toString());*/ }

    }
    }

  • Avinash Ramanath

    September 22, 2018 at 4:38 pm

    I don’t know what am doing wrong here, must be in the for loop. The script seems to be selecting files with odd number names and only placing those inside the Assets folder. Please check the image to understand my problem,

    // Select folder to import
    var targetFolder = Folder.selectDialog("Import Files From Folder");
    if (targetFolder)
    {
    var files = targetFolder.getFiles();
    for (var i = 0; i &lt; files.length; i++)
    {
    try
    {
    var importOptions = new ImportOptions(files[i]);
    app.project.importFile(importOptions);
    }
    catch (error)
    { /*alert(error.toString());*/ }
    }
    }
    //create Assets folder
    var compFolder = app.project.items.addFolder("Assets");
    //collect items and move to Assets folder
    var files = app.project.items.length;
    for (var i = 1; i &lt;= files; i++)
    {
    if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == false && app.project.item(i).duration == 0)
    { // Check if Video or image
    app.project.item(i).parentFolder = compFolder;
    }
    else
    if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == true && app.project.item(i).duration !== 0)
    { // Check if Video or image
    app.project.item(i).parentFolder = compFolder;
    }
    }

  • Avinash Ramanath

    September 22, 2018 at 4:39 pm

    The wrong image uploaded in the previous post. Please see this one.

  • Dan Ebberts

    September 22, 2018 at 5:18 pm

    You’re changing the order of the items while you’re looping through them. I would loop through all the items and store the ones that need to be moved into an array. Then loop through the array and move them into the compFolder.

    Dan

  • Avinash Ramanath

    September 22, 2018 at 6:01 pm

    Dan, could you please modify the script for me.

  • Dan Ebberts

    September 22, 2018 at 6:09 pm

    I haven’t tested it, but here you go:


    // Select folder to import
    var targetFolder = Folder.selectDialog("Import Files From Folder");
    if (targetFolder)
    {
    var files = targetFolder.getFiles();
    for (var i = 0; i < files.length; i++)
    {
    try
    {
    var importOptions = new ImportOptions(files[i]);
    app.project.importFile(importOptions);
    }
    catch (error)
    { /*alert(error.toString());*/ }
    }
    }
    //create Assets folder
    var compFolder = app.project.items.addFolder("Assets");
    //collect items and move to Assets folder
    var files = app.project.items.length;
    var myItems = [];
    for (var i = 1; i <= files; i++)
    {
    if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == false && app.project.item(i).duration == 0)
    { // Check if Video or image
    myItems.push(app.project.item(i));
    }
    else
    if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == true && app.project.item(i).duration !== 0)
    { // Check if Video or image
    myItems.push(app.project.item(i));
    }
    }
    for (var i = 0; i < myItems.length; i++){
    myItems[i].parentFolder = compFolder;
    }

    Dan

Viewing 1 - 10 of 11 posts

Log in to reply.

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