Extendscript. How to get last inserted clip. inPoint bug?

Explorer ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

I need to trim clip from start and end for 1 second:

var files = ["21.mp4","22.mp4","23.mp4"];

var media = app.project.rootItem.createBin("Media");
app.project.importFiles(files,true,media);

function getMediaByName(name,folder) {
    for(var i=0; i<folder.children.numItems; i++)
        if(folder.children[i].name==name)
            return folder.children[i];
}

start = 0;
seq = app.project.createNewSequence('test','/Temp/test');
for(var i=0;i<files.length;i++) { // I need to insert videos in same sequence as in array
    cMedia  = getMediaByName(files[i].split("/").pop(),media);
    seq.videoTracks[0].insertClip(cMedia,start);
    clip = seq.videoTracks[0].clips[(seq.videoTracks[0].clips.numItems - 1)]; //last inserted clip
    
     // trimming 1 secod from start and end
     inPoint = new Time();
     inPoint.seconds = start + 1;
     clip.inPoint = inPoint;
     end = new Time();
     end.seconds = start + clip.duration.seconds - 1;
     clip.end = end;
     //
    
    start = clip.end.seconds;
    $.writeln(clip.name);
}

After setting inPoint i have this bug in timeline:

Dmitriy5FD0_0-1648745611842.png

so when i try to get last inserted clip:

clip = seq.videoTracks[0].clips[(seq.videoTracks[0].clips.numItems - 1)];

i get first one due to this phantom clip in audiotrack o_O

is there any way to get inserted clip another way or how can i avoid that phantom added clip?

 

TOPICS
How to , SDK

Views

159

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

Explorer , Apr 01, 2022 Apr 01, 2022
I've applied same trim to audio track also and it fixed issue:clipAudio = seq.audioTracks[0].clips[(seq.audioTracks[0].clips.numItems - 1)];

Likes

Translate

Translate
Explorer ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

UPD, after setting inPoint and end i have this:

Dmitriy5FD0_0-1648746024944.png

video track trimmed as expected, audio not. outPoint doesn't work at all...

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
Adobe Employee ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

Which one is the phantom; the audio clip?

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 ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

check red circle on screenshot in 1st post

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
Adobe Employee ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

Yes, you'd circled the audio clip; none of your code references audio tracks, which is what I found confusing.

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 ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

you can try to run code, just replace file paths to real files.

 

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 ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

this only happens when I use inPoint adjustment...

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 ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

Dmitriy5FD0_2-1648798733652.png

That's what happening, is there any way to avoid that bug?

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 ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

I've applied same trim to audio track also and it fixed issue:

clipAudio = seq.audioTracks[0].clips[(seq.audioTracks[0].clips.numItems - 1)];

 

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 ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

That fixed phantom audio track, but i'm still unable to get last inserted video... Looks like i have to search it by name rather than getting last inserted clip...

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
Adobe Employee ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

Send me your 'attempting to get last inserted video' code, along with a .prproj containing a representative sequence?

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 ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

clip = seq.videoTracks[0].clips[(seq.videoTracks[0].clips.numItems - 1)];

this one doesn't work correctly after setting inPoints... Now as a solution I'm getting inserted clip by it's name...

 

 

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
Adobe Employee ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

LATEST

[I'd need the .prproj, and further code context, to provide meaningful guidance...]

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