Open source CapCut alternative.
TypeScript
build(site): compile ffmpeg 9.0.2 into the Cut worker
David Le40c190d21751
diff --git a/.github/workflows/deploy-cut-worker.yml b/.github/workflows/deploy-cut-worker.ymlindex 0ee2e9d6..5b4a1152 100644--- a/.github/workflows/deploy-cut-worker.yml+++ b/.github/workflows/deploy-cut-worker.yml@@ -62,15 +62,29 @@ jobs:- name: Bundle workerrun: npm run worker:build+ # The image's layers persist in the Actions cache, so the ffmpeg compile+ # runs only when ffmpeg-release or the build stage changes. This builder+ # is the default, so wrangler's build below reads the same layers.+ - uses: docker/setup-buildx-action@v4++ - name: Build the worker image+ uses: docker/build-push-action@v7+ with:+ context: site+ file: site/src/cut/worker/Dockerfile+ tags: cut-worker+ load: true+ cache-from: type=gha+ cache-to: type=gha,mode=max+# Render the export test project through the same runExport the container- # runs (site/src/cut/server/exportPipeline.e2e.test.ts), against a Linux- # GPL ffmpeg like the image's Debian build. A graph the container's- # ffmpeg family rejects fails the deploy here.+ # runs (site/src/cut/server/exportPipeline.e2e.test.ts), inside the image+ # itself, so a graph the shipped ffmpeg rejects fails the deploy here.- name: Render the export test projectrun: |- sudo apt-get update -qq- sudo apt-get install -y -qq ffmpeg- bun test src/cut/server/exportPipeline.e2e.test.ts+ docker run --rm --entrypoint bun -v "$PWD:/site" -w /site \+ -v "$(readlink -f "$(command -v bun)"):/usr/local/bin/bun:ro" \+ cut-worker test src/cut/server/exportPipeline.e2e.test.ts- name: Deploy to Cloudflareuses: cloudflare/wrangler-action@v4diff --git a/site/src/cut/worker/Dockerfile b/site/src/cut/worker/Dockerfileindex 98b52ced..2cbb5326 100644--- a/site/src/cut/worker/Dockerfile+++ b/site/src/cut/worker/Dockerfile@@ -2,15 +2,35 @@# then build this image from site/:# docker build -f src/cut/worker/Dockerfile -t donkey-cut-worker .#-# The Debian release picks the ffmpeg, so it is part of the contract: the-# export's final pass passes -display_rotation, which ffmpeg gained in 6.0.-# Bookworm's 5.1 encodes the entire file and then dies on that last command, at-# 98% progress, with "Unrecognized option". Trixie carries 7.1.+# ffmpeg is built from the ffmpeg.org tarball that ffmpeg-release names and+# checksums, the file the Mac app's bundle reads too, so both render one+# release. GPL here: x264 and x265 are the worker's only encoders.+FROM node:24-trixie-slim AS ffmpeg+COPY src/cut/worker/ffmpeg-release /tmp/ffmpeg-release+RUN . /tmp/ffmpeg-release \+ && apt-get update \+ && apt-get install -y --no-install-recommends build-essential pkg-config nasm curl ca-certificates xz-utils \+ libx264-dev libx265-dev libvpx-dev libmp3lame-dev libopus-dev libdav1d-dev libass-dev libgnutls28-dev zlib1g-dev \+ && curl -fsSL -o /tmp/ffmpeg.tar.xz "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" \+ && echo "${FFMPEG_SHA256} /tmp/ffmpeg.tar.xz" | sha256sum -c - \+ && mkdir /tmp/ffmpeg && tar -xJf /tmp/ffmpeg.tar.xz -C /tmp/ffmpeg --strip-components=1 \+ && cd /tmp/ffmpeg \+ && ./configure --prefix=/opt/ffmpeg --enable-gpl --disable-doc --disable-static --enable-shared \+ --enable-libx264 --enable-libx265 --enable-libvpx --enable-libmp3lame --enable-libopus --enable-libdav1d \+ --enable-libass --enable-gnutls --extra-ldflags="-Wl,-rpath,/opt/ffmpeg/lib" \+ && make -j"$(nproc)" \+ && make install+FROM node:24-trixie-slim-# ffmpeg/ffprobe for the render pipeline; python3 runs the yt-dlp zipapp.-RUN apt-get update \- && apt-get install -y --no-install-recommends ffmpeg python3 ca-certificates curl \+# ffmpeg/ffprobe for the render pipeline, with the runtime halves of the+# libraries it was built against; python3 runs the yt-dlp zipapp, and+# libasound2t64 is the ALSA library node-web-audio-api links.+COPY --from=ffmpeg /opt/ffmpeg /opt/ffmpeg+RUN ln -s /opt/ffmpeg/bin/ffmpeg /opt/ffmpeg/bin/ffprobe /usr/local/bin/ \+ && apt-get update \+ && apt-get install -y --no-install-recommends python3 ca-certificates curl \+ libx264-164 libx265-215 libvpx9 libmp3lame0 libopus0 libdav1d7 libass9 libgnutls30t64 zlib1g libasound2t64 \&& curl -fsSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp \-o /usr/local/bin/yt-dlp \&& chmod +x /usr/local/bin/yt-dlp \@@ -18,8 +38,8 @@ RUN apt-get update \&& apt-get autoremove -y \&& rm -rf /var/lib/apt/lists/*-# Hold the image to what the pipeline actually calls. A base bump that walks-# ffmpeg backwards fails here instead of at 98% of someone's export.+# Hold the image to what the pipeline actually calls. A build that walks+# ffmpeg backwards fails here, at image build, before it reaches an export.RUN ffmpeg -hide_banner -h full 2>&1 | grep -q -- '-display_rotation' \|| { echo "ffmpeg is too old: the export re-mux needs -display_rotation (6.0+)." >&2; exit 1; }@@ -60,6 +80,9 @@ RUN npm install --no-package-lock --omit=dev \mediabunny@^1.51.0 \@mediabunny/server@^1.54.0 \node-web-audio-api@^2.2.0+# A headless job installs all three at once, so a native library missing from+# the image fails the build here.+RUN node -e "Promise.all([import('@mediabunny/server'), import('skia-canvas'), import('node-web-audio-api')]).catch((e) => { console.error(e.message); process.exit(1); })"COPY dist/cut-worker/main.js ./main.js# The faces the editor shows, staged as files the canvas loads at startup so a# title renders in its own font. npm install stages them from the @fontsourcediff --git a/site/src/cut/worker/ffmpeg-release b/site/src/cut/worker/ffmpeg-releasenew file mode 100644index 00000000..ae0b4bb4--- /dev/null+++ b/site/src/cut/worker/ffmpeg-release@@ -0,0 +1,5 @@+# The ffmpeg release the Mac app's bundle (scripts/fetch-bundled-tools.sh) and+# the cloud worker's image (Dockerfile here) both build, and the sha256 of its+# ffmpeg.org tarball. Both read this file, so they build one release.+FFMPEG_VERSION=9.0.2+FFMPEG_SHA256=8c3850283eb25fa026482078a04051e0be17347b09ef81a0849bec15a96e002e