• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Extendscript .setOutPoint() Bugs?

Explorer ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Hello!  I am happy to provide further details or steps to reproduce, but since you may already be aware I'll try to be brief(-ish).

 

I am trying to insert a clip at the front of an otherwise complete sequence with many edits.  Since .insertClip() does not work like inserting a clip with say, cmd+drop where all tracks are pushed forward in the timeline, I need to use an audio "spacer" to move the audio tracks the exact duration of the png (logo) I am attempting to start the clip with.  We do this thousands of times a year at our company.

 

Trying to set an audio outpoint to match a video outpoint so that their final durations are the same is very difficult because of the following (which I see as bugs).

 

1)To keep my code more concise, I was using media type 4 for "all" media types on both the video and the audio.  This leads, in most cases, to the audio outpoint doing the craziest thing.  Instead of being set as instructed, it rounds down to what I call a "detent", based on a mechanical catch, that can be calculated with ((254016000000 * x) * 1.001)/30.  Then, when inserted, the end.seconds time rounds down again to the next closest (254016000000 *y)/sequenceFramerate.  This means that the duration of an audio file set with the same outpoint as a png will often be 1 or 2 frames shorter than the png on the timeline, moving my audio out of sync.  Another side effect is that, since there are only 30 "detents" in a second, you cannot target all frames in framerates above 30, such as 2 seconds and 2 frames at 50fps.  Much of that gets solved by simply changing the media type to 2, so there is a viable workaround but it was very time consuming to get to there.  That being said, I started messing with additional functions like .clearInPoint(), and I now purposefully use media type 4 at 29.97 and 59.94 on audio files which now gives the desried result.  In those framerates, clearing the inpoint first, media type 2 does not work as expected. So I thought I had it figured out for a second, but now I'm a little confused again.

 

2)The frequencey of the audio files also affects the outpoint and duration of a clip inserted to a timeline, specifically noticed at 23.976fps.  If I .insertClip() with a 41.4khz audio file in a 48kz 23.976 sequence, the file will be 1 frame short on the timeline (for testing purposes, you can always assume I am targeting 2 seconds and 2 frames, though I tested up to 4 seconds and 2 frames).  This stacks with the media type issue.

 

Here is the working function below.  It works in 23.976, 24, 29.97, 30, 50, 59.94, and 60fps with pngs and movs (that is to say, every combniation of files and framerates I have tested).  So it works for me and I'm moving forward, but I wanted to report the behavior.  Let me know if you'd like a follow-up!  

 

 

    foo: function () {
        var activeSeq = app.project.activeSequence;
        var exactSeqFPS = 1 / activeSeq.getSettings().videoFrameRate.seconds;
        aPng.setOverrideFrameRate(exactSeqFPS);
        var frameNumber = (exactSeqFPS * 2) + 2; //targeting required 2 seconds, plus 2 frames for safety
        frameNumber = parseInt(frameNumber.toFixed());
        var someTicks = (((frameNumber * ticksPerSecond) / exactSeqFPS)).toString();
        aPng.clearInPoint();
        aPng.setOutPoint(someTicks, 1);
        $.RunScript.pushClipToFrontofSeq(aPng);
    },
    
pushClipToFrontofSeq: function (aProjectItem) { // pushes a clip or still to the front of a sequence and adjusts all existing media
        if (aProjectItem.getOutPoint(2).seconds == 0) {
            clipHasAudio = false;
        } else {
            clipHasAudio = true;
        }
        var activeSeq = app.project.activeSequence;
        var exactSeqFPS = 1 / activeSeq.getSettings().videoFrameRate.seconds;
        var videoTracks = activeSeq.videoTracks;
        var audioTracks = activeSeq.audioTracks;
        var audioSpacer = $.RunScript.findOrImportClip("/AUTOMATION_SPACER.aac", "2.AUDIO");
        var itemDuration = parseInt(aProjectItem.getOutPoint(1).ticks) - parseInt(aProjectItem.getInPoint(1).ticks);
        var someTicks = itemDuration.toString();
        audioSpacer.clearInPoint();
        var roundedFPS = exactSeqFPS.toFixed(2);
        if (roundedFPS == "29.97" || roundedFPS == "59.94") {
            mediaType = 4;
        } else {
            mediaType = 2;
        }
        audioSpacer.setOutPoint(someTicks, mediaType); //cannot use 4 for audio only, would force "detents"
        for (var i = 0; i < audioTracks.numTracks; i++) { // push the spacer to all audio tracks
            if (i == 0) {
                if (!clipHasAudio) {
                    audioTracks[i].insertClip(audioSpacer, 0); //push spacer to 0 seconds on track A1
                } else {
                    videoTracks[i].insertClip(aProjectItem, 0); //push the actual file to to 0 seconds on track A1 and V1
                }
            } else {
                if (audioTracks[i].clips[0]) { //push spacer to the first clip of all other audio tracks
                    audioTracks[i].insertClip(audioSpacer, audioTracks[i].clips[0].start.seconds);
                }
            }
        }
        var audioEndPoint = audioTracks[0].clips[0].end.ticks; // could use someTicks again, but this compensates for bugs like "detents"
        var videoSpacer = $.RunScript.findOrImportClip("/AUTOMATION_SPACER.png", "STILL");
        videoSpacer.clearInPoint();
        videoSpacer.setOverrideFrameRate(exactSeqFPS);
        videoSpacer.setOutPoint(audioEndPoint, 1);
        for (var i = 0; i < videoTracks.numTracks; i++) { //push video the to all video tracks
            if (i == 0) {
                if (!clipHasAudio) { //if it has audio, we already pushed it
                    videoTracks[i].insertClip(aProjectItem, 0); //push the actual file to to 0 seconds on track A1 and V1
                }
            } else {
                if (videoTracks[i].clips[0]) {
                    videoTracks[i].insertClip(videoSpacer, videoTracks[i].clips[0].start.seconds);
                }
            }
        }
        for (var i = 1; i < activeSeq.videoTracks.numTracks; i++) { //remove the spacer from all tracks 
            if (videoTracks[i].clips[0]) {
                videoTracks[i].clips[0].remove(false, true); //first is the ripple delete, second is "align to nearest frame"
            }
        }
        if (clipHasAudio) {
            var startTrack = 1; //remove the spacer from all tracks except 0
        } else {
            var startTrack = 0; //remove the spacer from all tracks
        }
        for (var i = startTrack; i < activeSeq.audioTracks.numTracks; i++) {
            if (audioTracks[i].clips[0]) {
                audioTracks[i].clips[0].remove(false, true); //first is the ripple delete, second is "align to nearest frame"
            }
        }
    }

 

TOPICS
Error or problem , SDK

Views

859

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 , Feb 18, 2021 Feb 18, 2021

Thanks for the email @Bruce Bullis !  I am using Premiere 14.7.0.

 

Your results match my expectations, since the "bug" only presets itself with audio files (tested wav, mp3, aac), which I recognize in code with:

      if (aProjectItem.getOutPoint(2).seconds == 0) {
            clipHasAudio = false;
        } else {
            clipHasAudio = true;
        }

From my testing, I get the impression that when there is a video track, it overrides something that might have otherwise happened in the audio.

...

Votes

Translate

Translate
Adobe Employee ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

The audio is 'trimmed' to a frame boundary; this'll occur in the PPro UI as well, and isn't specific to the API. 

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Thanks @Bruce Bullis, but that's not really what I'm getting at.  The outpoint iteslf is not respected.  You can .setOutPoint on the audio clip with media type 4, then .getOutPoint(), and see that it has rounded down to a "detent" prior to insertion into a sequence.  Sorry, I was a little unclear in that point (since I am focused on the result). 

 

And why would a 41.4khz clip inserted with the same inpoint and outpoint as a 48khz clip insert with different durations?

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

You can .setOutPoint on the audio clip with media type 4, then .getOutPoint(), and see that it has rounded down to a "detent" prior to insertion into a sequence.

What tells you it was rounded, before insertion? 

Why would a 41.4khz clip inserted with the same inpoint and outpoint as a 48khz clip insert with different durations?

 

In that example, do you mean source in/out points, or sequence in/out points? 

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Thanks for the follow up @Bruce Bullis .  I have attached a screenshot of the following code executing:

    runTest: function () {
        var audioSpacer = $.RunScript.findOrImportClip("/AUTOMATION_SPACER.aac", "AUDIO");
        audioSpacer.setOutPoint("254016000000", 4);
        alert(audioSpacer.getOutPoint().ticks); //will not equal 254016000000, even if this is set to getOutPoint(2).ticks
    }

The project has no sequences, and the audio clip is never inserted.  The outpoint is set, then immediately read.  The outpoint is set to 1 second (in ticks) with mediaType 4, and is immediately rounded down to a number in the set ((254016000000 * x) * 1.001)/30, and in this case x is 29, so the ticks alerted are 245794348800.

 

If this audio clip were to be inserted at 0 seconds into an empty 30fps sequence, then audioTracks[0].clips[0].end.ticks would round down again to 245548800000, or (254016000000 * 29) / 30,  which is the frame boundary trimming you mentioned earlier.  I'm saying the real problem happens before that.   

 

If I had used .setOutPoint with mediaType 2, it would have returned 254016000000 as expected, and if inserted, end.ticks would also be 254016000000.

 

As for the audio insertion bug (which is different), those are also projectItem.clearInPoint() and projectItem.setOutPoint().

 

 

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Interesting! In what version of PPro are you testing? I think the time info from the source must have some impact; In my testing with a 'vanilla' MXF file (29.97fps), in the current PPro beta, I get the same value for all of these.

var first = app.project.rootItem.children[0];  // the 'vanilla' MXF file

if (first){
	first.setOutPoint("254016000000", 1);
	var outVideo = first.getOutPoint();
	alert ("Video = " + outVideo.ticks + " ticks.");
	first.setOutPoint("254016000000", 2);
	var outAudio = first.getOutPoint();
	alert ("Audio = " + outVideo.ticks + " ticks.");
	first.setOutPoint("254016000000", 3);
	var outData = first.getOutPoint();
	alert ("Data = " + outVideo.ticks + " ticks.");
	first.setOutPoint("254016000000", 4);
	var outANY = first.getOutPoint();
	alert ("Any = " + outVideo.ticks + " ticks.");
}

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Send me a representative .aac file?

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Thanks for the email @Bruce Bullis !  I am using Premiere 14.7.0.

 

Your results match my expectations, since the "bug" only presets itself with audio files (tested wav, mp3, aac), which I recognize in code with:

      if (aProjectItem.getOutPoint(2).seconds == 0) {
            clipHasAudio = false;
        } else {
            clipHasAudio = true;
        }

From my testing, I get the impression that when there is a video track, it overrides something that might have otherwise happened in the audio.  It's what gave me the idea to insert my audio spacer first, then read the end.ticks of the clip in the timeline, and set the png outpoint to the audio track's end.ticks.  That way, even if I were off by a frame, the durations would be the same.

 

However, in practice, I have found that by switching between mediaType 2 and 4, per my original code, I get the expected results.  But that feels like a bug.  Does this satisfy any requirements as a bug report?  Would you like any more info?

 

Let's ignore the second item (audio frequency issue) for now, I will make another post with some better examples.  But can we consider this also as a feature request for a sort of "push all" insert, like the cmd+drop behavior (on Mac)?

 

Many thanks!
   

Votes

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 ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

> But that feels like a bug.  Does this satisfy any requirements as a bug report?  Would you like any more info?


There aren't such formal requirements, and yes, we're already aware of the 'different in/out points for audio and video file insertion' behavior. 🙂

> But can we consider this also as a feature request for a sort of "push all" insert, like the cmd+drop behavior (on Mac)?

Sure; we're tracking that request as DVAPR-4229801.

 

Votes

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