codec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // example: https://github.com/rgov/js-theora-decoder/blob/main/index.html
  2. // https://github.com/brion/ogv.js/releases, yarn add has no simd
  3. // dev: copy decoder files from node/ogv/dist/* to project dir
  4. // dist: .... to dist
  5. /*
  6. OGVDemuxerOggW: 'ogv-demuxer-ogg-wasm.js',
  7. OGVDemuxerWebMW: 'ogv-demuxer-webm-wasm.js',
  8. OGVDecoderAudioOpusW: 'ogv-decoder-audio-opus-wasm.js',
  9. OGVDecoderAudioVorbisW: 'ogv-decoder-audio-vorbis-wasm.js',
  10. OGVDecoderVideoTheoraW: 'ogv-decoder-video-theora-wasm.js',
  11. OGVDecoderVideoVP8W: 'ogv-decoder-video-vp8-wasm.js',
  12. OGVDecoderVideoVP8MTW: 'ogv-decoder-video-vp8-mt-wasm.js',
  13. OGVDecoderVideoVP9W: 'ogv-decoder-video-vp9-wasm.js',
  14. OGVDecoderVideoVP9SIMDW: 'ogv-decoder-video-vp9-simd-wasm.js',
  15. OGVDecoderVideoVP9MTW: 'ogv-decoder-video-vp9-mt-wasm.js',
  16. OGVDecoderVideoVP9SIMDMTW: 'ogv-decoder-video-vp9-simd-mt-wasm.js',
  17. OGVDecoderVideoAV1W: 'ogv-decoder-video-av1-wasm.js',
  18. OGVDecoderVideoAV1SIMDW: 'ogv-decoder-video-av1-simd-wasm.js',
  19. OGVDecoderVideoAV1MTW: 'ogv-decoder-video-av1-mt-wasm.js',
  20. OGVDecoderVideoAV1SIMDMTW: 'ogv-decoder-video-av1-simd-mt-wasm.js',
  21. */
  22. import { simd } from "wasm-feature-detect";
  23. export async function loadVp9(callback) {
  24. // Multithreading is used only if `options.threading` is true.
  25. // This requires browser support for the new `SharedArrayBuffer` and `Atomics` APIs,
  26. // currently available in Firefox and Chrome with experimental flags enabled.
  27. // 所有主流浏览器均默认于2018年1月5日禁用SharedArrayBuffer
  28. const isSIMD = await simd();
  29. console.log('isSIMD: ' + isSIMD);
  30. window.OGVLoader.loadClass(
  31. isSIMD ? "OGVDecoderVideoVP9SIMDW" : "OGVDecoderVideoVP9W",
  32. (videoCodecClass) => {
  33. window.videoCodecClass = videoCodecClass;
  34. videoCodecClass({ videoFormat: {} }).then((decoder) => {
  35. decoder.init(() => {
  36. callback(decoder);
  37. })
  38. })
  39. },
  40. { worker: true, threading: true }
  41. );
  42. }