Last active
February 13, 2024 07:52
-
-
Save djshaji/8b3e7caa032536b90c7add149f316899 to your computer and use it in GitHub Desktop.
Automatically add dynamic compressor to all video elements on page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compressor = null | |
videos = document.getElementsByTagName ("video") | |
for (audioElt of videos) { | |
audioCtx = new AudioContext(); | |
// Create a MediaElementAudioSourceNode | |
// Feed the HTMLMediaElement into it | |
const source = new MediaElementAudioSourceNode(audioCtx, { | |
mediaElement: audioElt, | |
}); | |
// Create a compressor node | |
compressor = new DynamicsCompressorNode(audioCtx, { | |
threshold: -50, | |
knee: 40, | |
ratio: 12, | |
attack: 0, | |
release: 0.25, | |
}); | |
// connect the AudioBufferSourceNode to the destination | |
source.connect(audioCtx.destination); | |
source.connect(compressor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment