4 Replies
Migrating away from web workers
The original ffmpeg.wasm used
web workers
but since CF workers can't create a web worker using new Worker(..)
I've created a single file with the logic from classes.ts and worker.ts
✅ This seems to work.
Error with emscripten build
But when I tried running my CF worker I get the error
not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)As I understand, this is an emscripten ENV related issue. My environment should be a
SERVICE WORKER
for it to support CF workers
And so I used claude to update my Dockerfile used to build ffmpeg wasm. I added the below code to Dockerfile
But resulting ffmpeg-core.js
still won't work
It did set the ENVIRONMENT to WORKER
But it fails here because self.location
is undefined
This is the error I see in my console
Failed to load FFmpeg: TypeError: Cannot read properties of undefined (reading 'href')Does anyone know how to build ffmpeg for CF Worker? Or building a project using emscripten for CF Worker?
I may try build a ffmpeg build for workers at some point next weak when i will have more time. But just looking very quickly on you code here i can point few things: MAXIMUM_MEMORY as 2Gb make no sense. Should be 128M; Claude like others AIs appears to just make some renames and references to cloudflare but not make any real customization to the actual environment.
When (if) i got to work i will let you know.
Awesome! Thank you very much
Hey @Wallacy
Where you able to give it a try?
(Making ffmepg work on a cf worker)
Unfortunately no... i didn't get time to do that. Anyway, the only thing that cross my mind whiout look at the script is: "self.location", should no be "globalThis.location"? Self will probably reference the function on this script, i dont know if is ES5/6 but anyway. The loader part is probably confusing a lot of refs. You may actually target nodejs and use CF worker node compat layer also.