🎥 Make videos programmatically with React
better browser tests
Jonny Burger88d606045bb7
diff --git a/packages/dockerfiles/.gitignore b/packages/dockerfiles/.gitignoreindex 8c022c039c..995923cba8 100644--- a/packages/dockerfiles/.gitignore+++ b/packages/dockerfiles/.gitignore@@ -1 +1,5 @@ensure-browser.mjs+bundle/+out/++bundle\ No newline at end of filediff --git a/packages/dockerfiles/Dockerfile.al2023 b/packages/dockerfiles/Dockerfile.al2023index 06c8892f45..3b0162d07c 100644--- a/packages/dockerfiles/Dockerfile.al2023+++ b/packages/dockerfiles/Dockerfile.al2023@@ -2,22 +2,20 @@ FROM amazonlinux:2023WORKDIR /usr/appRUN yum install git -y-RUN git clone https://github.com/remotion-dev/template-helloworld /usr/app-RUN cd /usr/appRUN yum install nodejs -y-RUN npm i+RUN npm i -g @remotion/cliRUN yum install -y \mesa-libgbm \libX11 \- libXrandr \- libdrm \- libXdamage \- libXfixes \+ libXrandr \+ libdrm \+ libXdamage \+ libXfixes \libxkbcommon \- dbus-libs \- libXcomposite \- alsa-lib \- nss \+ dbus-libs \+ libXcomposite \+ alsa-lib \+ nss \dbus \pango \cups-libs \@@ -27,4 +25,9 @@ RUN yum install -y \COPY ensure-browser.mjs .COPY ensure.mjs .RUN node ensure.mjs-RUN npx remotion compositions++# Copy the pre-built bundle+COPY bundle/ /usr/app/bundle/++RUN npx remotion compositions /usr/app/bundle+RUN npx remotion render /usr/app/bundle browser-test /usr/app/out.mp4diff --git a/packages/dockerfiles/Dockerfile.debian b/packages/dockerfiles/Dockerfile.debianindex b3697e5d80..cd81486259 100644--- a/packages/dockerfiles/Dockerfile.debian+++ b/packages/dockerfiles/Dockerfile.debian@@ -20,12 +20,14 @@ RUN apt install -y \libcups2 \libcairo2-RUN git clone https://github.com/remotion-dev/template-helloworld /usr/app-RUN cd /usr/app+RUN npm i -g @remotion/cliCOPY ensure-browser.mjs .COPY ensure.mjs .RUN node ensure.mjs-RUN npm i-RUN npx remotion compositions+# Copy the pre-built bundle+COPY bundle/ /usr/app/bundle/++RUN npx remotion compositions /usr/app/bundle+RUN npx remotion render /usr/app/bundle browser-test /usr/app/out.mp4diff --git a/packages/dockerfiles/Dockerfile.nix b/packages/dockerfiles/Dockerfile.nixindex ece1c48ed3..24410aeb42 100644--- a/packages/dockerfiles/Dockerfile.nix+++ b/packages/dockerfiles/Dockerfile.nix@@ -1,4 +1,4 @@-# TODO: Cannot execute `npx remotion render HelloWorld --browser-executable=$(which chromium)` yet, because it misses libstdc++.so.6+# TODO: Cannot execute `npx remotion render HelloWorld --browser-executable=$(which chromium)` yet, because it misses libstdc++.so.6FROM nixos/nixRUN mkdir -p /etc/profile.d@@ -6,19 +6,20 @@ RUN echo 'set -eux; nix-channel --update' > /etc/profile.d/nix.shWORKDIR /usr/app-RUN git clone https://github.com/remotion-dev/template-helloworld /usr/app-RUN cd /usr/app--RUN nix-env -iA nixpkgs.nodejs-18_xRUN nix-env -iA nixpkgs.ungoogled-chromium-RUN npm i+RUN npm i -g @remotion/cliCOPY remotion.nix .-RUN chmod +x /usr/app/node_modules/@remotion/compositor-linux-arm64-gnu/remotion-RUN nix run nixpkgs#patchelf --extra-experimental-features nix-command --extra-experimental-features flakes -- --set-interpreter "$(nix eval nixpkgs#stdenv.cc.bintools.dynamicLinker --raw --extra-experimental-features nix-command --extra-experimental-features flakes)" /usr/app/node_modules/@remotion/compositor-linux-arm64-gnu/remotion-RUN nix run nixpkgs#patchelf --extra-experimental-features nix-command --extra-experimental-features flakes -- --set-interpreter "$(nix eval nixpkgs#stdenv.cc.bintools.dynamicLinker --raw --extra-experimental-features nix-command --extra-experimental-features flakes)" /usr/app/node_modules/@remotion/compositor-linux-arm64-gnu/ffmpeg-RUN nix run nixpkgs#patchelf --extra-experimental-features nix-command --extra-experimental-features flakes -- --set-interpreter "$(nix eval nixpkgs#stdenv.cc.bintools.dynamicLinker --raw --extra-experimental-features nix-command --extra-experimental-features flakes)" /usr/app/node_modules/@remotion/compositor-linux-arm64-gnu/ffprobe-RUN npx remotion render HelloWorld --browser-executable=$(which chromium)+# Copy the pre-built bundle+COPY bundle/ /usr/app/bundle/++RUN chmod +x /root/.npm/_npx/*/node_modules/@remotion/compositor-linux-arm64-gnu/remotion || true+RUN nix run nixpkgs#patchelf --extra-experimental-features nix-command --extra-experimental-features flakes -- --set-interpreter "$(nix eval nixpkgs#stdenv.cc.bintools.dynamicLinker --raw --extra-experimental-features nix-command --extra-experimental-features flakes)" /root/.npm/_npx/*/node_modules/@remotion/compositor-linux-arm64-gnu/remotion || true+RUN nix run nixpkgs#patchelf --extra-experimental-features nix-command --extra-experimental-features flakes -- --set-interpreter "$(nix eval nixpkgs#stdenv.cc.bintools.dynamicLinker --raw --extra-experimental-features nix-command --extra-experimental-features flakes)" /root/.npm/_npx/*/node_modules/@remotion/compositor-linux-arm64-gnu/ffmpeg || true+RUN nix run nixpkgs#patchelf --extra-experimental-features nix-command --extra-experimental-features flakes -- --set-interpreter "$(nix eval nixpkgs#stdenv.cc.bintools.dynamicLinker --raw --extra-experimental-features nix-command --extra-experimental-features flakes)" /root/.npm/_npx/*/node_modules/@remotion/compositor-linux-arm64-gnu/ffprobe || true++RUN npx remotion compositions /usr/app/bundle --browser-executable=$(which chromium)+RUN npx remotion render /usr/app/bundle browser-test --browser-executable=$(which chromium) /usr/app/out.mp4diff --git a/packages/dockerfiles/Dockerfile.ubuntu22 b/packages/dockerfiles/Dockerfile.ubuntu22index 669bebce45..477b60713b 100644--- a/packages/dockerfiles/Dockerfile.ubuntu22+++ b/packages/dockerfiles/Dockerfile.ubuntu22@@ -4,9 +4,7 @@ RUN apt-get updateRUN apt-get install git curl make -yRUN curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s 20WORKDIR /usr/app-RUN git clone https://github.com/remotion-dev/template-helloworld /usr/app-RUN cd /usr/app-RUN npm i+RUN npm i -g @remotion/cliRUN apt install -y \libnss3 \libdbus-1-3 \@@ -27,4 +25,8 @@ COPY ensure-browser.mjs .COPY ensure.mjs .RUN node ensure.mjs-RUN npx remotion compositions+# Copy the pre-built bundle+COPY bundle/ /usr/app/bundle/++RUN npx remotion compositions /usr/app/bundle+RUN npx remotion render /usr/app/bundle browser-test /usr/app/out.mp4 --log=verbose\ No newline at end of filediff --git a/packages/dockerfiles/Dockerfile.ubuntu24 b/packages/dockerfiles/Dockerfile.ubuntu24index 948ceb88de..eeff1822c0 100644--- a/packages/dockerfiles/Dockerfile.ubuntu24+++ b/packages/dockerfiles/Dockerfile.ubuntu24@@ -4,9 +4,7 @@ RUN apt-get updateRUN apt-get install git curl make -yRUN curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s 20WORKDIR /usr/app-RUN git clone https://github.com/remotion-dev/template-helloworld /usr/app-RUN cd /usr/app-RUN npm i+RUN npm i -g @remotion/cliRUN apt install -y \libnss3 \libdbus-1-3 \@@ -27,4 +25,8 @@ COPY ensure-browser.mjs .COPY ensure.mjs .RUN node ensure.mjs-RUN npx remotion compositions+# Copy the pre-built bundle+COPY bundle/ /usr/app/bundle/++RUN npx remotion compositions /usr/app/bundle+RUN npx remotion render /usr/app/bundle browser-test /usr/app/out.mp4 --log=verbosediff --git a/packages/dockerfiles/README.md b/packages/dockerfiles/README.mdindex 120b50a489..94e4fe7bd1 100644--- a/packages/dockerfiles/README.md+++ b/packages/dockerfiles/README.md@@ -1,3 +1,30 @@Sample Dockerfiles for different operating systems that show how to install Remotion including the browser.Uses `npx remotion browser ensure` to install the browser, which requires some shared libraries.++## Running the tests++```bash+./run.sh+```++This will:+1. Build the browser-test bundle from `packages/example` (using `src/browser-test-entry.ts`)+2. Build Docker images for each platform (ubuntu24, ubuntu22, debian, nix)+3. Each Docker build runs `npx remotion compositions` and `npx remotion render`+4. Extract the rendered videos to `out/` directory++Output videos:+- `out/ubuntu24.mp4`+- `out/ubuntu22.mp4`+- `out/debian.mp4`+- `out/nix.mp4`++## browser-test composition++Located in `packages/example/src/BrowserTest/index.tsx`, it tests:+- GPU/WebGL rendering (Three.js)+- Video playback with different codecs (H.264, H.265)+- WebGL availability++The bundle is built from `packages/example` and copied into each Docker container during build.diff --git a/packages/dockerfiles/run.sh b/packages/dockerfiles/run.shindex edc5123540..824ac4838c 100644--- a/packages/dockerfiles/run.sh+++ b/packages/dockerfiles/run.sh@@ -3,8 +3,40 @@ cd ../rendererbun build-browser-downloader.tscp ensure-browser.mjs ../dockerfiles/ensure-browser.mjscd ../dockerfiles-docker build --file Dockerfile.al2023 . --output type=tar,dest=/dev/null --progress=plain-docker build --file Dockerfile.ubuntu24 . --output type=tar,dest=/dev/null --progress=plain-docker build --file Dockerfile.ubuntu22 . --output type=tar,dest=/dev/null --progress=plain-docker build --file Dockerfile.debian . --output type=tar,dest=/dev/null --progress=plain-docker build --file Dockerfile.nix . --output type=tar,dest=/dev/null --progress=plain++# Build the browser-test bundle from packages/example+echo "Building browser-test bundle..."+cd ../example+bunx remotion bundle src/browser-test-entry.ts --out-dir ../dockerfiles/bundle+cd ../dockerfiles++echo "Bundle created at packages/dockerfiles/bundle"++# Create output directory for videos+mkdir -p out++# Function to build and extract video+build_and_extract() {+ local dockerfile=$1+ local tag=$2+ local output_name=$3++ echo "Building $tag..."+ docker build --file $dockerfile -t $tag .++ echo "Extracting video from $tag..."+ container_id=$(docker create $tag)+ docker cp $container_id:/usr/app/out.mp4 ./out/$output_name+ docker rm $container_id+ echo "Video saved to out/$output_name"+}++# build_and_extract Dockerfile.al2023 remotion-al2023 al2023.mp4+build_and_extract Dockerfile.ubuntu24 remotion-ubuntu24 ubuntu24.mp4+build_and_extract Dockerfile.ubuntu22 remotion-ubuntu22 ubuntu22.mp4+build_and_extract Dockerfile.debian remotion-debian debian.mp4+# build_and_extract Dockerfile.nix remotion-nix nix.mp4++echo ""+echo "All videos extracted to packages/dockerfiles/out/"+ls -la out/diff --git a/packages/example/src/BrowserTest/index.tsx b/packages/example/src/BrowserTest/index.tsxindex 275f2dbdd0..e337d06aac 100644--- a/packages/example/src/BrowserTest/index.tsx+++ b/packages/example/src/BrowserTest/index.tsx@@ -236,24 +236,93 @@ const WebGLCheck: React.FC = () => {);};+const SystemFontCheck: React.FC = () => {+ const frame = useCurrentFrame();+ const opacity = Math.min(1, frame / 30);++ return (+ <AbsoluteFill+ style={{+ backgroundColor: 'white',+ justifyContent: 'center',+ alignItems: 'center',+ padding: 40,+ }}+ >+ <div+ style={{+ display: 'flex',+ flexDirection: 'column',+ alignItems: 'center',+ gap: 30,+ opacity,+ }}+ >+ <h1+ style={{+ fontFamily: 'sans-serif',+ fontSize: 120,+ color: 'black',+ fontWeight: 'bold',+ margin: 0,+ }}+ >+ System Font Test+ </h1>+ <p+ style={{+ fontFamily: 'serif',+ fontSize: 60,+ color: 'black',+ margin: 0,+ }}+ >+ Serif: The quick brown fox+ </p>+ <p+ style={{+ fontFamily: 'sans-serif',+ fontSize: 60,+ color: 'black',+ margin: 0,+ }}+ >+ Sans-serif: jumps over the lazy dog+ </p>+ <p+ style={{+ fontFamily: 'monospace',+ fontSize: 48,+ color: 'black',+ margin: 0,+ }}+ >+ Monospace: 0123456789 !@#$%+ </p>+ </div>+ </AbsoluteFill>+ );+};+const FPS = 30;const DURATION_IN_FRAMES = 2 * 60 * FPS; // 2 minutes-const GPU_SCENE_DURATION = Math.floor(DURATION_IN_FRAMES / 3);-const MEDIA_DURATION = Math.floor(DURATION_IN_FRAMES / 3);-const WEBGL_DURATION = DURATION_IN_FRAMES - GPU_SCENE_DURATION - MEDIA_DURATION;+const SCENE_DURATION = Math.floor(DURATION_IN_FRAMES / 4);export const BrowserTest: React.FC = () => {return (<AbsoluteFill>- <Sequence durationInFrames={GPU_SCENE_DURATION}>+ <Sequence durationInFrames={SCENE_DURATION}>+ <SystemFontCheck />+ </Sequence>+ <Sequence from={SCENE_DURATION} durationInFrames={SCENE_DURATION}><GpuScene /></Sequence>- <Sequence from={GPU_SCENE_DURATION} durationInFrames={MEDIA_DURATION}>+ <Sequence from={SCENE_DURATION * 2} durationInFrames={SCENE_DURATION}><MediaVideos /></Sequence><Sequence- from={GPU_SCENE_DURATION + MEDIA_DURATION}- durationInFrames={WEBGL_DURATION}+ from={SCENE_DURATION * 3}+ durationInFrames={DURATION_IN_FRAMES - SCENE_DURATION * 3}><WebGLCheck /></Sequence>diff --git a/packages/example/src/BrowserTestRoot.tsx b/packages/example/src/BrowserTestRoot.tsxnew file mode 100644index 0000000000..cc101a6768--- /dev/null+++ b/packages/example/src/BrowserTestRoot.tsx@@ -0,0 +1,16 @@+import React from 'react';+import {Composition} from 'remotion';+import {BrowserTest} from './BrowserTest';++export const BrowserTestRoot: React.FC = () => {+ return (+ <Composition+ id="browser-test"+ component={BrowserTest}+ width={1280}+ height={720}+ fps={30}+ durationInFrames={2 * 60 * 30}+ />+ );+};diff --git a/packages/example/src/browser-test-entry.ts b/packages/example/src/browser-test-entry.tsnew file mode 100644index 0000000000..9e154fbf5d--- /dev/null+++ b/packages/example/src/browser-test-entry.ts@@ -0,0 +1,4 @@+import {registerRoot} from 'remotion';+import {BrowserTestRoot} from './BrowserTestRoot';++registerRoot(BrowserTestRoot);diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsxindex 09e2fde0a5..2645703f10 100644--- a/packages/media/src/video/video-for-rendering.tsx+++ b/packages/media/src/video/video-for-rendering.tsx@@ -149,10 +149,13 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({const timestamp = frame / fps;const durationInSeconds = 1 / fps;- const newHandle = delayRender(`Extracting frame at time ${timestamp}`, {- retries: delayRenderRetries ?? undefined,- timeoutInMilliseconds: delayRenderTimeoutInMilliseconds ?? undefined,- });+ const newHandle = delayRender(+ `Extracting frame at time ${timestamp} from ${src}`,+ {+ retries: delayRenderRetries ?? undefined,+ timeoutInMilliseconds: delayRenderTimeoutInMilliseconds ?? undefined,+ },+ );const shouldRenderAudio = (() => {if (!audioEnabled) {