Skip to main content
SimonBjörk
Known Participant
October 28, 2021
Question

Image sequence - access first and last frame?

  • October 28, 2021
  • 2 replies
  • 233 views

I'm trying to access the first and last frame of an image sequence but I haven't found a way. For example, say I have an image sequene that is named sequentially on disk, something like shot.0100.jpg all the way to shot.0200.jpg. I would like to access the first frame (100) and last frame (200) or at least the filepath to the first and last frame.

 

If I call the file attribute on the file object I only get the path to the first frame:

var item = app.project.item(1);
alert(item.file)
>> /path/to/shot.0100.jpg

 

If the imported image sequence is not renamed, I can access the frame range via the file attribute (after parsing the result).

var item = app.project.item(1);
alert(item.name)
>> frame_number_v001.[0046-0200].jpg

But this only works if the footage hasn't been renamed after import.

 

I've looked through the attributes/methods of FileSource/FootageSource/FootageItem without luck. It seems to me I need to call getFiles and parse each file in a file directory and check the names. For long sequences/network drives this is going to be very slow.

 

Anyone have a better solution?

This topic has been closed for replies.

2 replies

Meng Zhiqun
Inspiring
October 29, 2021

You can try this. Hope this helps!

var proj = app.project;
var itemTotal = proj.numItems;
var selection = proj.selection;

for (var i=0;i<selection.length;i++){
    var curItem = selection[i];
    var iFsName = curItem.mainSource.file;
    iFsName = iFsName.toString().replace(/%20/g, " ");
    var curFolderPath = iFsName.substr(0, iFsName.lastIndexOf("/")+1);

    var allFFiles = Folder(curFolderPath).getFiles();
    var firstItem = allFFiles[0];
    var lastItem = allFFiles[allFFiles.length-1];
    alert("first item = " + firstItem.name + "//" +"last item = " +  lastItem.name);
}
Mathias Moehl
Community Expert
Community Expert
October 29, 2021

Thanks for sharing! Note that this seems to rely on a lot of assumptions. In particular it assumes that only the image sequence and no other files are in the folder. And that getFiles() returns the files sorted from first sequence item to last sequence item. Not sure if the latter is the case for all Ae and Os versions (not sure, but it may be the case).

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Meng Zhiqun
Inspiring
October 29, 2021

Thanks for point this out Mathias! Yup it definitely does. I'm sure if we have more details, we can add more variables to better location the item we want with the getFiles() method.

Mathias Moehl
Community Expert
Community Expert
October 29, 2021

Unfortunately, I also think that looking at the names of all files in the folder is the only robust solution, unfortunately.

Maybe, from the duration and frame rate of the item you can guess the number of files, but not sure how reliable that is.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects