Skip to main content
Hey Evgenii
Inspiring
May 16, 2023
Answered

Premiere pro extend script set audio level of clip

  • May 16, 2023
  • 1 reply
  • 1155 views

Hi guys I am trying to descrease/increase level of clip's audio using extendScript, what can be the problem here?

 

function setAudioLevel(volume){
  var activeSequence = app.project.activeSequence;
  var track = activeSequence.audioTracks[0]
  for (var i = 0; i < track.clips.length; i++) {
    var prop = track.clips[i].components[0].properties[1]
        prop.setTimeVarying(false)
    var value = prop.getValue() // returns 0.17782793939114 while interface shows 0.0 
    track.clips[i].components[0].properties[1].setValue(volume)// if volume is -3 it will set to infinity 
    
  }

}

 

Correct answer Justin Taylor-Hyper Brew

Found it, there's just an offset of 15 so these formulas after the log10 * 20 for db Conversion, these seem to work well:


function dbToDec(x) {
  return Math.pow(10, (x - 15) / 20);
}

function decToDb(x) {
  return 20 * Math.log(x) * Math.LOG10E + 15;
}

1 reply

Justin Taylor-Hyper Brew
Community Expert
Community Expert
May 22, 2023

So the values are displayed in dB, but they are stored in float 0.0-1.0 scale. That's why:

 

negative infinity : 0

-2 : 0.14125375449657

-1 : 0.15848931670189

0 : 0.17782793939114

1 : 0.19952623546124

2 : 0.22387212514877

15 : 1

 

I'm unsure of the exact conversion, supposed to be Log10 for dB, but looks little different, maybe @Bruce Bullis could chime in.

Justin Taylor-Hyper Brew
Community Expert
Community Expert
May 23, 2023

Found it, there's just an offset of 15 so these formulas after the log10 * 20 for db Conversion, these seem to work well:


function dbToDec(x) {
  return Math.pow(10, (x - 15) / 20);
}

function decToDb(x) {
  return 20 * Math.log(x) * Math.LOG10E + 15;
}
Hey Evgenii
Inspiring
May 22, 2025
had an issues  0.17782793939114  showing -7.87740184193808e-8

this is a little fix
function decToDb(x) {
var result = 20 * Math.log(x) * Math.LOG10E + 15;

// Round very small values to 0 (handles floating-point precision)
if (Math.abs(result) < 1e-6) {
return 0;
}

// Round to reasonable precision (2 decimal places for dB)
return Math.round(result * 100) / 100;
}