Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HDR toggle #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# About
enhanced-h264ify is a fork of well-known h264ify extension for Firefox/Chrome which blocks VP8/VP9 codecs on YouTube, so that you can use H264 only. This may be useful because there are lots of devices on the market which support H264 hardware decoding and do not support VP8/VP9.

This extension has new features such as manual blocking of H264, VP8, VP9, AV1 codecs and 60fps video. By default it blocks everything but H264 and 60fps video.
This extension has new features such as manual blocking of H264, VP8, VP9, AV1 codecs and 60fps or HDR videos. By default it blocks everything but H264 and 60fps/HDR videos.
It works only on YouTube.

# Installation
Expand Down
4 changes: 4 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"message": "Block 60fps video"
},

"optionsBlockHDR": {
"message": "Block HDR video"
},

"optionsBlockH264": {
"message": "Block h264"
},
Expand Down
1 change: 1 addition & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<h4 data-l10n-id="optionsTitle"></h4>
<ul>
<li><input type="checkbox" id="block_60fps" class="checkbox"><label for="block_60fps" data-l10n-id="optionsBlock60fps"></label></li>
<li><input type="checkbox" id="block_HDR" class="checkbox"><label for="block_HDR" data-l10n-id="optionsBlockHDR"></label></li>
<li><input type="checkbox" id="block_h264" class="checkbox"><label for="block_h264" data-l10n-id="optionsBlockH264"></label></li>
<li><input type="checkbox" id="block_vp8" class="checkbox"><label for="block_vp8" data-l10n-id="optionsBlockVP8"></label></li>
<li><input type="checkbox" id="block_vp9" class="checkbox"><label for="block_vp9" data-l10n-id="optionsBlockVP9"></label></li>
Expand Down
6 changes: 5 additions & 1 deletion options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Saves options to chrome.storage
function save_options() {
var block_60fps = document.getElementById('block_60fps').checked;
var block_HDR = document.getElementById('block_HDR').checked;
var block_h264 = document.getElementById('block_h264').checked;
var block_vp8 = document.getElementById('block_vp8').checked;
var block_vp9 = document.getElementById('block_vp9').checked;
Expand All @@ -9,6 +10,7 @@ function save_options() {
var disable_LN = document.getElementById('disable_LN').checked;
chrome.storage.local.set({
block_60fps: block_60fps,
block_HDR: block_HDR,
block_h264: block_h264,
block_vp8: block_vp8,
block_vp9: block_vp9,
Expand All @@ -22,13 +24,15 @@ function restore_options() {
// Default values
chrome.storage.local.get({
block_60fps: false,
block_HDR: false,
block_h264: false,
block_vp8: true,
block_vp9: true,
block_av1: true,
disable_LN: false
}, function(options) {
document.getElementById('block_60fps').checked = options.block_60fps;
document.getElementById('block_HDR').checked = options.block_HDR;
document.getElementById('block_h264').checked = options.block_h264;
document.getElementById('block_vp8').checked = options.block_vp8;
document.getElementById('block_vp9').checked = options.block_vp9;
Expand All @@ -48,5 +52,5 @@ for (var i = 0; i < checkboxes.length; i++) {

// l10n
for (let element of document.querySelectorAll('[data-l10n-id]')) {
element.textContent = chrome.i18n.getMessage(element.dataset.l10nId);
element.textContent = chrome.i18n.getMessage(element.dataset.l10nId) || element.dataset.l10nId;
}
5 changes: 5 additions & 0 deletions src/inject/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
if (localStorage['enhanced-h264ify-block_60fps'] === undefined) {
localStorage['enhanced-h264ify-block_60fps'] = false;
}
if (localStorage['enhanced-h264ify-block_HDR'] === undefined) {
localStorage['enhanced-h264ify-block_HDR'] = false;
}
if (localStorage['enhanced-h264ify-block_h264'] === undefined) {
localStorage['enhanced-h264ify-block_h264'] = false;
}
Expand All @@ -54,13 +57,15 @@ if (localStorage['enhanced-h264ify-disable_LN'] === undefined) {
chrome.storage.local.get({
// Set defaults
block_60fps: false,
block_HDR: false,
block_h264: false,
block_vp8: true,
block_vp9: true,
block_av1: true,
disable_LN: false
}, function(options) {
localStorage['enhanced-h264ify-block_60fps'] = options.block_60fps;
localStorage['enhanced-h264ify-block_HDR'] = options.block_HDR;
localStorage['enhanced-h264ify-block_h264'] = options.block_h264;
localStorage['enhanced-h264ify-block_vp8'] = options.block_vp8;
localStorage['enhanced-h264ify-block_vp9'] = options.block_vp9;
Expand Down
44 changes: 44 additions & 0 deletions src/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,50 @@ function inject () {
if (match && match[1] > 30) return '';
}

if (localStorage['enhanced-h264ify-block_HDR'] === 'true') {
// parse AV1 and VP8/VP9 format strings
// see https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter
const match = /codecs="(.*)"/.exec(type);
const codecs = match && match[1] ? match && match[1] : '';

const HDRTransferCharacteristics = [
'16', // SMPTE ST 2084 Perceptual Quantizer
'18' // BT.2100 Hybrid Log Gamma
];

if (/^av01/.test(codecs)) {
const [
fourCharacterCode,
profile,
level,
bitDepth,
monochrome,
chromaSubsampling,
colorPrimaries,
transferCharacteristics,
matrixCoefficients,
videoFullRangeFlag
] = codecs.split('.');

if (HDRTransferCharacteristics.includes(transferCharacteristics)) return '';

} else if (/^vp\d\d/.test(codecs)) {
const [
fourCharacterCode,
profile,
level,
bitDepth,
chromaSubsampling,
colorPrimaries,
transferCharacteristics,
matrixCoefficients,
videoFullRangeFlag
] = codecs.split('.');

if (HDRTransferCharacteristics.includes(transferCharacteristics)) return '';
}
}

// Otherwise, ask the browser
return origChecker(type);
};
Expand Down