Skip to content

Instantly share code, notes, and snippets.

@zenofile
Created September 30, 2020 00:53
Show Gist options
  • Save zenofile/c2974c1d2571ae3d07edf611cd3b6bcb to your computer and use it in GitHub Desktop.
Save zenofile/c2974c1d2571ae3d07edf611cd3b6bcb to your computer and use it in GitHub Desktop.
Improve videos with bad audio (too quiet or loud, one channel stereo, ..)
(function() {
let ctx = new AudioContext();
let gain = ctx.createGain();
let cmpr = ctx.createDynamicsCompressor();
let src = ctx.createMediaElementSource(document.getElementsByTagName("video")[0]);
ctx.destination.channelCount = 1;
let ts = ctx.currentTime;
gain.gain.setValueAtTime(6, ts);
cmpr.threshold.setValueAtTime(-50, ts);
cmpr.knee.setValueAtTime(40, ts);
cmpr.ratio.setValueAtTime(12, ts);
cmpr.attack.setValueAtTime(0, ts);
cmpr.release.setValueAtTime(0.25, ts);
src.connect(gain);
gain.connect(cmpr);
cmpr.connect(ctx.destination);
})();
`javascript:(function()%7Blet%20a%3Dnew%20AudioContext()%3Blet%20p%3Da%5B'createGain'%5D()%3Blet%20i%3Da%5B'createDynamicsCompressor'%5D()%3Blet%20o%3Da%5B'createMediaElementSource'%5D(document%5B'getElementsByTagName'%5D('video')%5B0x0%5D)%3Blet%20h%3Da%5B'currentTime'%5D%3Bp%5B'gain'%5D%5B'setValueAtTime'%5D(0x6%2Ch)%3Bi%5B'threshold'%5D%5B'setValueAtTime'%5D(-0x32%2Ch)%3Bi%5B'knee'%5D%5B'setValueAtTime'%5D(0x28%2Ch)%3Bi%5B'ratio'%5D%5B'setValueAtTime'%5D(0xc%2Ch)%3Bi%5B'attack'%5D%5B'setValueAtTime'%5D(0x0%2Ch)%3Bi%5B'release'%5D%5B'setValueAtTime'%5D(0.25%2Ch)%3Bo%5B'connect'%5D(p)%3Bp%5B'connect'%5D(i)%3Bi%5B'connect'%5D(a%5B'destination'%5D)%3B%7D)()%3B`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment