YouTube Codecs - Hardware Acceleration Only

Use codecs with hardware accleration supported for media playback on YouTube

当前为 2025-06-02 提交的版本,查看 最新版本

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