2

I was having the SharedArrayBuffer error as described in this other issue and to fix I added the cross origin isolation as suggested (also suggested here) by adding the headers

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

After that, now when I try to run the code I just got Uncaught ReferenceError: FFmpeg is not defined. The error is happening on Firefox

My code is:

<script  src="https://unpkg.com/@ffmpeg/ffmpeg@0.10.0/dist/ffmpeg.min.js"></script>
<script>
    
    const { createFFmpeg, fetchFile } = FFmpeg; //error happens here
    const ffmpegInstance = createFFmpeg({
        corePath: 'https://unpkg.com/@ffmpeg/core@0.10.0/dist/ffmpeg-core.js',
        log: true,
    });
 </script> 

Before that, on Brave browser the process ran ok without having to add the Cross origin headers and also FFmpeg variable was defined.

Fnr
  • 2,096
  • 7
  • 41
  • 76

1 Answers1

1

The reason is that for SharedArrayBuffer to work, the scripts using its functionality must opt-in via those headers as well.

Unfortunately, https://unpkg.com/ currently doesn't serve scripts with COOP/COEP headers.

To make your application work again, you'll have to either copy and self-host those sources from your own origin, or bundle them as part of your application.

RReverser
  • 1,940
  • 14
  • 15
  • That's strange because I still have status 200 after get request from unpkg... – Fnr Sep 14 '21 at 20:42
  • If i load the .js scripts locally then it fails with 404 error `GET http://127.0.0.1:3000/ffmpeg/ffmpeg-core.wasm` and `GEThttp://127.0.0.1:3000/ffmpeg/ffmpeg-core.worker.js`.. the scripts try to load the other resources locally... – Fnr Sep 14 '21 at 20:48
  • Well it fails with 404 only because you don't have those resources. Either download all of them manually, or, the easiest, use npm: `npm install @ffmpeg/ffmpeg @ffmpeg/core` (from https://github.com/ffmpegwasm/ffmpeg.wasm README). Then you'll have a copy with everything needed in `node_modules/@ffmpeg/...` which you can access from your script. – RReverser Sep 15 '21 at 11:56