ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

Export ffmpeg-core.worker.js for core package

Open higgins opened this issue 7 months ago • 2 comments

In order to run the single threaded worker, we need to either serve the built worker.js file and its dependencies on the domain where the worker will be instantiated OR blobify (via toBlobURL()) a compiled worker asset.

The core-mt package makes this possible via:

const baseURL = 'https://unpkg.com/@ffmpeg/[email protected]/dist/esm'  
ffmpeg = new FFmpeg();
const [coreURL, wasmURL, workerURL] = await Promise.all([
  toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'),
  toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'),
  toBlobURL(`${baseURL}/ffmpeg-core.worker.js`, 'text/javascript'),
]);
await ffmpeg.load({ coreURL, wasmURL, workerURL, classWorkerURL: workerURL });

but since the core package does not produce this ffmpeg-core.worker.js artifact, we have to create our own (basically a concatenation of worker.js + const.js + errors.js -> ffmpeg-core.worker.js)

Describe the solution you'd like Like you're already doing with the core-mt package, create and publish a ffmpeg-core.worker.js artifact for the single threaded core package.

Describe alternatives you've considered

  1. We're not ready to try the multithreaded solution
  2. The workaround noted here about hosting the worker.js, const.js and errors.js files on the our domain is error prone

Additional context We think this is a reasonable alternative to perhaps bigger refactors proposed elsewhere: https://github.com/ffmpegwasm/ffmpeg.wasm/issues/617

Thank you for this great library and for your time and attention!

higgins avatar Jul 19 '24 20:07 higgins