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

Remove silence Script for Premiere Pro

Community Beginner ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Hello! 🙂 I'm new to Premiere Pro Scripting but not new to coding. 

I've got PP2023 and I'm using JSX Launcher to run my jsx code as ExtendScript won't work on my Mac

I'm trying to create a script which will delete any silences from my project to make my editing faser.

I've made some very simple scripts for JSX (counting the clips etc) which work find. But the script I'm using to cut the silences is doing nothing. Can anyone tell me where I'm going wrong please? 

 

// Define the noise level, minimum time, and offset time
var noiseLevel = 0.1; // 10%
var minTime = 1; // 1 second
var offsetTime = 0.5; // 0.5 seconds

// Get the active sequence
var activeSequence = app.project.activeSequence;

// Get the audio tracks in the active sequence
var audioTracks = activeSequence.audioTracks;

// Loop through each audio track
for (var i = 0; i < audioTracks.numTracks; i++) {

// Get the audio clips in the current audio track
var audioClips = audioTracks[i].clips;

// Loop through each audio clip in the current audio track
for (var j = 0; j < audioClips.numItems; j++) {

// Get the current audio clip
var audioClip = audioClips[j];

// Get the audio components in the current audio clip
var audioComponents = audioClip.components;

// Get the corresponding video clip for the current audio clip
var videoClip = activeSequence.videoTracks[i].clips[j];

// Create an array to store the cut points for the current clip
var cutPoints = [];

// Loop through each audio component in the current audio clip
for (var k = 0; k < audioComponents.numItems; k++) {

// Get the current audio component
var component = audioComponents[k];

// Check if the current audio component is silent
if (component.audioLevel <= noiseLevel && component.end-component.start >= minTime) {

// Add the start and end points of the silent component to the cut points array
cutPoints.push(component.start-offsetTime);
cutPoints.push(component.end+offsetTime);
}
}

// Sort the cut points array in ascending order
cutPoints.sort(function(a, b) {
return a - b;
});

// If there are any cut points, cut the video and audio clips between them
if (cutPoints.length > 0) {

// Cut the first clip from the start of the original clip to the first cut point
var firstClip = audioClip.clone();
firstClip.end = cutPoints[0];
videoClip.end = cutPoints[0];
audioClip.start = cutPoints[0];

// Cut the rest of the clips between the cut points
for (var l = 0; l < cutPoints.length; l += 2) {
var newClip = audioClip.clone();
newClip.start = cutPoints[l];
newClip.end = cutPoints[l+1];
videoClip.start = cutPoints[l];
videoClip.end = cutPoints[l+1];
}

// Cut the last clip from the last cut point to the end of the original clip
var lastClip = audioClip.clone();
lastClip.start = cutPoints[cutPoints.length-1];
videoClip.start = cutPoints[cutPoints.length-1];
audioClip.end = cutPoints[cutPoints.length-1];
}
}
}

TOPICS
Error or problem , SDK

Views

2.2K

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

Adobe Employee , Feb 14, 2023 Feb 14, 2023

I don't think that the value of the volume parameter, will have anything to do with the actual audio amplitude coming from that trackItem, at a given time. 

There is no access to audio data, from within the ExtendScript API. 

Votes

Translate

Translate
Adobe Employee ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Thanks for the question, Simon. Welcome to Adobe Premiere Pro forums. That is a very cool idea you have there, as this is a feature request I was recently upvoting. I know "delete silence" is possible via ffmpeg, so that may hold some clues if you look at that code. 

 

Make sure you click the "SDK" label when creating posts along these lines. It alerts our engineering manager who fosters such projects. I edited your post and did that for you. I hope you get a response soon. I wish you luck!

 

Thanks,

Kevin

Kevin Monahan - Sr. Community & Engagement Strategist – Pro Video and Audio

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
Community Beginner ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Thank you so much for the warm welcome Kevin! Really appreciate it. 🙂 

 

How do i change the label on this post please? I'll happily amend so it gets to the right people. 

 

And thank you so much. Has someone else managed to do this then? (I did have a search but might have missed their post). Thank you so much! Si

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 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

It seems like you're getting the value of an audio volume setting, but I'm not certain you're getting anything like actual audio data. [If the volume setting is <= 0, the distinction matters less...]


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
Community Beginner ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Good point Bruce. Thank you. I've amended it here to set a DB threshold (and to put markers for now, just to see if it's the cut feature that wasn't working!). But this still isn't doing anything. Is there any additional set-up I need to do (other than installing the JSX launcher) to run scripts please? I'm on a Mac if that makes any difference. 

 

// Set the threshold for silence (in decibels)
var silenceThreshold = -48;

// Get the active sequence
var activeSequence = app.project.activeSequence;

// Get the first audio track in the active sequence
var audioTrack = activeSequence.audioTracks[0];

// Get the audio clips in the first audio track
var audioClips = audioTrack.clips;

// Loop through each audio clip in the first audio track
for (var i = 0; i < audioClips.numItems; i++) {

// Get the current audio clip
var audioClip = audioClips[i];

// Get the audio components in the current audio clip
var audioComponents = audioClip.components;

// Loop through each audio component in the current audio clip
for (var j = 0; j < audioComponents.numItems; j++) {

// Get the current audio component
var component = audioComponents[j];

// Check if the current audio component is silent
if (component.audioLevels[0].level <= silenceThreshold) {

// Get the start and end time of the current audio component
var start = component.start;
var end = component.end;

// Add a marker at the start of the silent section
var marker = activeSequence.createMarker(start);
marker.name = "Silence start";

// Add a marker at the end of the silent section
var marker = activeSequence.createMarker(end);
marker.name = "Silence end";
}
}
}

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 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

I don't think that the value of the volume parameter, will have anything to do with the actual audio amplitude coming from that trackItem, at a given time. 

There is no access to audio data, from within the ExtendScript 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
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

¿Any updates on this? i been doing basic scripts but i cant find a way to do this, theres an extension that do it so i know is posible.

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 ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

There have been no changes to PPro's ExtendScript API. 

I'm not sure 'Level' is getting you useful data; you're checking a Level setting associated with a trackItem; you're not checking the value of a VU meter, or actual audio data.


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
Engaged ,
Dec 12, 2023 Dec 12, 2023

Copy link to clipboard

Copied

Any news since?

I will check this ffmeg to see if it work out in the meantime.

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
New Here ,
May 27, 2024 May 27, 2024

Copy link to clipboard

Copied

LATEST

Hey
Do you have an update on the subject?

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