Skip to content

🎥 Make videos programmatically with React

cool

JonnyBurger37cf68438d7b
diff --git a/packages/docs/docs/transitions/presentations/zoom-blur.mdx b/packages/docs/docs/transitions/presentations/zoom-blur.mdx
index 8c6b0d7ece..f0bd3cf791 100644
--- a/packages/docs/docs/transitions/presentations/zoom-blur.mdx
+++ b/packages/docs/docs/transitions/presentations/zoom-blur.mdx
@@ -11,7 +11,7 @@ A presentation where the outgoing scene zooms out and rotates while the incoming
<Demo type="zoom-blur" />
:::warning
-This presentation is built on top of the experimental [HTML-in-canvas](/docs/client-side-rendering/html-in-canvas) feature and currently requires [Chrome Canary](https://www.google.com/chrome/canary/) with `chrome://flags/#canvas-draw-element` enabled. It does not work in Firefox or Safari.
+This presentation is built with [HTML-in-canvas](/docs/remotion/html-in-canvas) and currently requires [Chrome Canary](https://www.google.com/chrome/canary/) with `chrome://flags/#canvas-draw-element` enabled. It does not work in Firefox or Safari.
:::
## Example
@@ -85,7 +85,7 @@ Defaults to `Math.PI / 6` (30°).
studio
/>
-Because this presentation relies on [HTML-in-canvas](/docs/client-side-rendering/html-in-canvas), it only runs in Chromium builds that ship the experimental `drawElementImage` and `canvas.requestPaint()` APIs. In a desktop browser or the Studio, this means [Chrome Canary](https://www.google.com/chrome/canary/) with the `chrome://flags/#canvas-draw-element` flag enabled. For server-side renders pass `--allow-html-in-canvas` (or [`Config.setAllowHtmlInCanvasEnabled(true)`](/docs/config#setallowhtmlincanvasenabled)); Remotion's bundled Chromium for Lambda already includes the required APIs, and locally you can point at a Chrome Canary executable.
+For Preview, Chrome Canary with the `chrome://flags/#canvas-draw-element` flag enabled is required.
## See also
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 68d5cefc8e..ca1ca33fb7 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -6411,6 +6411,15 @@ export const articles = [
noAi: false,
slug: 'transitions/presentations/wipe',
},
+ {
+ id: 'transitions/presentations/zoom-blur',
+ title: 'zoomBlur()',
+ relativePath: 'docs/transitions/presentations/zoom-blur.mdx',
+ compId: 'articles-docs-transitions-presentations-zoom-blur',
+ crumb: '@remotion/transitions - Presentations',
+ noAi: false,
+ slug: 'transitions/presentations/zoom-blur',
+ },
{
id: 'transitions/timings/custom',
title: 'Custom timings',
diff --git a/packages/docs/static/generated/articles-docs-ai-coding-agents.png b/packages/docs/static/generated/articles-docs-ai-coding-agents.png
new file mode 100644
index 0000000000..8c8dbe870e
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-ai-coding-agents.png differ
diff --git a/packages/example/src/HtmlInCanvas/index.tsx b/packages/example/src/HtmlInCanvas/index.tsx
index 5d011a7718..d11ca9ef40 100644
--- a/packages/example/src/HtmlInCanvas/index.tsx
+++ b/packages/example/src/HtmlInCanvas/index.tsx
@@ -13,4 +13,7 @@ export {
export {HtmlInCanvasPrivacy} from './privacy';
export {HtmlInCanvasReactSvg} from './react-svg';
export {HtmlInCanvasScene} from './scene';
-export {ZoomBlurTransitionDoc} from './zoom-blur-doc';
+export {
+ ZoomBlurTransitionDoc,
+ ZoomBlurTransitionDocThumb,
+} from './zoom-blur-doc';
diff --git a/packages/example/src/HtmlInCanvas/nested-webgl.tsx b/packages/example/src/HtmlInCanvas/nested-webgl.tsx
new file mode 100644
index 0000000000..9b626039dc
--- /dev/null
+++ b/packages/example/src/HtmlInCanvas/nested-webgl.tsx
@@ -0,0 +1,275 @@
+/**
+ * Nested `<HtmlInCanvas>` platform test: **inner = Canvas 2D**, **outer = WebGL**
+ *
+ * Use this to compare behavior with an inner WebGL pass. The 2D path uses
+ * `drawElementImage` with a 2D transform (rotate) plus a CSS filter for a
+ * clearly “2D-only” look.
+ */
+import React, {useCallback, useRef} from 'react';
+import {
+ HtmlInCanvas,
+ type HtmlInCanvasOnInit,
+ type HtmlInCanvasOnPaint,
+ interpolate,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+type GpuState = {
+ gl: WebGL2RenderingContext;
+ program: WebGLProgram;
+ uMatrix: WebGLUniformLocation | null;
+ uTex: WebGLUniformLocation | null;
+ texture: WebGLTexture;
+ vao: WebGLVertexArrayObject;
+ buffer: WebGLBuffer;
+};
+
+const VS = `#version 300 es
+in vec2 a_pos;
+in vec2 a_uv;
+uniform mat3 u_matrix;
+out vec2 v_uv;
+void main() {
+ vec3 p = u_matrix * vec3(a_pos, 1.0);
+ gl_Position = vec4(p.xy, 0.0, 1.0);
+ v_uv = a_uv;
+}`;
+
+const FS_VIGNETTE = `#version 300 es
+precision highp float;
+uniform sampler2D u_tex;
+in vec2 v_uv;
+out vec4 o;
+void main() {
+ vec2 p = v_uv * 2.0 - 1.0;
+ float edge = 1.0 - dot(p, p) * 0.45;
+ vec4 c = texture(u_tex, v_uv);
+ o = vec4(c.rgb * edge, c.a);
+}`;
+
+function compileGlsl(gl: WebGL2RenderingContext, vs: string, fs: string) {
+ const vert = gl.createShader(gl.VERTEX_SHADER)!;
+ gl.shaderSource(vert, vs);
+ gl.compileShader(vert);
+ const frag = gl.createShader(gl.FRAGMENT_SHADER)!;
+ gl.shaderSource(frag, fs);
+ gl.compileShader(frag);
+ const program = gl.createProgram()!;
+ gl.attachShader(program, vert);
+ gl.attachShader(program, frag);
+ gl.linkProgram(program);
+ gl.deleteShader(vert);
+ gl.deleteShader(frag);
+ return program;
+}
+
+const QUAD = new Float32Array([
+ -1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1,
+]);
+
+function initOuterGpu(
+ canvas: OffscreenCanvas,
+ fragmentSource: string,
+): {gpu: GpuState; cleanup: () => void} {
+ const gl = canvas.getContext('webgl2', {
+ alpha: true,
+ premultipliedAlpha: true,
+ antialias: false,
+ });
+ if (!gl) {
+ throw new Error('WebGL2 unavailable');
+ }
+
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
+
+ const program = compileGlsl(gl, VS, fragmentSource);
+ const uMatrix = gl.getUniformLocation(program, 'u_matrix');
+ const uTex = gl.getUniformLocation(program, 'u_tex');
+
+ const texture = gl.createTexture()!;
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+
+ const buffer = gl.createBuffer()!;
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+ gl.bufferData(gl.ARRAY_BUFFER, QUAD, gl.STATIC_DRAW);
+
+ const vao = gl.createVertexArray()!;
+ gl.bindVertexArray(vao);
+ const locPos = gl.getAttribLocation(program, 'a_pos');
+ const locUv = gl.getAttribLocation(program, 'a_uv');
+ gl.enableVertexAttribArray(locPos);
+ gl.vertexAttribPointer(locPos, 2, gl.FLOAT, false, 16, 0);
+ gl.enableVertexAttribArray(locUv);
+ gl.vertexAttribPointer(locUv, 2, gl.FLOAT, false, 16, 8);
+
+ const gpu: GpuState = {
+ gl,
+ program,
+ uMatrix,
+ uTex,
+ texture,
+ vao,
+ buffer,
+ };
+
+ return {
+ gpu,
+ cleanup: () => {
+ gl.deleteProgram(program);
+ gl.deleteTexture(texture);
+ gl.deleteVertexArray(vao);
+ gl.deleteBuffer(buffer);
+ },
+ };
+}
+
+export const HtmlInCanvasNestedWebGL: React.FC = () => {
+ const frame = useCurrentFrame();
+ const {width, height, durationInFrames} = useVideoConfig();
+ const outerGpuRef = useRef<GpuState | null>(null);
+
+ const innerW = Math.floor(width * 0.58);
+ const innerH = Math.floor(height * 0.58);
+ const left = Math.floor((width - innerW) / 2);
+ const top = Math.floor((height - innerH) / 2);
+
+ const rotation = interpolate(
+ frame,
+ [0, durationInFrames - 1],
+ [0, Math.PI * 2],
+ {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ },
+ );
+
+ const innerOnPaint: HtmlInCanvasOnPaint = useCallback(
+ ({canvas, element, elementImage}) => {
+ const ctx = canvas.getContext('2d');
+ if (!ctx) {
+ throw new Error(
+ 'Nested 2D test: failed to get 2d context on offscreen',
+ );
+ }
+
+ ctx.reset();
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // 2D-only extra: filter runs on the rasterized element image (after layout).
+ ctx.filter = 'saturate(1.6) contrast(1.08)';
+
+ ctx.save();
+ ctx.translate(canvas.width / 2, canvas.height / 2);
+ ctx.rotate(rotation);
+ ctx.translate(-canvas.width / 2, -canvas.height / 2);
+
+ const transform = ctx.drawElementImage(
+ elementImage,
+ 0,
+ 0,
+ canvas.width,
+ canvas.height,
+ );
+ element.style.transform = transform.toString();
+
+ ctx.restore();
+ ctx.filter = 'none';
+ },
+ [rotation],
+ );
+
+ const outerOnInit: HtmlInCanvasOnInit = useCallback(({canvas}) => {
+ const {gpu, cleanup} = initOuterGpu(canvas, FS_VIGNETTE);
+ outerGpuRef.current = gpu;
+ return () => {
+ cleanup();
+ outerGpuRef.current = null;
+ };
+ }, []);
+
+ const outerOnPaint: HtmlInCanvasOnPaint = useCallback(({elementImage}) => {
+ const gpu = outerGpuRef.current;
+ if (!gpu) {
+ return;
+ }
+
+ const {gl} = gpu;
+ gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
+ gl.useProgram(gpu.program);
+
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, gpu.texture);
+ gl.texElementImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ elementImage,
+ );
+
+ if (gpu.uTex) {
+ gl.uniform1i(gpu.uTex, 0);
+ }
+
+ const id = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
+ if (gpu.uMatrix) {
+ gl.uniformMatrix3fv(gpu.uMatrix, false, id);
+ }
+
+ gl.bindVertexArray(gpu.vao);
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
+ }, []);
+
+ return (
+ <HtmlInCanvas
+ width={width}
+ height={height}
+ onInit={outerOnInit}
+ onPaint={outerOnPaint}
+ >
+ <div
+ style={{
+ position: 'relative',
+ width,
+ height,
+ backgroundColor: '#151528',
+ }}
+ >
+ <HtmlInCanvas
+ width={innerW}
+ height={innerH}
+ onPaint={innerOnPaint}
+ style={{
+ position: 'absolute',
+ left,
+ top,
+ }}
+ >
+ <div
+ style={{
+ width: '100%',
+ height: '100%',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ color: 'white',
+ fontSize: Math.min(72, innerW / 10),
+ fontFamily: 'system-ui, sans-serif',
+ fontWeight: 600,
+ textAlign: 'center',
+ backgroundColor: '#2d2640',
+ }}
+ >
+ Inner 2D rotate + saturate / outer WebGL vignette
+ </div>
+ </HtmlInCanvas>
+ </div>
+ </HtmlInCanvas>
+ );
+};
diff --git a/packages/example/src/HtmlInCanvas/zoom-blur-doc.tsx b/packages/example/src/HtmlInCanvas/zoom-blur-doc.tsx
index 5f0d9e0d3e..11ffc45224 100644
--- a/packages/example/src/HtmlInCanvas/zoom-blur-doc.tsx
+++ b/packages/example/src/HtmlInCanvas/zoom-blur-doc.tsx
@@ -57,3 +57,22 @@ export const ZoomBlurTransitionDoc: React.FC = () => {
</AbsoluteFill>
);
};
+
+export const ZoomBlurTransitionDocThumb: React.FC = () => {
+ return (
+ <AbsoluteFill style={{containerType: 'size'}}>
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={30}>
+ <SceneA />
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={zoomBlur({})}
+ timing={linearTiming({durationInFrames: 30})}
+ />
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <SceneB />
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index cf3d2b5648..0e695b0d2c 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -57,6 +57,7 @@ import {
HtmlInCanvasPrivacy,
HtmlInCanvasReactSvg,
ZoomBlurTransitionDoc,
+ ZoomBlurTransitionDocThumb,
} from './HtmlInCanvas';
import {HugeImage} from './HugeImage';
import {HugePayload, hugePayloadSchema} from './HugePayload';
@@ -967,11 +968,11 @@ export const Index: React.FC = () => {
/>
<Composition
id="zoom-blur-transition-doc-thumb"
- component={ZoomBlurTransitionDoc}
+ component={ZoomBlurTransitionDocThumb}
fps={30}
height={280}
width={540}
- durationInFrames={90}
+ durationInFrames={60}
/>
<Composition
id="html-in-canvas-complex-text"