cj
cj
CDCloudflare Developers
Created by cj on 10/7/2024 in #workers-help
I'm trying to build ffmpeg.wasm for CF worker. Need help
(Making ffmepg work on a cf worker)
10 replies
CDCloudflare Developers
Created by cj on 10/7/2024 in #workers-help
I'm trying to build ffmpeg.wasm for CF worker. Need help
Hey @Wallacy Where you able to give it a try?
10 replies
CDCloudflare Developers
Created by cj on 10/7/2024 in #workers-help
I'm trying to build ffmpeg.wasm for CF worker. Need help
Awesome! Thank you very much
10 replies
CDCloudflare Developers
Created by cj on 10/7/2024 in #workers-help
I'm trying to build ffmpeg.wasm for CF worker. Need help
It did set the ENVIRONMENT to WORKER
var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = true;
var ENVIRONMENT_IS_NODE = false;
var ENVIRONMENT_IS_SHELL = false;
var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = true;
var ENVIRONMENT_IS_NODE = false;
var ENVIRONMENT_IS_SHELL = false;
But it fails here because self.location is undefined
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
scriptDirectory = self.location.href;
}
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
scriptDirectory = self.location.href;
}
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?
10 replies
CDCloudflare Developers
Created by cj on 10/7/2024 in #workers-help
I'm trying to build ffmpeg.wasm for CF worker. Need help
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
# Build ffmpeg.wasm for Cloudflare Workers
FROM ffmpeg-builder AS ffmpeg-wasm-cloudflare-builder
COPY src/bind /src/src/bind
COPY src/fftools /src/src/fftools
COPY build/ffmpeg-wasm.sh build.sh
# libraries to link
ENV FFMPEG_LIBS \
-lx264 \
-lx265 \
-lvpx \
-lmp3lame \
-logg \
-ltheora \
-lvorbis \
-lvorbisenc \
-lvorbisfile \
-lopus \
-lz \
-lwebpmux \
-lwebp \
-lsharpyuv \
-lfreetype \
-lfribidi \
-lharfbuzz \
-lass \
-lzimg

# Build for Cloudflare Workers
RUN mkdir -p /src/dist/cloudflare && bash -x /src/build.sh \
${FFMPEG_LIBS} \
-s ENVIRONMENT=worker \
-s EXPORTED_RUNTIME_METHODS=['cwrap','setValue','getValue'] \
-s EXPORT_NAME=FFmpeg \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s USE_ES6_IMPORT_META=0 \
-s MALLOC=emmalloc \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=16777216 \
-s MAXIMUM_MEMORY=2147483648 \
-s WASM_BIGINT=1 \
-s ASSERTIONS=0 \
-s EXIT_RUNTIME=0 \
-s FILESYSTEM=0 \
-s EXPORTED_FUNCTIONS=['_malloc','_free'] \
-o dist/cloudflare/ffmpeg-core.js
# Build ffmpeg.wasm for Cloudflare Workers
FROM ffmpeg-builder AS ffmpeg-wasm-cloudflare-builder
COPY src/bind /src/src/bind
COPY src/fftools /src/src/fftools
COPY build/ffmpeg-wasm.sh build.sh
# libraries to link
ENV FFMPEG_LIBS \
-lx264 \
-lx265 \
-lvpx \
-lmp3lame \
-logg \
-ltheora \
-lvorbis \
-lvorbisenc \
-lvorbisfile \
-lopus \
-lz \
-lwebpmux \
-lwebp \
-lsharpyuv \
-lfreetype \
-lfribidi \
-lharfbuzz \
-lass \
-lzimg

# Build for Cloudflare Workers
RUN mkdir -p /src/dist/cloudflare && bash -x /src/build.sh \
${FFMPEG_LIBS} \
-s ENVIRONMENT=worker \
-s EXPORTED_RUNTIME_METHODS=['cwrap','setValue','getValue'] \
-s EXPORT_NAME=FFmpeg \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s USE_ES6_IMPORT_META=0 \
-s MALLOC=emmalloc \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=16777216 \
-s MAXIMUM_MEMORY=2147483648 \
-s WASM_BIGINT=1 \
-s ASSERTIONS=0 \
-s EXIT_RUNTIME=0 \
-s FILESYSTEM=0 \
-s EXPORTED_FUNCTIONS=['_malloc','_free'] \
-o dist/cloudflare/ffmpeg-core.js
But resulting ffmpeg-core.js still won't work
10 replies
CDCloudflare Developers
Created by cj on 10/7/2024 in #workers-help
I'm trying to build ffmpeg.wasm for CF worker. Need help
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.
10 replies
CDCloudflare Developers
Created by Rishabh on 6/6/2024 in #pages-help
Build Failed: build exceeded memory limit and was terminated
You can use CI/CD to build the app and deploy it. This way the deploy is automated
6 replies
CDCloudflare Developers
Created by Rishabh on 6/6/2024 in #pages-help
Build Failed: build exceeded memory limit and was terminated
You can try deploying from your terminal using wrangler pages deploy
6 replies
CDCloudflare Developers
Created by cj on 6/5/2024 in #workers-help
Should `unsafe.bindings.ratelimit` have different `namespace_id` for each worker environment?
Ty. This is much better
3 replies
CDCloudflare Developers
Created by cj on 6/5/2024 in #workers-help
Should `unsafe.bindings.ratelimit` have different `namespace_id` for each worker environment?
I fixed it
[env.dev.unsafe]
bindings = [
{name = "RATE_LIMITER", type = "ratelimit", namespace_id = "1002", simple = { limit = 30, period = 60 }}
]
[env.dev.unsafe]
bindings = [
{name = "RATE_LIMITER", type = "ratelimit", namespace_id = "1002", simple = { limit = 30, period = 60 }}
]
3 replies
CDCloudflare Developers
Created by cj on 6/4/2024 in #workers-help
Impossible to add a new ENV Variable if using unstable.bindings.RATE_LIMITER
Ty
4 replies