Participating Frequently
March 11, 2024
Question
InsertClip adding strange offset in audio-only track-item for a particular audio file.
- March 11, 2024
- 1 reply
- 1728 views
Goal:
- Using PP-Scripting Clone a subsequence (created using Sequence.createSubsequence()) in its raw clips form to create a target sequence. Multiple subsequences will be used to create the complete target sequence without using subsequences to avoid nested sequences.
Scenario:
- Multiple cameras are used for footage, while their audios are not used. Audios are sourced from separate audio recording devices.
- Adobe Premiere Pro 2024 (Version 24.2.1) Build 2
- Windows 10
Method Adopted:
- Looped over each video track in the source. Copied each clip and inserted it into the target, similar to the source, using insertClip(). Removed its audio part. Then, looped over each audio track in the source. Inserted each audio clip into the target, similar to the source.
Problem:
- This worked fine for video tracks. However, for audio tracks, the first track clip (Track 2) with the Audio Item (Tr2.wav) seems to get inserted with an offset. The original subsequence had Track 2 at 0 ticks. Inserting it in the Target Sequence at 0 ticks yields a clip with a few seconds offset.
Important Note:
- The problem does not occur when a .prproj file is downgraded for opening in Premiere Pro 2023 and saved. Processing this saved .prproj file, even with Premiere Pro 2024, yields the expected result (clip insertion at specified start time-ticks).
Comments:
- I am not sure if this is a bug in Premiere Pro 2024, a problem in the approach used, or some error in the code. Maybe I forgot a terminator 😄
Code: (For audio-tracks cloning portion)
// Loop through each audio track in the source sequence
for (var i = 0; i < src_seq.audioTracks.numTracks; i++) {
var audioTrack = src_seq.audioTracks[i];
var targetAudioTrack = target_seq.audioTracks[i];
var clipOffset = 0; // Initialize clip offset
// Process each clip in the current audio track
for (var j = 0; j < audioTrack.clips.numItems; j++) {
var clip = audioTrack.clips[j];
var clip_projectItem = clip.projectItem;
var inPoint = clip.inPoint;
var outPoint = clip.outPoint;
var clipDuration = clip.end.ticks - clip.start.ticks; // Duration in ticks
var newClipStartTime = lastEndTime + clipOffset; // Calculate new start time
targetAudioTrack.insertClip(clip_projectItem, String(newClipStartTime));
var targetClipIndex = targetAudioTrack.clips.numItems - 1;
var targetClip = targetAudioTrack.clips[targetClipIndex];
var curr_end_sec = tick_to_sec(newClipStartTime + clipDuration);
// Set the in and out points for the target clip
targetClip.inPoint = inPoint;
targetClip.outPoint = outPoint;
targetClip.end = curr_end_sec; // Adjust the end time
targetClip.disabled = clip.disabled; // Copy the disabled state
clipOffset = clipDuration; // Update clip offset for the next iteration
}
}