YouTube Codecs - Hardware Acceleration Only

Use codecs with hardware accleration supported for media playback on YouTube

  1. // ==UserScript==
  2. // @name YouTube Codecs - Hardware Acceleration Only
  3. // @name:zh-TW YouTube Codecs - Hardware Acceleration Only
  4. // @name:zh-HK YouTube Codecs - Hardware Acceleration Only
  5. // @name:zh-CN YouTube Codecs - Hardware Acceleration Only
  6. // @name:ja YouTube Codecs - Hardware Acceleration Only
  7. // @name:ko YouTube Codecs - Hardware Acceleration Only
  8. // @name:vi YouTube Codecs - Hardware Acceleration Only
  9. // @name:de YouTube Codecs - Hardware Acceleration Only
  10. // @name:fr YouTube Codecs - Hardware Acceleration Only
  11. // @name:it YouTube Codecs - Hardware Acceleration Only
  12. // @name:es YouTube Codecs - Hardware Acceleration Only
  13. // @description Use codecs with hardware accleration supported for media playback on YouTube
  14. // @description:zh-TW Use codecs with hardware accleration supported for media playback on YouTube
  15. // @description:zh-HK Use codecs with hardware accleration supported for media playback on YouTube
  16. // @description:zh-CN Use codecs with hardware accleration supported for media playback on YouTube
  17. // @description:ja Use codecs with hardware accleration supported for media playback on YouTube
  18. // @description:ko Use codecs with hardware accleration supported for media playback on YouTube
  19. // @description:vi Use codecs with hardware accleration supported for media playback on YouTube
  20. // @description:de Use codecs with hardware accleration supported for media playback on YouTube
  21. // @description:fr Use codecs with hardware accleration supported for media playback on YouTubee
  22. // @description:it Use codecs with hardware accleration supported for media playback on YouTube
  23. // @description:es Use codecs with hardware accleration supported for media playback on YouTube
  24. // @namespace http://tampermonkey.net/
  25. // @version 0.0.2
  26. // @author CY Fung
  27. // @match https://www.youtube.com/*
  28. // @match https://www.youtube.com/embed/*
  29. // @match https://www.youtube-nocookie.com/embed/*
  30. // @exclude https://www.youtube.com/live_chat*
  31. // @exclude https://www.youtube.com/live_chat_replay*
  32. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  33. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  34. // @grant none
  35. // @run-at document-start
  36. // @license MIT
  37. //
  38. // @compatible firefox Violentmonkey
  39. // @compatible firefox Tampermonkey
  40. // @compatible firefox FireMonkey
  41. // @compatible chrome Violentmonkey
  42. // @compatible chrome Tampermonkey
  43. // @compatible opera Violentmonkey
  44. // @compatible opera Tampermonkey
  45. // @compatible safari Stay
  46. // @compatible edge Violentmonkey
  47. // @compatible edge Tampermonkey
  48. // @compatible brave Violentmonkey
  49. // @compatible brave Tampermonkey
  50. //
  51. // @unwrap
  52. // @allFrames true
  53. // @inject-into page
  54. // ==/UserScript==
  55.  
  56. (function (__Promise__) {
  57. 'use strict';
  58.  
  59. /** @type {globalThis.PromiseConstructor} */
  60. const Promise = (async () => { })().constructor; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.
  61.  
  62. if (typeof VideoEncoder !== 'function' || typeof VideoEncoder.isConfigSupported !== 'function') {
  63. console.error('VideoEncoder.isConfigSupported is not supported');
  64. return;
  65. }
  66.  
  67. const storageKey = '__codecs_vvgZHhgVKfAlY0__';
  68. let useCache = false;
  69. let useAV1 = false;
  70. const getMap = () => {
  71. const v = localStorage[storageKey]
  72. if (v) {
  73. try {
  74. const obj = JSON.parse(v);
  75. const resMap = new Map(Object.entries(obj));
  76. useCache = true;
  77. return resMap;
  78. } catch (e) { }
  79. }
  80. return new Map();
  81. }
  82.  
  83. const objectKey = '__codecs_qyg8YVnvXJZ9E5__';
  84.  
  85. const __codecs__ = window[objectKey] || (window[objectKey] = getMap());
  86.  
  87. const testCodec = async (codec) => {
  88.  
  89. if (!codec) return null;
  90.  
  91. if (__codecs__.has(codec)) return __codecs__.get(codec);
  92.  
  93. __codecs__.set(codec, null);
  94.  
  95. const config = {
  96. codec: codec,
  97. hardwareAcceleration: 'prefer-hardware',
  98. width: 1920,
  99. height: 1080,
  100. bitrate: 12_000_000,
  101. bitrateMode: "variable",
  102. framerate: 60,
  103. sampleRate: 48000,
  104. numberOfChannels: 2,
  105. };
  106.  
  107. let supported = false;
  108.  
  109. try {
  110. const resV = await VideoDecoder.isConfigSupported(config);
  111. const resA = await AudioDecoder.isConfigSupported(config);
  112. if (resV.supported === true || resA.supported === true) {
  113. supported = true;
  114. }
  115. } catch (e) {
  116. console.warn(e)
  117. }
  118.  
  119. __codecs__.set(codec, supported);
  120.  
  121. return supported;
  122.  
  123. }
  124.  
  125. const getCodecResult = (codec) => {
  126. if (codec.length === 30 && /^av01\.0\.\d\dM\.\d\d\b/.test(`${codec}`)) {
  127. // av01.0.05M.08.0.110.05.01.06.0
  128. codec = codec.substring(0, 13);
  129. // av01.0.05M.08
  130. }
  131. let q = __codecs__.get(codec);
  132. return q;
  133. }
  134.  
  135. // reference: https://cobalt.googlesource.com/cobalt/+/refs/tags/24.lts.40/starboard/nplb/media_can_play_mime_and_key_system_test_helpers.h
  136. // https://cconcolato.github.io/media-mime-support/mediacapabilities.html
  137.  
  138. if (useCache) {
  139. console.log('[yt-codecs-hardware-acceleration-only] (init) load from cache')
  140. } else {
  141. Promise.all([
  142. "avc1.420034",
  143. "hvc1.1.6.L123.00",
  144. "vp8",
  145. // "vp09.00.10.08",
  146. // "av01.0.04M.08",
  147. "vp09.02.51.10.01.09.16.09.00",
  148. "vp09.02.51.10.01.09.99.99.00",
  149. "vp09.02.50.10.01.09.16.09.00",
  150. "vp09.02.50.10.01.09.99.99.00",
  151. "vp09.02.41.10.01.09.16.09.00",
  152. "vp09.02.41.10.01.09.99.99.00",
  153. "vp09.02.40.10.01.09.16.09.00",
  154. "vp09.02.40.10.01.09.99.99.00",
  155. "vp09.02.31.10.01.09.16.09.00",
  156. "vp09.02.31.10.01.09.99.09.00",
  157. "vp09.02.30.10.01.09.16.09.00",
  158. "vp09.02.30.10.01.09.99.09.00",
  159. "vp09.02.21.10.01.09.16.09.00",
  160. "vp09.02.21.10.01.09.99.09.00",
  161. "vp09.02.11.10.01.09.16.09.00",
  162. "vp09.02.11.10.01.09.99.09.00",
  163. "vp09.02.10.10.01.09.16.09.00",
  164. "vp09.02.10.10.01.09.99.09.00",
  165. "mp4a.40.5",
  166. "mp4a.40.2",
  167. "opus",
  168. "vp9",
  169. "vp09.00.51.08.01.01.01.01.00",
  170. "vp09.00.51.08",
  171. "vp09.00.50.08",
  172. "vp09.00.41.08",
  173. "vp09.00.40.08",
  174. "vp09.00.31.08",
  175. "vp09.00.30.08",
  176. "vp09.00.21.08",
  177. "vp09.00.20.08",
  178. "vp09.00.11.08",
  179. "vp09.00.10.08",
  180. "avc1.640028",
  181. "avc1.4d401e",
  182. "avc1.4d4015",
  183. "avc1.4d400c",
  184. "avc1.42001E",
  185. "avc1.4d401f",
  186. "avc1.64001F",
  187. "avc1.4d4020",
  188. "avc1.64002a",
  189. "avc1.64002A",
  190. "avc1.4D4020",
  191. "avc1.4D401F",
  192. "avc1.4D401E",
  193. "avc1.4D4015",
  194. "avc1.4D400C",
  195. "avc1.4d002a",
  196. "avc1.4d0028",
  197. "avc1.6e0034",
  198.  
  199. "av01.0.00M.08",
  200. "av01.0.01M.08",
  201. "av01.0.02M.08",
  202. "av01.0.03M.08",
  203. "av01.0.04M.08",
  204. "av01.0.05M.08",
  205. "av01.0.06M.08",
  206. "av01.0.07M.08",
  207. "av01.0.08M.08",
  208. "av01.0.09M.08",
  209. "av01.0.12M.08",
  210. "av01.0.13M.08",
  211. "av01.0.14M.08",
  212. "av01.0.15M.08",
  213. "av01.0.16M.08",
  214. "av01.0.17M.08",
  215. "av01.0.18M.08",
  216. "av01.0.19M.08",
  217.  
  218.  
  219. "av01.0.00M.10",
  220. "av01.0.01M.10",
  221. "av01.0.02M.10",
  222. "av01.0.03M.10",
  223. "av01.0.04M.10",
  224. "av01.0.05M.10",
  225. "av01.0.06M.10",
  226. "av01.0.07M.10",
  227. "av01.0.08M.10",
  228. "av01.0.09M.10",
  229. "av01.0.12M.10",
  230. "av01.0.13M.10",
  231. "av01.0.14M.10",
  232. "av01.0.15M.10",
  233. "av01.0.16M.10",
  234. "av01.0.17M.10",
  235. "av01.0.18M.10",
  236. "av01.0.19M.10",
  237.  
  238.  
  239. /*
  240.  
  241. "av01.0.00M.10.0.110.09.16.09.0",
  242. "av01.0.01M.10.0.110.09.16.09.0",
  243. "av01.0.02M.10.0.110.09.16.09.0",
  244. "av01.0.03M.10.0.110.09.16.09.0",
  245. "av01.0.04M.10.0.110.09.16.09.0",
  246. "av01.0.05M.10.0.110.09.16.09.0",
  247. "av01.0.06M.10.0.110.09.16.09.0",
  248. "av01.0.07M.10.0.110.09.16.09.0",
  249. "av01.0.08M.10.0.110.09.16.09.0",
  250. "av01.0.09M.10.0.110.09.16.09.0",
  251. "av01.0.12M.10.0.110.09.16.09.0",
  252. "av01.0.13M.10.0.110.09.16.09.0",
  253. "av01.0.14M.10.0.110.09.16.09.0",
  254. "av01.0.15M.10.0.110.09.16.09.0",
  255. "av01.0.16M.10.0.110.09.16.09.0",
  256. "av01.0.17M.10.0.110.09.16.09.0",
  257. "av01.0.18M.10.0.110.09.16.09.0",
  258. "av01.0.19M.10.0.110.09.16.09.0",
  259.  
  260.  
  261. "av01.0.00M.08.0.110.05.01.06.0",
  262. "av01.0.01M.08.0.110.05.01.06.0",
  263. "av01.0.02M.08.0.110.05.01.06.0",
  264. "av01.0.03M.08.0.110.05.01.06.0",
  265. "av01.0.04M.08.0.110.05.01.06.0",
  266. "av01.0.05M.08.0.110.05.01.06.0",
  267. "av01.0.06M.08.0.110.05.01.06.0",
  268. "av01.0.07M.08.0.110.05.01.06.0",
  269. "av01.0.08M.08.0.110.05.01.06.0",
  270. "av01.0.09M.08.0.110.05.01.06.0",
  271. "av01.0.12M.08.0.110.05.01.06.0",
  272. "av01.0.13M.08.0.110.05.01.06.0",
  273. "av01.0.14M.08.0.110.05.01.06.0",
  274. "av01.0.15M.08.0.110.05.01.06.0",
  275. "av01.0.16M.08.0.110.05.01.06.0",
  276. "av01.0.17M.08.0.110.05.01.06.0",
  277. "av01.0.18M.08.0.110.05.01.06.0",
  278. "av01.0.19M.08.0.110.05.01.06.0",
  279.  
  280.  
  281. "av01.0.00M.08.0.110.06.01.06.0",
  282. "av01.0.01M.08.0.110.06.01.06.0",
  283. "av01.0.02M.08.0.110.06.01.06.0",
  284. "av01.0.03M.08.0.110.06.01.06.0",
  285. "av01.0.04M.08.0.110.06.01.06.0",
  286. "av01.0.05M.08.0.110.06.01.06.0",
  287. "av01.0.06M.08.0.110.06.01.06.0",
  288. "av01.0.07M.08.0.110.06.01.06.0",
  289. "av01.0.08M.08.0.110.06.01.06.0",
  290. "av01.0.09M.08.0.110.06.01.06.0",
  291. "av01.0.12M.08.0.110.06.01.06.0",
  292. "av01.0.13M.08.0.110.06.01.06.0",
  293. "av01.0.14M.08.0.110.06.01.06.0",
  294. "av01.0.15M.08.0.110.06.01.06.0",
  295. "av01.0.16M.08.0.110.06.01.06.0",
  296. "av01.0.17M.08.0.110.06.01.06.0",
  297. "av01.0.18M.08.0.110.06.01.06.0",
  298. "av01.0.19M.08.0.110.06.01.06.0",
  299.  
  300. */
  301.  
  302. "av01.0.00M.08",
  303. "av01.0.00M.10",
  304. "av01.0.00M.12",
  305. "av01.0.00H.08",
  306. "av01.0.00H.10",
  307. "av01.0.00H.12",
  308. "av01.0.01M.08",
  309. "av01.0.01M.10",
  310. "av01.0.01M.12",
  311. "av01.0.01H.08",
  312. "av01.0.01H.10",
  313. "av01.0.01H.12",
  314. "av01.0.02M.08",
  315. "av01.0.02M.10",
  316. "av01.0.02M.12",
  317. "av01.0.02H.08",
  318. "av01.0.02H.10",
  319. "av01.0.02H.12",
  320. "av01.0.03M.08",
  321. "av01.0.03M.10",
  322. "av01.0.03M.12",
  323. "av01.0.03H.08",
  324. "av01.0.03H.10",
  325. "av01.0.03H.12",
  326. "av01.0.04M.08",
  327. "av01.0.04M.10",
  328. "av01.0.04M.12",
  329. "av01.0.04H.08",
  330. "av01.0.04H.10",
  331. "av01.0.04H.12",
  332. "av01.0.05M.08",
  333. "av01.0.05M.10",
  334. "av01.0.05M.12",
  335. "av01.0.05H.08",
  336. "av01.0.05H.10",
  337. "av01.0.05H.12",
  338. "av01.0.06M.08",
  339. "av01.0.06M.10",
  340. "av01.0.06M.12",
  341. "av01.0.06H.08",
  342. "av01.0.06H.10",
  343. "av01.0.06H.12",
  344. "av01.0.07M.08",
  345. "av01.0.07M.10",
  346. "av01.0.07M.12",
  347. "av01.0.07H.08",
  348. "av01.0.07H.10",
  349. "av01.0.07H.12",
  350. "av01.0.08M.08",
  351. "av01.0.08M.10",
  352. "av01.0.08M.12",
  353. "av01.0.08H.08",
  354. "av01.0.08H.10",
  355. "av01.0.08H.12",
  356. "av01.0.09M.08",
  357. "av01.0.09M.10",
  358. "av01.0.09M.12",
  359. "av01.0.09H.08",
  360. "av01.0.09H.10",
  361. "av01.0.09H.12",
  362. "av01.0.10M.08",
  363. "av01.0.10M.10",
  364. "av01.0.10M.12",
  365. "av01.0.10H.08",
  366. "av01.0.10H.10",
  367. "av01.0.10H.12",
  368. "av01.0.11M.08",
  369. "av01.0.11M.10",
  370. "av01.0.11M.12",
  371. "av01.0.11H.08",
  372. "av01.0.11H.10",
  373. "av01.0.11H.12",
  374. "av01.0.12M.08",
  375. "av01.0.12M.10",
  376. "av01.0.12M.12",
  377. "av01.0.12H.08",
  378. "av01.0.12H.10",
  379. "av01.0.12H.12",
  380. "av01.0.13M.08",
  381. "av01.0.13M.10",
  382. "av01.0.13M.12",
  383. "av01.0.13H.08",
  384. "av01.0.13H.10",
  385. "av01.0.13H.12",
  386. "av01.0.14M.08",
  387. "av01.0.14M.10",
  388. "av01.0.14M.12",
  389. "av01.0.14H.08",
  390. "av01.0.14H.10",
  391. "av01.0.14H.12",
  392. "av01.0.15M.08",
  393. "av01.0.15M.10",
  394. "av01.0.15M.12",
  395. "av01.0.15H.08",
  396. "av01.0.15H.10",
  397. "av01.0.15H.12",
  398. "av01.0.16M.08",
  399. "av01.0.16M.10",
  400. "av01.0.16M.12",
  401. "av01.0.16H.08",
  402. "av01.0.16H.10",
  403. "av01.0.16H.12",
  404. "av01.0.17M.08",
  405. "av01.0.17M.10",
  406. "av01.0.17M.12",
  407. "av01.0.17H.08",
  408. "av01.0.17H.10",
  409. "av01.0.17H.12",
  410. "av01.0.18M.08",
  411. "av01.0.18M.10",
  412. "av01.0.18M.12",
  413. "av01.0.18H.08",
  414. "av01.0.18H.10",
  415. "av01.0.18H.12",
  416. "av01.0.19M.08",
  417. "av01.0.19M.10",
  418. "av01.0.19M.12",
  419. "av01.0.19H.08",
  420. "av01.0.19H.10",
  421. "av01.0.19H.12",
  422. "av01.0.20M.08",
  423. "av01.0.20M.10",
  424. "av01.0.20M.12",
  425. "av01.0.20H.08",
  426. "av01.0.20H.10",
  427. "av01.0.20H.12",
  428. "av01.0.21M.08",
  429. "av01.0.21M.10",
  430. "av01.0.21M.12",
  431. "av01.0.21H.08",
  432. "av01.0.21H.10",
  433. "av01.0.21H.12",
  434. "av01.0.22M.08",
  435. "av01.0.22M.10",
  436. "av01.0.22M.12",
  437. "av01.0.22H.08",
  438. "av01.0.22H.10",
  439. "av01.0.22H.12",
  440. "av01.0.23M.08",
  441. "av01.0.23M.10",
  442. "av01.0.23M.12",
  443. "av01.0.23H.08",
  444. "av01.0.23H.10",
  445. "av01.0.23H.12",
  446. "av01.0.31M.08",
  447. "av01.0.31M.10",
  448. "av01.0.31M.12",
  449. "av01.0.31H.08",
  450. "av01.0.31H.10",
  451. "av01.0.31H.12",
  452. "av01.1.00M.08",
  453. "av01.1.00M.10",
  454. "av01.1.00M.12",
  455. "av01.1.00H.08",
  456. "av01.1.00H.10",
  457. "av01.1.00H.12",
  458. "av01.1.01M.08",
  459. "av01.1.01M.10",
  460. "av01.1.01M.12",
  461. "av01.1.01H.08",
  462. "av01.1.01H.10",
  463. "av01.1.01H.12",
  464. "av01.1.02M.08",
  465. "av01.1.02M.10",
  466. "av01.1.02M.12",
  467. "av01.1.02H.08",
  468. "av01.1.02H.10",
  469. "av01.1.02H.12",
  470. "av01.1.03M.08",
  471. "av01.1.03M.10",
  472. "av01.1.03M.12",
  473. "av01.1.03H.08",
  474. "av01.1.03H.10",
  475. "av01.1.03H.12",
  476. "av01.1.04M.08",
  477. "av01.1.04M.10",
  478. "av01.1.04M.12",
  479. "av01.1.04H.08",
  480. "av01.1.04H.10",
  481. "av01.1.04H.12",
  482. "av01.1.05M.08",
  483. "av01.1.05M.10",
  484. "av01.1.05M.12",
  485. "av01.1.05H.08",
  486. "av01.1.05H.10",
  487. "av01.1.05H.12",
  488. "av01.1.06M.08",
  489. "av01.1.06M.10",
  490. "av01.1.06M.12",
  491. "av01.1.06H.08",
  492. "av01.1.06H.10",
  493. "av01.1.06H.12",
  494. "av01.1.07M.08",
  495. "av01.1.07M.10",
  496. "av01.1.07M.12",
  497. "av01.1.07H.08",
  498. "av01.1.07H.10",
  499. "av01.1.07H.12",
  500. "av01.1.08M.08",
  501. "av01.1.08M.10",
  502. "av01.1.08M.12",
  503. "av01.1.08H.08",
  504. "av01.1.08H.10",
  505. "av01.1.08H.12",
  506. "av01.1.09M.08",
  507. "av01.1.09M.10",
  508. "av01.1.09M.12",
  509. "av01.1.09H.08",
  510. "av01.1.09H.10",
  511. "av01.1.09H.12",
  512. "av01.1.10M.08",
  513. "av01.1.10M.10",
  514. "av01.1.10M.12",
  515. "av01.1.10H.08",
  516. "av01.1.10H.10",
  517. "av01.1.10H.12",
  518. "av01.1.11M.08",
  519. "av01.1.11M.10",
  520. "av01.1.11M.12",
  521. "av01.1.11H.08",
  522. "av01.1.11H.10",
  523. "av01.1.11H.12",
  524. "av01.1.12M.08",
  525. "av01.1.12M.10",
  526. "av01.1.12M.12",
  527. "av01.1.12H.08",
  528. "av01.1.12H.10",
  529. "av01.1.12H.12",
  530. "av01.1.13M.08",
  531. "av01.1.13M.10",
  532. "av01.1.13M.12",
  533. "av01.1.13H.08",
  534. "av01.1.13H.10",
  535. "av01.1.13H.12",
  536. "av01.1.14M.08",
  537. "av01.1.14M.10",
  538. "av01.1.14M.12",
  539. "av01.1.14H.08",
  540. "av01.1.14H.10",
  541. "av01.1.14H.12",
  542. "av01.1.15M.08",
  543. "av01.1.15M.10",
  544. "av01.1.15M.12",
  545. "av01.1.15H.08",
  546. "av01.1.15H.10",
  547. "av01.1.15H.12",
  548. "av01.1.16M.08",
  549. "av01.1.16M.10",
  550. "av01.1.16M.12",
  551. "av01.1.16H.08",
  552. "av01.1.16H.10",
  553. "av01.1.16H.12",
  554. "av01.1.17M.08",
  555. "av01.1.17M.10",
  556. "av01.1.17M.12",
  557. "av01.1.17H.08",
  558. "av01.1.17H.10",
  559. "av01.1.17H.12",
  560. "av01.1.18M.08",
  561. "av01.1.18M.10",
  562. "av01.1.18M.12",
  563. "av01.1.18H.08",
  564. "av01.1.18H.10",
  565. "av01.1.18H.12",
  566. "av01.1.19M.08",
  567. "av01.1.19M.10",
  568. "av01.1.19M.12",
  569. "av01.1.19H.08",
  570. "av01.1.19H.10",
  571. "av01.1.19H.12",
  572. "av01.1.20M.08",
  573. "av01.1.20M.10",
  574. "av01.1.20M.12",
  575. "av01.1.20H.08",
  576. "av01.1.20H.10",
  577. "av01.1.20H.12",
  578. "av01.1.21M.08",
  579. "av01.1.21M.10",
  580. "av01.1.21M.12",
  581. "av01.1.21H.08",
  582. "av01.1.21H.10",
  583. "av01.1.21H.12",
  584. "av01.1.22M.08",
  585. "av01.1.22M.10",
  586. "av01.1.22M.12",
  587. "av01.1.22H.08",
  588. "av01.1.22H.10",
  589. "av01.1.22H.12",
  590. "av01.1.23M.08",
  591. "av01.1.23M.10",
  592. "av01.1.23M.12",
  593. "av01.1.23H.08",
  594. "av01.1.23H.10",
  595. "av01.1.23H.12",
  596. "av01.1.31M.08",
  597. "av01.1.31M.10",
  598. "av01.1.31M.12",
  599. "av01.1.31H.08",
  600. "av01.1.31H.10",
  601. "av01.1.31H.12",
  602. "av01.2.00M.08",
  603. "av01.2.00M.10",
  604. "av01.2.00M.12",
  605. "av01.2.00H.08",
  606. "av01.2.00H.10",
  607. "av01.2.00H.12",
  608. "av01.2.01M.08",
  609. "av01.2.01M.10",
  610. "av01.2.01M.12",
  611. "av01.2.01H.08",
  612. "av01.2.01H.10",
  613. "av01.2.01H.12",
  614. "av01.2.02M.08",
  615. "av01.2.02M.10",
  616. "av01.2.02M.12",
  617. "av01.2.02H.08",
  618. "av01.2.02H.10",
  619. "av01.2.02H.12",
  620. "av01.2.03M.08",
  621. "av01.2.03M.10",
  622. "av01.2.03M.12",
  623. "av01.2.03H.08",
  624. "av01.2.03H.10",
  625. "av01.2.03H.12",
  626. "av01.2.04M.08",
  627. "av01.2.04M.10",
  628. "av01.2.04M.12",
  629. "av01.2.04H.08",
  630. "av01.2.04H.10",
  631. "av01.2.04H.12",
  632. "av01.2.05M.08",
  633. "av01.2.05M.10",
  634. "av01.2.05M.12",
  635. "av01.2.05H.08",
  636. "av01.2.05H.10",
  637. "av01.2.05H.12",
  638. "av01.2.06M.08",
  639. "av01.2.06M.10",
  640. "av01.2.06M.12",
  641. "av01.2.06H.08",
  642. "av01.2.06H.10",
  643. "av01.2.06H.12",
  644. "av01.2.07M.08",
  645. "av01.2.07M.10",
  646. "av01.2.07M.12",
  647. "av01.2.07H.08",
  648. "av01.2.07H.10",
  649. "av01.2.07H.12",
  650. "av01.2.08M.08",
  651. "av01.2.08M.10",
  652. "av01.2.08M.12",
  653. "av01.2.08H.08",
  654. "av01.2.08H.10",
  655. "av01.2.08H.12",
  656. "av01.2.09M.08",
  657. "av01.2.09M.10",
  658. "av01.2.09M.12",
  659. "av01.2.09H.08",
  660. "av01.2.09H.10",
  661. "av01.2.09H.12",
  662. "av01.2.10M.08",
  663. "av01.2.10M.10",
  664. "av01.2.10M.12",
  665. "av01.2.10H.08",
  666. "av01.2.10H.10",
  667. "av01.2.10H.12",
  668. "av01.2.11M.08",
  669. "av01.2.11M.10",
  670. "av01.2.11M.12",
  671. "av01.2.11H.08",
  672. "av01.2.11H.10",
  673. "av01.2.11H.12",
  674. "av01.2.12M.08",
  675. "av01.2.12M.10",
  676. "av01.2.12M.12",
  677. "av01.2.12H.08",
  678. "av01.2.12H.10",
  679. "av01.2.12H.12",
  680. "av01.2.13M.08",
  681. "av01.2.13M.10",
  682. "av01.2.13M.12",
  683. "av01.2.13H.08",
  684. "av01.2.13H.10",
  685. "av01.2.13H.12",
  686. "av01.2.14M.08",
  687. "av01.2.14M.10",
  688. "av01.2.14M.12",
  689. "av01.2.14H.08",
  690. "av01.2.14H.10",
  691. "av01.2.14H.12",
  692. "av01.2.15M.08",
  693. "av01.2.15M.10",
  694. "av01.2.15M.12",
  695. "av01.2.15H.08",
  696. "av01.2.15H.10",
  697. "av01.2.15H.12",
  698. "av01.2.16M.08",
  699. "av01.2.16M.10",
  700. "av01.2.16M.12",
  701. "av01.2.16H.08",
  702. "av01.2.16H.10",
  703. "av01.2.16H.12",
  704. "av01.2.17M.08",
  705. "av01.2.17M.10",
  706. "av01.2.17M.12",
  707. "av01.2.17H.08",
  708. "av01.2.17H.10",
  709. "av01.2.17H.12",
  710. "av01.2.18M.08",
  711. "av01.2.18M.10",
  712. "av01.2.18M.12",
  713. "av01.2.18H.08",
  714. "av01.2.18H.10",
  715. "av01.2.18H.12",
  716. "av01.2.19M.08",
  717. "av01.2.19M.10",
  718. "av01.2.19M.12",
  719. "av01.2.19H.08",
  720. "av01.2.19H.10",
  721. "av01.2.19H.12",
  722. "av01.2.20M.08",
  723. "av01.2.20M.10",
  724. "av01.2.20M.12",
  725. "av01.2.20H.08",
  726. "av01.2.20H.10",
  727. "av01.2.20H.12",
  728. "av01.2.21M.08",
  729. "av01.2.21M.10",
  730. "av01.2.21M.12",
  731. "av01.2.21H.08",
  732. "av01.2.21H.10",
  733. "av01.2.21H.12",
  734. "av01.2.22M.08",
  735. "av01.2.22M.10",
  736. "av01.2.22M.12",
  737. "av01.2.22H.08",
  738. "av01.2.22H.10",
  739. "av01.2.22H.12",
  740. "av01.2.23M.08",
  741. "av01.2.23M.10",
  742. "av01.2.23M.12",
  743. "av01.2.23H.08",
  744. "av01.2.23H.10",
  745. "av01.2.23H.12",
  746. "av01.2.31M.08",
  747. "av01.2.31M.10",
  748. "av01.2.31M.12",
  749. "av01.2.31H.08",
  750. "av01.2.31H.10",
  751. "av01.2.31H.12",
  752.  
  753. "avc1.42000a",
  754. "avc1.42000b",
  755. "avc1.42000c",
  756. "avc1.42000d",
  757. "avc1.420014",
  758. "avc1.420015",
  759. "avc1.420016",
  760. "avc1.42001e",
  761. "avc1.42001f",
  762. "avc1.420020",
  763. "avc1.420028",
  764. "avc1.420029",
  765. "avc1.42002a",
  766. "avc1.420032",
  767. "avc1.420033",
  768. "avc1.420034",
  769. "avc1.42400a",
  770. "avc1.42400b",
  771. "avc1.42400c",
  772. "avc1.42400d",
  773. "avc1.424014",
  774. "avc1.424015",
  775. "avc1.424016",
  776. "avc1.42401e",
  777. "avc1.42401f",
  778. "avc1.424020",
  779. "avc1.424028",
  780. "avc1.424029",
  781. "avc1.42402a",
  782. "avc1.424032",
  783. "avc1.424033",
  784. "avc1.424034",
  785. "avc1.4d000a",
  786. "avc1.4d000b",
  787. "avc1.4d000c",
  788. "avc1.4d000d",
  789. "avc1.4d0014",
  790. "avc1.4d0015",
  791. "avc1.4d0016",
  792. "avc1.4d001e",
  793. "avc1.4d001f",
  794. "avc1.4d0020",
  795. "avc1.4d0028",
  796. "avc1.4d0029",
  797. "avc1.4d002a",
  798. "avc1.4d0032",
  799. "avc1.4d0033",
  800. "avc1.4d0034",
  801. "avc1.4d400a",
  802. "avc1.4d400b",
  803. "avc1.4d400c",
  804. "avc1.4d400d",
  805. "avc1.4d4014",
  806. "avc1.4d4015",
  807. "avc1.4d4016",
  808. "avc1.4d401e",
  809. "avc1.4d401f",
  810. "avc1.4d4020",
  811. "avc1.4d4028",
  812. "avc1.4d4029",
  813. "avc1.4d402a",
  814. "avc1.4d4032",
  815. "avc1.4d4033",
  816. "avc1.4d4034",
  817. "avc1.58000a",
  818. "avc1.58000b",
  819. "avc1.58000c",
  820. "avc1.58000d",
  821. "avc1.580014",
  822. "avc1.580015",
  823. "avc1.580016",
  824. "avc1.58001e",
  825. "avc1.58001f",
  826. "avc1.580020",
  827. "avc1.580028",
  828. "avc1.580029",
  829. "avc1.58002a",
  830. "avc1.580032",
  831. "avc1.580033",
  832. "avc1.580034",
  833. "avc1.64000a",
  834. "avc1.64000b",
  835. "avc1.64000c",
  836. "avc1.64000d",
  837. "avc1.640014",
  838. "avc1.640015",
  839. "avc1.640016",
  840. "avc1.64001e",
  841. "avc1.64001f",
  842. "avc1.640020",
  843. "avc1.640028",
  844. "avc1.640029",
  845. "avc1.64002a",
  846. "avc1.640032",
  847. "avc1.640033",
  848. "avc1.640034",
  849. "avc1.64080a",
  850. "avc1.64080b",
  851. "avc1.64080c",
  852. "avc1.64080d",
  853. "avc1.640814",
  854. "avc1.640815",
  855. "avc1.640816",
  856. "avc1.64081e",
  857. "avc1.64081f",
  858. "avc1.640820",
  859. "avc1.640828",
  860. "avc1.640829",
  861. "avc1.64082a",
  862. "avc1.640832",
  863. "avc1.640833",
  864. "avc1.640834",
  865. "avc1.6e000a",
  866. "avc1.6e000b",
  867. "avc1.6e000c",
  868. "avc1.6e000d",
  869. "avc1.6e0014",
  870. "avc1.6e0015",
  871. "avc1.6e0016",
  872. "avc1.6e001e",
  873. "avc1.6e001f",
  874. "avc1.6e0020",
  875. "avc1.6e0028",
  876. "avc1.6e0029",
  877. "avc1.6e002a",
  878. "avc1.6e0032",
  879. "avc1.6e0033",
  880. "avc1.6e0034",
  881. "avc1.6e100a",
  882. "avc1.6e100b",
  883. "avc1.6e100c",
  884. "avc1.6e100d",
  885. "avc1.6e1014",
  886. "avc1.6e1015",
  887. "avc1.6e1016",
  888. "avc1.6e101e",
  889. "avc1.6e101f",
  890. "avc1.6e1020",
  891. "avc1.6e1028",
  892. "avc1.6e1029",
  893. "avc1.6e102a",
  894. "avc1.6e1032",
  895. "avc1.6e1033",
  896. "avc1.6e1034",
  897. "avc1.7a000a",
  898. "avc1.7a000b",
  899. "avc1.7a000c",
  900. "avc1.7a000d",
  901. "avc1.7a0014",
  902. "avc1.7a0015",
  903. "avc1.7a0016",
  904. "avc1.7a001e",
  905. "avc1.7a001f",
  906. "avc1.7a0020",
  907. "avc1.7a0028",
  908. "avc1.7a0029",
  909. "avc1.7a002a",
  910. "avc1.7a0032",
  911. "avc1.7a0033",
  912. "avc1.7a0034",
  913. "avc1.7a100a",
  914. "avc1.7a100b",
  915. "avc1.7a100c",
  916. "avc1.7a100d",
  917. "avc1.7a1014",
  918. "avc1.7a1015",
  919. "avc1.7a1016",
  920. "avc1.7a101e",
  921. "avc1.7a101f",
  922. "avc1.7a1020",
  923. "avc1.7a1028",
  924. "avc1.7a1029",
  925. "avc1.7a102a",
  926. "avc1.7a1032",
  927. "avc1.7a1033",
  928. "avc1.7a1034",
  929. "avc1.f4000a",
  930. "avc1.f4000b",
  931. "avc1.f4000c",
  932. "avc1.f4000d",
  933. "avc1.f40014",
  934. "avc1.f40015",
  935. "avc1.f40016",
  936. "avc1.f4001e",
  937. "avc1.f4001f",
  938. "avc1.f40020",
  939. "avc1.f40028",
  940. "avc1.f40029",
  941. "avc1.f4002a",
  942. "avc1.f40032",
  943. "avc1.f40033",
  944. "avc1.f40034",
  945. "avc1.f4100a",
  946. "avc1.f4100b",
  947. "avc1.f4100c",
  948. "avc1.f4100d",
  949. "avc1.f41014",
  950. "avc1.f41015",
  951. "avc1.f41016",
  952. "avc1.f4101e",
  953. "avc1.f4101f",
  954. "avc1.f41020",
  955. "avc1.f41028",
  956. "avc1.f41029",
  957. "avc1.f4102a",
  958. "avc1.f41032",
  959. "avc1.f41033",
  960. "avc1.f41034",
  961. "avc1.2c000a",
  962. "avc1.2c000b",
  963. "avc1.2c000c",
  964. "avc1.2c000d",
  965. "avc1.2c0014",
  966. "avc1.2c0015",
  967. "avc1.2c0016",
  968. "avc1.2c001e",
  969. "avc1.2c001f",
  970. "avc1.2c0020",
  971. "avc1.2c0028",
  972. "avc1.2c0029",
  973. "avc1.2c002a",
  974. "avc1.2c0032",
  975. "avc1.2c0033",
  976. "avc1.2c0034",
  977.  
  978. "av01.0.08H.10",
  979. "hev1.1.6.L93.B0",
  980. "hev1.2.4.L120.B0",
  981.  
  982. "avc1.4d400b",
  983. "mp4v.20.3",
  984. "avc1.42001E, mp4a.40.2",
  985. "avc1.64001F, mp4a.40.2",
  986. "vp9.2",
  987.  
  988. "av99.0.05M.08",
  989. "ec-3",
  990.  
  991. "ac-3",
  992.  
  993. ].map(testCodec)).then(() => {
  994.  
  995. try {
  996. localStorage[storageKey] = JSON.stringify(Object.fromEntries(__codecs__.entries()));
  997. } catch (e) { }
  998.  
  999. console.log('[yt-codecs-hardware-acceleration-only] (init) check done')
  1000. }).catch(console.warn);
  1001. }
  1002.  
  1003. const supportedFormatsConfig = () => {
  1004.  
  1005. function typeTest(type) {
  1006.  
  1007. if (typeof type === 'string' && type.startsWith('video/')) {
  1008. if (useAV1) {
  1009. if (type.includes('av01')) {
  1010. if (/codecs[\x20-\x7F]+\bav01\b/.test(type)) return true;
  1011. } else if (type.includes('av1')) {
  1012. if (/codecs[\x20-\x7F]+\bav1\b/.test(type)) return true;
  1013. }
  1014. }
  1015. }
  1016.  
  1017. }
  1018.  
  1019. // return a custom MIME type checker that can defer to the original function
  1020. function makeModifiedTypeChecker(origChecker, dx) {
  1021. // Check if a video type is allowed
  1022. return function (type) {
  1023.  
  1024. let m;
  1025. if (m = /codecs="([^"\r\n]*?)"/.exec(type)) {
  1026.  
  1027. const codec = m[1];
  1028. const codecRes = getCodecResult(codec);
  1029.  
  1030. if (codecRes === false) return "";
  1031.  
  1032. if (codecRes === undefined) {
  1033.  
  1034. testCodec(codec);
  1035.  
  1036. console.warn('[yt-codecs-hardware-acceleration-only] new format', type)
  1037.  
  1038. }
  1039.  
  1040. }
  1041.  
  1042. let res = undefined;
  1043. if (type === undefined) res = false;
  1044. else res = typeTest(type);
  1045. if (res === undefined) res = origChecker.apply(this, arguments);
  1046. else res = !dx ? res : (res ? "probably" : "");
  1047.  
  1048. // console.debug(20, type, res)
  1049.  
  1050. return res;
  1051. };
  1052. }
  1053.  
  1054. // Override video element canPlayType() function
  1055. const proto = (HTMLVideoElement || 0).prototype;
  1056. if (proto && typeof proto.canPlayType == 'function') {
  1057. proto.canPlayType = makeModifiedTypeChecker(proto.canPlayType, true);
  1058. }
  1059.  
  1060. // Override media source extension isTypeSupported() function
  1061. const mse = window.MediaSource;
  1062. // Check for MSE support before use
  1063. if (mse && typeof mse.isTypeSupported == 'function') {
  1064. mse.isTypeSupported = makeModifiedTypeChecker(mse.isTypeSupported);
  1065. }
  1066.  
  1067.  
  1068. }
  1069.  
  1070. function enableAV1() {
  1071. // This is the setting to force AV1
  1072. // localStorage['yt-player-av1-pref'] = '8192';
  1073. try {
  1074. Object.defineProperty(localStorage.constructor.prototype, 'yt-player-av1-pref', {
  1075. get() {
  1076. if (this === localStorage) return '8192';
  1077. return this.getItem('yt-player-av1-pref');
  1078. },
  1079. set(nv) {
  1080. this.setItem('yt-player-av1-pref', nv);
  1081. return true;
  1082. },
  1083. enumerable: true,
  1084. configurable: true
  1085. });
  1086. } catch (e) {
  1087. // localStorage['yt-player-av1-pref'] = '8192';
  1088. }
  1089. if (localStorage['yt-player-av1-pref'] !== '8192') {
  1090. console.warn('Use YouTube AV1 is not supported in your browser.');
  1091. return;
  1092. }
  1093. useAV1 = true;
  1094. }
  1095.  
  1096. let promise = null;
  1097.  
  1098. try {
  1099. promise = navigator.mediaCapabilities.decodingInfo({
  1100. type: "file",
  1101. video: {
  1102. contentType: "video/mp4; codecs=av01.0.05M.08.0.110.05.01.06.0",
  1103. height: 1080,
  1104. width: 1920,
  1105. framerate: 30,
  1106. bitrate: 2826848,
  1107. },
  1108. audio: {
  1109. contentType: "audio/webm; codecs=opus",
  1110. channels: "2.1",
  1111. samplerate: 44100,
  1112. bitrate: 255236,
  1113. }
  1114. });
  1115. } catch (e) {
  1116. promise = null;
  1117. }
  1118.  
  1119. const msgAV1NotSupported = 'Your browser does not support AV1. You might conside to use the latest version of Google Chrome or Mozilla FireFox.';
  1120.  
  1121. const callback = (result) => {
  1122. if (result && result.supported && result.smooth) enableAV1();
  1123. else {
  1124. console.warn("yt-codecs-hardware-acceleration-only", msgAV1NotSupported);
  1125. }
  1126. };
  1127.  
  1128. (promise || Promise.resolve(0)).catch(callback).then(callback);
  1129.  
  1130. supportedFormatsConfig();
  1131.  
  1132. })(Promise);