Problem
As mentioned in #594,#560,#548,there a lot issues about woker.js,I also encountered the same problem when developing chrome extension,and finally find the solution.
Now there are two ways to use @ffmpeg/ffmpeg:
umd
We could load ffmpeg via cdn like https://cdn.jsdelivr.net/npm/@ffmpeg/ffmpeg@0.12.7/dist/umd/ffmpeg.min.js. But it will report an error like #560 (comment) when we execute ffmpeg.load()。
The reason is that Webpack will build the new Worker(xxx) into a seperate file,so there will be two file in umd,see here:
- ffmpeg.js
- 814.ffmpeg.js ( worker.js)
When we load ffmpeg.js, it will load 814.ffmpeg.js , but in a wrong path.
esm
In esm module, new Worker('./worker.js') will remain in production mode. Due to different bundling tools presenting this relative path differently, it can sometimes lead to worker.js is not found.
Solution
My proposed solution is to bundle worker.js as inline code, eliminating the need to worry about the path to worker.js.
There are two potential solutions:
- Use Vite for code bundling, like this:
- Use Webpack for bundling using the asset/inline. However, the ESM code generated by
Webpack may appear less elegant.
If necessary, I can submit a PR.
Problem
As mentioned in #594,#560,#548,there a lot issues about woker.js,I also encountered the same problem when developing chrome extension,and finally find the solution.
Now there are two ways to use
@ffmpeg/ffmpeg:umd
We could load
ffmpegvia cdn like https://cdn.jsdelivr.net/npm/@ffmpeg/ffmpeg@0.12.7/dist/umd/ffmpeg.min.js. But it will report an error like #560 (comment) when we executeffmpeg.load()。The reason is that Webpack will build the
new Worker(xxx)into a seperate file,so there will be two file in umd,see here:When we load
ffmpeg.js, it will load814.ffmpeg.js, but in a wrong path.esm
In esm module,
new Worker('./worker.js')will remain in production mode. Due to different bundling tools presenting this relative path differently, it can sometimes lead toworker.js is not found.Solution
My proposed solution is to bundle worker.js as inline code, eliminating the need to worry about the path to worker.js.
There are two potential solutions:
Webpackmay appear less elegant.If necessary, I can submit a PR.