🎥 Make videos programmatically with React
update
JonnyBurger8f25d172f12b
diff --git a/packages/docs/docs/canvas-effects/blur.mdx b/packages/docs/docs/canvas-effects/blur.mdxdeleted file mode 100644index 31396b0a35..0000000000--- a/packages/docs/docs/canvas-effects/blur.mdx+++ /dev/null@@ -1,39 +0,0 @@-----image: /generated/articles-docs-canvas-effects-blur.png-title: blur()-crumb: '@remotion/canvas-effects'------# blur()<AvailableFrom v="4.0.452" />--A WebGL2 [canvas effect](/docs/canvas-effects) that applies a separable Gaussian blur to the source. Returns a tuple of `[horizontal, vertical]` passes; the chain runtime flattens the array automatically.--```tsx twoslash title="src/BlurDemo.tsx"-import {blur} from '@remotion/canvas-effects';-import {Solid} from 'remotion';--export const BlurDemo = () => (- <Solid color="hotpink" width={1920} height={1080} effects={[blur({radius: 24})]} />-);-```--The blur uses a 9-tap Gaussian kernel. Sample stride scales with `radius` so the kernel always spans approximately ±`radius` pixels; sigma is set to `radius / 3`.--## Parameters--### radius--Blur radius in pixels. Higher values produce a softer image. The same radius is used for both passes.--## Single-axis variants--If you only need a one-dimensional blur, the individual passes are exported separately:--- `blurHorizontal({radius})`-- `blurVertical({radius})`--## See also--- [Canvas effects overview](/docs/canvas-effects)-- [`wave()`](/docs/canvas-effects/wave)-- [`tint()`](/docs/canvas-effects/tint)diff --git a/packages/docs/docs/canvas-effects/define-effect.mdx b/packages/docs/docs/canvas-effects/define-effect.mdxdeleted file mode 100644index e16ef6070d..0000000000--- a/packages/docs/docs/canvas-effects/define-effect.mdx+++ /dev/null@@ -1,127 +0,0 @@-----image: /generated/articles-docs-canvas-effects-define-effect.png-title: defineEffect()-crumb: 'Canvas effects'------# defineEffect()<AvailableFrom v="4.0.452" />--Helper for declaring a [canvas effect](/docs/canvas-effects). Wrapping a definition in `defineEffect()` does not change its runtime behavior — it only enables type inference for the parameter and state generics.--```tsx twoslash title="src/effects/identity.ts"-import {defineEffect, createDescriptor} from 'remotion';--const identityDef = defineEffect<{}, null>({- type: 'remotion-docs/identity',- backend: '2d',- setup: () => null,- apply: ({source, target, width, height}) => {- const ctx = target.getContext('2d');- if (!ctx) {- return;- }-- ctx.clearRect(0, 0, width, height);- ctx.drawImage(source, 0, 0, width, height);- },-});--export const identity = () => createDescriptor(identityDef, {});-```--## Definition fields--### type--A unique string identifier. Used in error messages and dev-tools; not used for caching.--### backend--One of `'2d' | 'webgl2' | 'webgpu'`. Determines which kind of context the runtime hands you in `target.getContext(...)`.--### setup--`(target: HTMLCanvasElement) => S | Promise<S>`--Called once per effect identity, per chain. Use it to compile shaders, allocate textures, or upload static buffers. The returned value is passed back to `apply()` as `state`.--The runtime caches the returned state in a `WeakMap<EffectDefinition, ...>`, so re-rendering does not re-run setup. The cache is invalidated only when the chain unmounts or the canvas dimensions change.--### apply--`(params: EffectApplyParams<P, S>) => void | Promise<void>`--Called every frame. Receives:--#### source--A `CanvasImageSource` containing the input image (the output of the previous effect, or the source component's image for the first effect in the chain).--#### target--The `HTMLCanvasElement` to draw the output into. The runtime owns this canvas; the effect must not hold a reference to it across frames.--#### state--The value returned from `setup()`.--#### params--The parameters passed in the [`createDescriptor()`](#createdescriptor) call.--#### frame--The current frame number, equivalent to [`useCurrentFrame()`](/docs/use-current-frame).--#### width / height / pixelRatio--The chain's dimensions and the host's pixel ratio.--#### gpuDevice--A `GPUDevice` if any effect in the chain uses the `'webgpu'` backend, otherwise `null`. The type is `unknown` to avoid pulling `@webgpu/types` into core; cast it at the use site.--### cleanup?--`(state: S) => void`--Called when the chain unmounts. Use it to free GPU resources allocated in `setup()`. Optional.--## createDescriptor()--Pairs a definition with a set of parameters to produce an `EffectDescriptor` that can be passed to a source component's `effects` prop.--```ts twoslash-import {defineEffect, createDescriptor} from 'remotion';--const identityDef = defineEffect<{}, null>({- type: 'remotion-docs/identity',- backend: '2d',- setup: () => null,- apply: () => undefined,-});-// ---cut----const descriptor = createDescriptor(identityDef, {});-```--Effect authors typically expose a thin wrapper:--```ts twoslash-import {defineEffect, createDescriptor} from 'remotion';--type WaveParams = {amplitude: number};-const waveDef = defineEffect<WaveParams, null>({- type: 'remotion-docs/wave',- backend: '2d',- setup: () => null,- apply: () => undefined,-});-// ---cut----export const wave = (params: WaveParams) => createDescriptor(waveDef, params);-```--## See also--- [`<Solid>`](/docs/solid)-- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)-- [Canvas effects overview](/docs/canvas-effects)diff --git a/packages/docs/docs/canvas-effects/html-in-canvas.mdx b/packages/docs/docs/canvas-effects/html-in-canvas.mdxdeleted file mode 100644index 09d2209ed9..0000000000--- a/packages/docs/docs/canvas-effects/html-in-canvas.mdx+++ /dev/null@@ -1,88 +0,0 @@-----image: /generated/articles-docs-canvas-effects-html-in-canvas.png-title: <Experimental.HtmlInCanvas>-crumb: 'Canvas effects'------# <Experimental.HtmlInCanvas><AvailableFrom v="4.0.452" />--<ExperimentalBadge>-<p>-This component depends on the experimental{' '}-<a href="https://github.com/WICG/html-in-canvas">WICG html-in-canvas</a> proposal,-which currently requires Chrome Canary with{' '}-<code>chrome://flags/#canvas-draw-element</code> enabled. Composition rendering-will fail with a clear error in any other environment.-</p>-</ExperimentalBadge>--A [canvas-effect source](/docs/canvas-effects) that rasterizes its DOM children into a canvas using the WICG `html-in-canvas` proposal. The captured DOM image then flows through an [effect chain](/docs/canvas-effects).--```tsx twoslash title="src/HtmlInCanvasDemo.tsx"-import {wave} from '@remotion/canvas-effects';-import {AbsoluteFill, Experimental, useVideoConfig} from 'remotion';--export const HtmlInCanvasDemo = () => {- const {width, height} = useVideoConfig();-- return (- <AbsoluteFill style={{backgroundColor: 'black'}}>- <Experimental.HtmlInCanvas- width={width}- height={height}- effects={[wave({amplitude: 60, wavelength: 240})]}- >- <div- style={{- display: 'flex',- alignItems: 'center',- justifyContent: 'center',- width: '100%',- height: '100%',- color: 'white',- fontSize: 96,- }}- >- Hello!- </div>- </Experimental.HtmlInCanvas>- </AbsoluteFill>- );-};-```--## Props--### width--Width of the output canvas, in pixels.--### height--Height of the output canvas, in pixels.--### children--The DOM subtree to rasterize. Rendered inside a wrapper `<div>` sized to `width`/`height` so children can use `width: 100%`/`height: 100%`. The wrapper is itself a child of the source `<canvas>`, whose `layoutSubtree` flag is set so children participate in layout and paint.--### effects?--An array of [`EffectDescriptor`](/docs/canvas-effects/define-effect) values. See [`<Solid>`](/docs/solid) for details on the `effects` prop.--### className?--Forwarded to the visible output `<canvas>`.--### style?--Forwarded to the visible output `<canvas>`.--### pixelRatio?--Forwarded to effects as `pixelRatio` in `EffectApplyParams`. Default `1`.--## See also--- [Canvas effects overview](/docs/canvas-effects)-- [`<Solid>`](/docs/solid)-- [`defineEffect()`](/docs/canvas-effects/define-effect)diff --git a/packages/docs/docs/canvas-effects/index.mdx b/packages/docs/docs/canvas-effects/index.mdxdeleted file mode 100644index d10ad2039e..0000000000--- a/packages/docs/docs/canvas-effects/index.mdx+++ /dev/null@@ -1,107 +0,0 @@-----image: /generated/articles-docs-canvas-effects-index.png-title: 'Canvas effects'-crumb: 'Canvas effects'------# Canvas effects<AvailableFrom v="4.0.452" />--Canvas effects let you build After Effects–style per-pixel transformations directly on a `<canvas>`, composing 2D, WebGL2, and (in the future) WebGPU passes inside a single chain.--The system has two layers:--- The runtime, source components ([`<Solid>`](/docs/solid), [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)), and the [`defineEffect()`](/docs/canvas-effects/define-effect) helper ship inside `remotion`.-- Sample effects ([`wave`](/docs/canvas-effects/wave), [`tint`](/docs/canvas-effects/tint), [`blur`](/docs/canvas-effects/blur)) ship inside [`@remotion/canvas-effects`](/docs/canvas-effects).--## Installation--The runtime is part of `remotion` itself — there is nothing extra to install if all you need is the source components and `defineEffect()`.--To use the bundled sample effects, install [`@remotion/canvas-effects`](https://www.npmjs.com/package/@remotion/canvas-effects):--import Tabs from '@theme/Tabs';-import TabItem from '@theme/TabItem';--<Tabs-defaultValue="npm"-values={[-{ label: 'npm', value: 'npm' },-{ label: 'pnpm', value: 'pnpm' },-{ label: 'yarn', value: 'yarn' },-]}>-<TabItem value="npm">--```bash-npm i @remotion/canvas-effects-```-- </TabItem>- <TabItem value="pnpm">--```bash-pnpm i @remotion/canvas-effects-```-- </TabItem>- <TabItem value="yarn">--```bash-yarn add @remotion/canvas-effects-```-- </TabItem>-</Tabs>--Align the version with `remotion` and any other `@remotion/*` packages.--## Concepts--### Source components--A source component owns a chain. It produces a `CanvasImageSource` (the input image) for every frame and renders the chain output into a visible `<canvas>`. The first source components are:--- [`<Solid>`](/docs/solid) — a flat-color source.-- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas) — rasterizes DOM children into a canvas via the [WICG `html-in-canvas` proposal](https://github.com/WICG/html-in-canvas).--### Effects--An effect is a description of how to transform an input image into an output image. Each effect targets a single backend (`'2d'`, `'webgl2'`, or `'webgpu'`) and defines `setup`, `apply`, and (optionally) `cleanup` lifecycle hooks. Authors declare effects with [`defineEffect()`](/docs/canvas-effects/define-effect).--Effects are passed into a source component as an array via the `effects` prop:--```tsx twoslash title="src/Demo.tsx"-import {blur, tint} from '@remotion/canvas-effects';-import {Solid} from 'remotion';--export const Demo = () => (- <Solid- color="hotpink"- width={1920}- height={1080}- effects={[blur({radius: 24}), tint({color: 'cyan', amount: 0.4})]}- />-);-```--### Chain semantics--The chain runtime processes effects sequentially. Adjacent effects sharing the same backend are grouped into a single "run" and ping-ponged between two scratch canvases. Between runs, the runtime transfers the intermediate image via `createImageBitmap()` so the next backend can sample it.--The runtime owns one `delayRender()`/`continueRender()` pair per frame and per chain.--### Alpha and color space--All scratch canvases use **premultiplied alpha** and **sRGB** storage. Effects that perform color math in linear space must convert to/from sRGB themselves. Source components write their input image in this format; the runtime preserves it through every transition.--## API--- [`<Solid>`](/docs/solid)-- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)-- [`defineEffect()`](/docs/canvas-effects/define-effect)-- [`wave()`](/docs/canvas-effects/wave)-- [`tint()`](/docs/canvas-effects/tint)-- [`blur()`](/docs/canvas-effects/blur)--## License--MITdiff --git a/packages/docs/docs/canvas-effects/tint.mdx b/packages/docs/docs/canvas-effects/tint.mdxdeleted file mode 100644index 484bbaa0d9..0000000000--- a/packages/docs/docs/canvas-effects/tint.mdx+++ /dev/null@@ -1,39 +0,0 @@-----image: /generated/articles-docs-canvas-effects-tint.png-title: tint()-crumb: '@remotion/canvas-effects'------# tint()<AvailableFrom v="4.0.452" />--A 2D [canvas effect](/docs/canvas-effects) that overlays a flat color onto the source. The tint respects the source's alpha mask via `globalCompositeOperation: 'source-atop'`.--```tsx twoslash title="src/TintDemo.tsx"-import {tint} from '@remotion/canvas-effects';-import {Solid} from 'remotion';--export const TintDemo = () => (- <Solid- color="hotpink"- width={1920}- height={1080}- effects={[tint({color: 'cyan', amount: 0.5})]}- />-);-```--## Parameters--### color--The CSS color to overlay onto the source.--### amount?--Blend strength between `0` (no tint) and `1` (full color over opaque pixels). Values are clamped. Default `0.5`.--## See also--- [Canvas effects overview](/docs/canvas-effects)-- [`wave()`](/docs/canvas-effects/wave)-- [`blur()`](/docs/canvas-effects/blur)diff --git a/packages/docs/docs/canvas-effects/wave.mdx b/packages/docs/docs/canvas-effects/wave.mdxdeleted file mode 100644index fd36135222..0000000000--- a/packages/docs/docs/canvas-effects/wave.mdx+++ /dev/null@@ -1,51 +0,0 @@-----image: /generated/articles-docs-canvas-effects-wave.png-title: wave()-crumb: '@remotion/canvas-effects'------# wave()<AvailableFrom v="4.0.452" />--A 2D [canvas effect](/docs/canvas-effects) that shifts vertical slices of the source up and down with an animated sine wave.--```tsx twoslash title="src/WaveDemo.tsx"-import {wave} from '@remotion/canvas-effects';-import {Solid} from 'remotion';--export const WaveDemo = () => (- <Solid- color="white"- width={1920}- height={1080}- effects={[wave({amplitude: 60, wavelength: 240})]}- />-);-```--## Parameters--### amplitude?--Maximum vertical displacement in pixels. Default `60`.--### wavelength?--Horizontal period of the wave, in pixels. Default `240`.--### speed?--Per-frame phase increment, in radians. Default `1 / 6` (≈9.5° per frame).--### sliceWidth?--Width of each vertical slice, in pixels. Smaller values produce smoother curves at the cost of more draw calls. Default `4`.--### background?--CSS color for the background fill drawn before the slices. Default `'transparent'` (no fill).--## See also--- [Canvas effects overview](/docs/canvas-effects)-- [`tint()`](/docs/canvas-effects/tint)-- [`blur()`](/docs/canvas-effects/blur)diff --git a/packages/docs/docs/solid.mdx b/packages/docs/docs/solid.mdxdeleted file mode 100644index 6393d2e86f..0000000000--- a/packages/docs/docs/solid.mdx+++ /dev/null@@ -1,56 +0,0 @@-----image: /generated/articles-docs-solid.png-title: <Solid>-crumb: 'Canvas effects'------# <Solid><AvailableFrom v="4.0.452" />--A flat-color [canvas-effect source](/docs/canvas-effects). Useful as a procedural input to a chain of [effects](/docs/canvas-effects/define-effect).--```tsx twoslash title="src/SolidDemo.tsx"-import {blur} from '@remotion/canvas-effects';-import {Solid} from 'remotion';--export const SolidDemo = () => (- <Solid color="hotpink" width={1920} height={1080} effects={[blur({radius: 24})]} />-);-```--## Props--### color--A CSS color string used to fill the source canvas. Any value the 2D context accepts is allowed.--### width--Width of the visible output canvas, in pixels.--### height--Height of the visible output canvas, in pixels.--### effects?--An array of [`EffectDescriptor`](/docs/canvas-effects/define-effect) values. Adjacent same-backend effects are grouped and ping-ponged between scratch canvases. Defaults to `[]`, in which case the source color is drawn directly into the output.--You may also pass nested arrays — e.g. `[blur({radius: 12})]` returns a `[horizontal, vertical]` pair. The runtime calls `.flat()` once before processing.--### className?--Forwarded to the underlying `<canvas>`.--### style?--Forwarded to the underlying `<canvas>`.--### pixelRatio?--Forwarded to effects as `pixelRatio` in `EffectApplyParams`. Default `1`.--## See also--- [Canvas effects overview](/docs/canvas-effects)-- [`defineEffect()`](/docs/canvas-effects/define-effect)-- [`<Experimental.HtmlInCanvas>`](/docs/canvas-effects/html-in-canvas)diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex fcf3ae3a8e..fe844d5996 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -229,22 +229,6 @@ const sidebars: SidebarsConfig = {'captions/create-tiktok-style-captions',],},- {- type: 'category',- label: 'Canvas effects',- link: {- type: 'doc',- id: 'canvas-effects/index',- },- items: [- 'solid',- 'canvas-effects/html-in-canvas',- 'canvas-effects/define-effect',- 'canvas-effects/wave',- 'canvas-effects/tint',- 'canvas-effects/blur',- ],- },{type: 'category',label: '@remotion/cloudrun',diff --git a/packages/example/src/CanvasEffects/SolidDemo.tsx b/packages/example/src/CanvasEffects/SolidDemo.tsxdeleted file mode 100644index 783b3034a0..0000000000--- a/packages/example/src/CanvasEffects/SolidDemo.tsx+++ /dev/null@@ -1,39 +0,0 @@-import {blur, tint} from '@remotion/canvas-effects';-import React from 'react';-import {- AbsoluteFill,- interpolate,- Solid,- useCurrentFrame,- useVideoConfig,-} from 'remotion';--// Demonstrates the canvas-effect chain with `<Solid>` as the source. The chain-// runs a separable Gaussian blur (WebGL2) followed by a tint pass (2D),-// exercising the runtime's cross-backend transfer (createImageBitmap) inside-// a single chain.-export const SolidEffectsDemo: React.FC = () => {- const frame = useCurrentFrame();- const {width, height, durationInFrames} = useVideoConfig();-- const radius = interpolate(frame, [0, durationInFrames - 1], [8, 64], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- });-- const tintAmount = interpolate(frame, [0, durationInFrames - 1], [0.1, 0.6], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- });-- return (- <AbsoluteFill style={{backgroundColor: 'black'}}>- <Solid- color="hotpink"- width={width}- height={height}- effects={[blur({radius}), tint({color: 'cyan', amount: tintAmount})]}- />- </AbsoluteFill>- );-};diff --git a/packages/example/src/HtmlInCanvas/index.tsx b/packages/example/src/HtmlInCanvas/index.tsxindex f9f0748fde..2cdb22e2dd 100644--- a/packages/example/src/HtmlInCanvas/index.tsx+++ b/packages/example/src/HtmlInCanvas/index.tsx@@ -1,8 +1,9 @@-import {wave} from '@remotion/canvas-effects';+import {blur, tint, wave} from '@remotion/canvas-effects';import React from 'react';import {AbsoluteFill,Experimental,+ interpolate,useCurrentFrame,useVideoConfig,} from 'remotion';@@ -40,14 +41,29 @@ const Scene: React.FC = () => {};export const HtmlInCanvasDemo: React.FC = () => {- const {width, height} = useVideoConfig();+ const frame = useCurrentFrame();+ const {width, height, durationInFrames} = useVideoConfig();++ const blurRadius = interpolate(frame, [0, durationInFrames - 1], [0, 24], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ });++ const tintAmount = interpolate(frame, [0, durationInFrames - 1], [0, 0.4], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ });return (<AbsoluteFill style={{backgroundColor: 'black'}}><Experimental.HtmlInCanvaswidth={width}height={height}- effects={[wave({amplitude: 60, wavelength: 240})]}+ effects={[+ wave({amplitude: 40, wavelength: 240}),+ blur({radius: blurRadius}),+ tint({color: 'cyan', amount: tintAmount}),+ ]}><Scene /></Experimental.HtmlInCanvas>diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex adf1956132..0fc032637a 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -16,7 +16,6 @@ import {NativeBufferStateForImage} from './BufferState/Image';import {NativeBufferState} from './BufferState/Simple';import {NativeBufferStateForVideo} from './BufferState/Video';import {CancelRender} from './CancelRender';-import {SolidEffectsDemo} from './CanvasEffects/SolidDemo';import {ClassSerialization} from './ClassSerialization';import {ColorInterpolation} from './ColorInterpolation';import {ComplexSounds} from './ComplexSounds';@@ -843,14 +842,6 @@ export const Index: React.FC = () => {width={1920}durationInFrames={120}/>- <Composition- id="solid-effects"- component={SolidEffectsDemo}- fps={30}- height={1080}- width={1920}- durationInFrames={120}- /><Compositionid="video-testing-webm"component={VideoTesting}diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.jsonindex 2858e379bb..0a915cf41e 100644--- a/packages/example/tsconfig.json+++ b/packages/example/tsconfig.json@@ -18,6 +18,7 @@{"path": "../babel-loader"},{"path": "../bundler"},{"path": "../captions"},+ {"path": "../canvas-effects"},{"path": "../cli"},{"path": "../eslint-config"},{"path": "../eslint-plugin"},