-
-
Save fa7ad/fa995474f5cb9fe91fb209686881373d to your computer and use it in GitHub Desktop.
Disable youtube volume normalization (allow true video 100% volume)
This file contains 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
// ==UserScript== | |
// @name YouTube Disable Normalization | |
// @namespace https://gist.github.com/fa7ad/fa995474f5cb9fe91fb209686881373d | |
// @version 0.2 | |
// @description Allows true 100% volume on youtube videos. | |
// @author Wouter Gerarts | |
// @match https://www.youtube.com/* | |
// @match https://youtube.com/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
function baseElement() { | |
return document.querySelector("#content"); | |
} | |
if (typeof fullVolumeButtonTaskId === "number") { | |
console.log("clearing interval"); | |
clearInterval(fullVolumeButtonTaskId); | |
} | |
function maxVol() { | |
var videos = document.querySelectorAll("video"); | |
videos.forEach(function (video) { | |
video.volume = 1; | |
console.log(video, video.volume); | |
}); | |
} | |
function createFullVolumeButton() { | |
var css = ` | |
.full-volume-addon-button { | |
margin: 0 0.5em; | |
padding: 0.25em 1em; | |
background: transparent; | |
color: #fff; | |
border: 1px solid #fff; | |
border-radius: 1em; | |
font: caption; | |
} | |
.full-volume-addon-button:hover { | |
cursor: pointer; | |
background: #fff; | |
color: #000; | |
} | |
`; | |
var style = document.createElement("style"); | |
if (style.styleSheet) { | |
style.styleSheet.cssText = css; | |
} else { | |
style.appendChild(document.createTextNode(css)); | |
} | |
document.querySelector("head").appendChild(style); | |
var el = document.createElement("button"); | |
el.textContent = "100% Volume"; | |
el.classList.add("full-volume-addon-button"); | |
el.onclick = function (e) { | |
e.preventDefault(); | |
maxVol(); | |
}; | |
return el; | |
} | |
function round(num, sig) { | |
var mult = Math.pow(10, sig); | |
return Math.round(num * mult) / mult; | |
} | |
var fullVolumeButtonTaskId = setInterval(function () { | |
if (baseElement().querySelector("video") === undefined) { | |
console.log("video element not found"); | |
return; | |
} | |
var volTimer = setInterval(function () { | |
if ( | |
[].every.call(document.querySelectorAll("video"), function (vid) { | |
return vid.volume === 1; | |
}) | |
) { | |
console.log("vol maxed out"); | |
clearInterval(volTimer); | |
return; | |
} else { | |
maxVol(); | |
} | |
}, 500); | |
if (baseElement().querySelector(".full-volume-addon-button") != undefined) { | |
console.log("full volume addon button already found"); | |
clearInterval(fullVolumeButtonTaskId); | |
clearInterval(volTimer); | |
return; | |
} | |
var video = baseElement().querySelector("video"); | |
var videoTitleElement = baseElement().querySelector("#title h1"); | |
videoTitleElement.appendChild(createFullVolumeButton()); | |
}, 500); | |
})(); |
IIRC, enhanced-h264ify used to have successful prevention of normalization, but it stopped working at some point.
cf. https://github.com/alextrv/enhanced-h264ify/blob/e5f2ea22378e85fc55b9e6ccab27644b1bc66ba5/src/inject/inject.js#L79-L104
(and alextrv/enhanced-h264ify#1 (comment))
Whoops, I think I'll have to eat my own words. It seems like enhanced-h264ify actually still does work after disabling and re-enabling the checkbox as suggested in alextrv/enhanced-h264ify#7. Crazy.
FWIW, when lowering volume in the mixer, pausing and re-starting, then it stays. But when moving to a new video, it jumps back to 100%.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the reply! I'd definitely be interested in that, but take your time. :)
Regardless of the bug, I'd also like to disable normalization on its own.1
I tend to prefer having all sources at 100% and adjust volume only at the final output sink.
That said, I'm not sure whether it would work around the bug or not, either:
If any volume change API call to PulseAudio were be prevented, then I think it should.
But if two calls were made, one to normalized volume and another to go back to 100%, then I suppose it would still make the system mixer jump (i.e. lose any user-defined volume).
IIRC, enhanced-h264ify used to have successful prevention of normalization, but it stopped working at some point.
Footnotes
The better workaround would probably be to procure a JACK-enabled build of firefox, anyway. ↩