Skip to main content
jkmgz
Inspiring
August 26, 2020
Answered

Perform a cut from script?

  • August 26, 2020
  • 3 replies
  • 5953 views

I'm currently working on a PPro Panel that will cut the last second off of a clip and extend that clipped second duration out the next clip. I'm currently stuck on how to perform a clip cut from the script. This will be used to supply extending the visual in case the above-placed title is longer than the below clip. It'll pause the video while the title continues to finish out it's duration. 

 

These are the notes I have so far: 

app.project.activeSequence.getSelection()
this will be used to get the end seconds of a clip

app.project.activeSequence.setPlayerPosition()
this will be used to set the player position -1 second from end of selection.

 

I have PropertyExplorer installed and have exploring properties for a bit and haven't found the appropriate method/property to perform a cut. Help, please? 

This topic has been closed for replies.
Correct answer Bruce Bullis

What is the code snippet to adjust the end point?
There have been multiple responses from employees saying 'adjust the end point' without saying how to adjust the end point via script.

Wouldn't have commented about it but Google has led me back here like a dozen times.


var myClip = app.project.sequences[0].videoTracks[0].clips[0];  // grabs first trackItem in first track in first sequence

if (myClip){
	var oldEnd = myClip.end;
	if (oldEnd){
		oldEnd.seconds = oldEnd.seconds + 3; // arbitrary new value
		myClip.end = oldEnd;
	}
}

3 replies

krisc56526666
Participating Frequently
May 1, 2024

Here you go...

 

// Enable Quality Engineering library
app.enableQE();

// Function to find markers in the active sequence
function getMarkers() {
var activeSequence = app.project.activeSequence;
if (!activeSequence) {
throw new Error("No active sequence found.");
}

var markers = activeSequence.markers;
var markerList = [];
var currentMarker = markers.getFirstMarker();

while (currentMarker) {
markerList.push(currentMarker);
currentMarker = markers.getNextMarker(currentMarker);
}

return markerList;
}

// Function to pad a number with zeros
function padNumber(number, digits) {
var numberString = number.toString();
while (numberString.length < digits) {
numberString = "0" + numberString;
}
return numberString;
}

// Function to add a cut at a marker
function addCutAtMarker(marker) {
var sqe = qe.project.getActiveSequence(); // Get the active QE sequence
var timecode = marker.start.seconds; // Get the marker start time in seconds

// Convert the timecode to the format "HH:MM:SS:FF"
var hours = Math.floor(timecode / 3600);
var minutes = Math.floor((timecode - (hours * 3600)) / 60);
var seconds = Math.floor(timecode - (hours * 3600) - (minutes * 60));
var frames = Math.floor((timecode - Math.floor(timecode)) * 24); // Assuming 24 fps
var timecodeString = padNumber(hours, 2) + ":" + padNumber(minutes, 2) + ":" + padNumber(seconds, 2) + ":" + padNumber(frames, 2);

// Apply the cut to all video tracks
for (var i = 0; i < sqe.numVideoTracks; i++) {
var videoTrack = sqe.getVideoTrackAt(i);
videoTrack.razor(timecodeString, true);
}

// Apply the cut to all audio tracks
for (var i = 0; i < sqe.numAudioTracks; i++) {
var audioTrack = sqe.getAudioTrackAt(i);
audioTrack.razor(timecodeString, true);
}
}

// Example Usage:
var markers = getMarkers();

for (var i = 0; i < markers.length; i++) {
addCutAtMarker(markers[i]);
}

 

New Participant
November 30, 2021

There's no cut function in extendscript API. QE DOM has razor(string, bool, bool) method on sequence and track objects but I failed to get it to work.
As a workaround you can use overwriteClip() with one-frame media and then delete that new media immediately, so you will have two desired cutted clips BBBBUT with one frame gap.
Another workaround is adjusting inPoint, outPoint, start and end, but it is a bit tricky: clip's inPoint and outPoint work in a strange nonobvious way, so make tests first.

Bruce Bullis
Community Manager
Community Manager
August 26, 2020

There's no cut function; you'd need to change the end point of the trackItem (clip).

jkmgz
jkmgzAuthor
Inspiring
August 26, 2020

Can this be done through a different method? I'm currently working on this as a panel using HTML and ExtendScript/Javascript. Can another develop method provide this kind of automation? i.e. via the SDK

Participating Frequently
July 22, 2023

The proper way remains adjusting the end point.


What is the code snippet to adjust the end point?
There have been multiple responses from employees saying 'adjust the end point' without saying how to adjust the end point via script.

Wouldn't have commented about it but Google has led me back here like a dozen times.