Skip to content

πŸŽ₯ Make videos programmatically with React

wow not bad

JonnyBurgerd8fe5d1e8a16
diff --git a/.claude/skills/add-new-package/SKILL.md b/.claude/skills/add-new-package/SKILL.md
index 0ba78d15de..17714cf648 100644
--- a/.claude/skills/add-new-package/SKILL.md
+++ b/.claude/skills/add-new-package/SKILL.md
@@ -18,16 +18,19 @@
- `packages/studio-shared/src/package-info.ts` β€” add to `packages`, `descriptions`, `installableMap`, `apiDocs`
3. **Documentation (`packages/docs/docs/<name>/`):**
+ - Add `"@remotion/<name>": "workspace:*"` to `packages/docs/package.json` dependencies (needed for twoslash snippets)
- `index.mdx` β€” install tabs, table of contents, license
- `table-of-contents.tsx` β€” TOCItem grid linking to component/function pages
- Individual component/function `.mdx` pages
- Edit `packages/docs/sidebars.ts` β€” add category
- Edit `packages/docs/src/data/articles.ts` β€” add entries alphabetically
+ - Edit `packages/docs/components/TableOfContents/api.tsx` β€” import table of contents and add section
4. **Example usage:**
- Add `"@remotion/<name>": "workspace:*"` to `packages/example/package.json`
- Create `packages/example/src/<Name>/index.tsx`
- Register `<Composition>` in `packages/example/src/Root.tsx`
+ - Add `{"path": "../<name>"}` to `packages/example/tsconfig.json` references
5. **Run `bun i`** to install dependencies
diff --git a/.claude/skills/writing-docs/SKILL.md b/.claude/skills/writing-docs/SKILL.md
index 059f1cc72a..cd07d5fd2f 100644
--- a/.claude/skills/writing-docs/SKILL.md
+++ b/.claude/skills/writing-docs/SKILL.md
@@ -65,6 +65,8 @@ const frame = useCurrentFrame();
### Adding titles
+Always add a `title` to code fences that show example usage:
+
````md
```ts twoslash title="MyComponent.tsx"
console.log('Hello');
@@ -100,8 +102,14 @@ Demos must be implemented in `packages/docs/components/demos/index.tsx`. See the
Use to indicate when a feature or parameter was added. No import needed - it's globally available.
+**For page-level version indicators**, use an `# h1` heading with `<AvailableFrom>` inline so it appears next to the title (not below it). Use `&lt;` and `&gt;` to escape angle brackets in component names:
+
+```md
+# &lt;MyComponent&gt;<AvailableFrom v="4.0.123" />
+```
+
```md
-## myFunction()<AvailableFrom v="4.0.123" />
+# @remotion/my-package<AvailableFrom v="4.0.123" />
```
For section headings:
diff --git a/bun.lock b/bun.lock
index 74bc23aec3..6f801ea132 100644
--- a/bun.lock
+++ b/bun.lock
@@ -393,6 +393,7 @@
"@remotion/lambda-client": "workspace:*",
"@remotion/layout-utils": "workspace:*",
"@remotion/licensing": "workspace:*",
+ "@remotion/light-leaks": "workspace:*",
"@remotion/lottie": "workspace:*",
"@remotion/media": "workspace:*",
"@remotion/media-parser": "workspace:*",
diff --git a/packages/docs/components/TableOfContents/api.tsx b/packages/docs/components/TableOfContents/api.tsx
index 13183e0c44..872fc0c65d 100644
--- a/packages/docs/components/TableOfContents/api.tsx
+++ b/packages/docs/components/TableOfContents/api.tsx
@@ -11,6 +11,7 @@ import {TableOfContents as GoogleFontsTableOfContents} from '../../docs/google-f
import {TableOfContents as InstallWhisperCppTableOfContents} from '../../docs/install-whisper-cpp/install-whisper-cpp';
import {TableOfContents as LambdaTableOfContents} from '../../docs/lambda/table-of-contents';
import {TableOfContents as LayoutUtilsTableOfContents} from '../../docs/layout-utils/table-of-contents';
+import {TableOfContents as LightLeaksTableOfContents} from '../../docs/light-leaks/table-of-contents';
import {TableOfContents as LicensingTableOfContents} from '../../docs/licensing/TableOfContents';
import {TableOfContents as LottieTableOfContents} from '../../docs/lottie/table-of-contents';
import {TableOfContents as MediaParserTableOfContents} from '../../docs/media-parser/TableOfContents';
@@ -150,6 +151,9 @@ export const TableOfContents: React.FC = () => {
<h2>@remotion/zod-types</h2>
<p>Zod types enabling Remotion Studio UI</p>
<ZodTypesTableOfContents />
+ <h2>@remotion/light-leaks</h2>
+ <p>Light leak effects</p>
+ <LightLeaksTableOfContents />
<h2>@remotion/motion-blur</h2>
<p>Apply motion blur effects to components</p>
<MotionBlurTableOfContents />
diff --git a/packages/docs/components/demos/LightLeakDemo.tsx b/packages/docs/components/demos/LightLeakDemo.tsx
new file mode 100644
index 0000000000..17f8f3fd55
--- /dev/null
+++ b/packages/docs/components/demos/LightLeakDemo.tsx
@@ -0,0 +1,16 @@
+import {LightLeak} from '@remotion/light-leaks';
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+interface Props {
+ readonly seed: number;
+ readonly hueShift: number;
+}
+
+export const LightLeakDemoComp: React.FC<Props> = ({seed, hueShift}) => {
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <LightLeak seed={seed} hueShift={hueShift} />
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index e4f4855355..5263e5ed86 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -17,6 +17,7 @@ import {
flipPresentationDemo,
heartDemo,
irisPresentationDemo,
+ lightLeakDemo,
noiseDemo,
nonePresentationDemo,
opacityDemo,
@@ -77,6 +78,7 @@ const demos: DemoType[] = [
springDemo,
springDampingDemo,
shaderDemo,
+ lightLeakDemo,
];
export const Demo: React.FC<{
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index b826b3cc9e..605a883de6 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -14,6 +14,7 @@ import {
import {CircleDemo} from './Circle';
import {EllipseDemo} from './Ellipse';
import {HeartDemo} from './Heart';
+import {LightLeakDemoComp} from './LightLeakDemo';
import {NoiseComp} from './NoiseDemo';
import {PieDemo} from './Pie';
import {PolygonDemo} from './Polygon';
@@ -917,3 +918,33 @@ export const springDampingDemo: DemoType = {
},
],
};
+
+export const lightLeakDemo: DemoType = {
+ comp: LightLeakDemoComp,
+ compHeight: 720,
+ compWidth: 1280,
+ durationInFrames: 90,
+ fps: 30,
+ id: 'light-leak',
+ autoPlay: true,
+ options: [
+ {
+ name: 'seed',
+ type: 'numeric',
+ default: 0,
+ min: 0,
+ max: 100,
+ step: 1,
+ optional: 'no',
+ },
+ {
+ name: 'hueShift',
+ type: 'numeric',
+ default: 0,
+ min: 0,
+ max: 360,
+ step: 1,
+ optional: 'no',
+ },
+ ],
+};
diff --git a/packages/docs/docs/light-leaks/index.mdx b/packages/docs/docs/light-leaks/index.mdx
index 87b4a415e4..8a5405260e 100644
--- a/packages/docs/docs/light-leaks/index.mdx
+++ b/packages/docs/docs/light-leaks/index.mdx
@@ -3,7 +3,7 @@ image: /generated/articles-docs-light-leaks-index.png
title: '@remotion/light-leaks'
---
-<AvailableFrom v="4.0.414" />
+# @remotion/light-leaks<AvailableFrom v="4.0.414" />
Light leak effects for Remotion videos.
diff --git a/packages/docs/docs/light-leaks/light-leak.mdx b/packages/docs/docs/light-leaks/light-leak.mdx
index 42116eef9e..ec0dd8c700 100644
--- a/packages/docs/docs/light-leaks/light-leak.mdx
+++ b/packages/docs/docs/light-leaks/light-leak.mdx
@@ -3,26 +3,43 @@ image: /generated/articles-docs-light-leaks-light-leak.png
title: '<LightLeak>'
---
-<AvailableFrom v="4.0.414" />
+# &lt;LightLeak&gt;<AvailableFrom v="4.0.415" />
-A component that renders a light leak effect as a [`<Sequence>`](/docs/sequence).
+Renders a WebGL-based light leak effect. The effect reveals during the first half of the duration and retracts during the second half.
-## API
+## Example
-The `<LightLeak>` component accepts all props that [`<Sequence>`](/docs/sequence) accepts.
+<Demo type="light-leak" />
-```tsx twoslash
+```tsx twoslash title="MyComp.tsx"
import {LightLeak} from '@remotion/light-leaks';
+import {AbsoluteFill} from 'remotion';
const MyVideo = () => {
return (
- <LightLeak durationInFrames={60}>
- <div>My content</div>
- </LightLeak>
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <LightLeak durationInFrames={60} seed={3} hueShift={30} />
+ </AbsoluteFill>
);
};
```
+## API
+
+Apart from the props listed below, all props from [`<Sequence>`](/docs/sequence) except `children` and `layout` are accepted.
+
+### `seed?`
+
+Determines the shape of the light leak pattern. Different seeds produce different patterns. Default: `0`.
+
+### `hueShift?`
+
+Rotates the hue of the light leak in degrees (`0`-`360`).
+
+- `0` (default) yellow-to-orange
+- `120` shifts toward green
+- `240` shifts toward blue
+
## See also
- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/light-leaks/src/LightLeak.tsx)
diff --git a/packages/docs/package.json b/packages/docs/package.json
index 79f551e53f..2de9801004 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -53,6 +53,7 @@
"@remotion/lambda-client": "workspace:*",
"@remotion/layout-utils": "workspace:*",
"@remotion/licensing": "workspace:*",
+ "@remotion/light-leaks": "workspace:*",
"@remotion/lottie": "workspace:*",
"@remotion/media": "workspace:*",
"@remotion/media-parser": "workspace:*",
diff --git a/packages/example/src/LightLeak/index.tsx b/packages/example/src/LightLeak/index.tsx
index c385da3a5a..dc8d94982b 100644
--- a/packages/example/src/LightLeak/index.tsx
+++ b/packages/example/src/LightLeak/index.tsx
@@ -4,14 +4,8 @@ import {AbsoluteFill} from 'remotion';
export const LightLeakExample: React.FC = () => {
return (
- <AbsoluteFill>
- <LightLeak durationInFrames={60}>
- <AbsoluteFill
- style={{backgroundColor: 'white', justifyContent: 'center', alignItems: 'center'}}
- >
- <h1 style={{fontSize: 60}}>Light Leak Effect</h1>
- </AbsoluteFill>
- </LightLeak>
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <LightLeak durationInFrames={60} seed={3} hueShift={30} />
</AbsoluteFill>
);
};
diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.json
index dd2da48fc0..abf81d2eeb 100644
--- a/packages/example/tsconfig.json
+++ b/packages/example/tsconfig.json
@@ -39,6 +39,7 @@
{"path": "../media-parser"},
{"path": "../webcodecs"},
{"path": "../whisper-web"},
+ {"path": "../light-leaks"},
{"path": "../layout-utils"},
{"path": "../media"},
{"path": "../rounded-text-box"}
diff --git a/packages/light-leaks/src/LightLeak.tsx b/packages/light-leaks/src/LightLeak.tsx
index eff03a0ed4..fe8392df3f 100644
--- a/packages/light-leaks/src/LightLeak.tsx
+++ b/packages/light-leaks/src/LightLeak.tsx
@@ -1,15 +1,241 @@
-import React from 'react';
+import React, {useCallback, useEffect, useRef} from 'react';
import type {SequenceProps} from 'remotion';
-import {Sequence} from 'remotion';
+import {AbsoluteFill, Sequence, useCurrentFrame, useVideoConfig} from 'remotion';
-export type LightLeakProps = Omit<SequenceProps, 'children'> & {
- children: React.ReactNode;
+export type LightLeakProps = Omit<SequenceProps, 'children' | 'layout'> & {
+ readonly seed?: number;
+ readonly hueShift?: number;
+};
+
+const VERTEX_SHADER = `
+attribute vec2 position;
+void main() {
+ gl_Position = vec4(position, 0.0, 1.0);
+}
+`;
+
+const FRAGMENT_SHADER = `
+#ifdef GL_ES
+precision mediump float;
+#endif
+
+uniform float evolveProgress;
+uniform float retractProgress;
+uniform float seed;
+uniform float retractSeed;
+uniform float hueShift;
+uniform vec2 resolution;
+
+const float Pi = 3.14159;
+
+vec3 computePattern(vec2 uv, float s, float t) {
+ vec2 p = uv * 0.8;
+ p += vec2(sin(s * 1.61803) * 5.0, cos(s * 2.71828) * 5.0);
+
+ for(int i = 1; i < 5; i++)
+ {
+ vec2 newp = p;
+ float fi = float(i);
+ float phase = s * 0.7 * fi;
+ newp.x += 0.6 / fi * cos(fi * p.y + t * 0.7 + 0.3 * fi + phase) + 20.0;
+ newp.y += 0.6 / fi * cos(fi * p.x + t * 0.7 + 0.3 * float(i + 10) + phase) - 20.0 + 15.0;
+ p = newp;
+ }
+
+ float v1 = 0.5 * sin(2.0 * p.x) + 0.5;
+ float v2 = 0.5 * sin(2.0 * p.y) + 0.5;
+ float blend = sin(p.x + p.y) * 0.5 + 0.5;
+ float brightness = v1 * 0.5 + v2 * 0.5;
+ float patternValue = brightness * 0.6 + blend * 0.4;
+
+ return vec3(brightness, blend, patternValue);
+}
+
+void main()
+{
+ vec2 uv = 0.001 * gl_FragCoord.xy;
+
+ vec3 patA = computePattern(uv, seed, evolveProgress * Pi);
+ float threshA = 1.0 - evolveProgress;
+ float revealAlpha = smoothstep(threshA, threshA + 0.3, patA.z);
+
+ vec2 maxUv = 0.001 * resolution;
+ vec2 retractUv = maxUv - uv;
+ vec3 patB = computePattern(retractUv, retractSeed, retractProgress * Pi);
+ float threshB = 1.0 - retractProgress;
+ float eraseAlpha = smoothstep(threshB, threshB + 0.3, patB.z);
+
+ float alpha = revealAlpha * (1.0 - eraseAlpha);
+
+ vec3 yellow = vec3(1.0, 0.85, 0.2);
+ vec3 orange = vec3(1.0, 0.5, 0.05);
+ vec3 col = mix(yellow, orange, patA.y);
+ col *= 0.6 + 0.6 * patA.x;
+
+ float angle = hueShift * Pi / 180.0;
+ float cosA = cos(angle);
+ float sinA = sin(angle);
+ mat3 hueRot = mat3(
+ cosA + (1.0 - cosA) / 3.0,
+ (1.0 - cosA) / 3.0 - sinA * 0.57735,
+ (1.0 - cosA) / 3.0 + sinA * 0.57735,
+ (1.0 - cosA) / 3.0 + sinA * 0.57735,
+ cosA + (1.0 - cosA) / 3.0,
+ (1.0 - cosA) / 3.0 - sinA * 0.57735,
+ (1.0 - cosA) / 3.0 - sinA * 0.57735,
+ (1.0 - cosA) / 3.0 + sinA * 0.57735,
+ cosA + (1.0 - cosA) / 3.0
+ );
+ col = clamp(hueRot * col, 0.0, 1.0);
+
+ gl_FragColor = vec4(col, alpha);
+}
+`;
+
+type GlContext = {
+ gl: WebGLRenderingContext;
+ resLoc: WebGLUniformLocation;
+ evolveProgressLoc: WebGLUniformLocation;
+ retractProgressLoc: WebGLUniformLocation;
+ seedLoc: WebGLUniformLocation;
+ retractSeedLoc: WebGLUniformLocation;
+ hueShiftLoc: WebGLUniformLocation;
+};
+
+const LightLeakCanvas: React.FC<{
+ readonly seed: number;
+ readonly hueShift: number;
+}> = ({seed, hueShift}) => {
+ const frame = useCurrentFrame();
+ const {width, height, durationInFrames} = useVideoConfig();
+ const canvasRef = useRef<HTMLCanvasElement>(null);
+ const glRef = useRef<GlContext | null>(null);
+
+ const initGl = useCallback((canvas: HTMLCanvasElement): GlContext | null => {
+ const gl = canvas.getContext('webgl', {
+ premultipliedAlpha: false,
+ alpha: true,
+ });
+ if (!gl) return null;
+ gl.enable(gl.BLEND);
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
+
+ const compile = (type: number, src: string) => {
+ const s = gl.createShader(type)!;
+ gl.shaderSource(s, src);
+ gl.compileShader(s);
+ return s;
+ };
+
+ const program = gl.createProgram()!;
+ gl.attachShader(program, compile(gl.VERTEX_SHADER, VERTEX_SHADER));
+ gl.attachShader(
+ program,
+ compile(gl.FRAGMENT_SHADER, FRAGMENT_SHADER),
+ );
+ gl.linkProgram(program);
+ gl.useProgram(program);
+
+ const buf = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, buf);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
+ gl.STATIC_DRAW,
+ );
+ const pos = gl.getAttribLocation(program, 'position');
+ gl.enableVertexAttribArray(pos);
+ gl.vertexAttribPointer(pos, 2, gl.FLOAT, false, 0, 0);
+
+ return {
+ gl,
+ resLoc: gl.getUniformLocation(program, 'resolution')!,
+ evolveProgressLoc: gl.getUniformLocation(
+ program,
+ 'evolveProgress',
+ )!,
+ retractProgressLoc: gl.getUniformLocation(
+ program,
+ 'retractProgress',
+ )!,
+ seedLoc: gl.getUniformLocation(program, 'seed')!,
+ retractSeedLoc: gl.getUniformLocation(program, 'retractSeed')!,
+ hueShiftLoc: gl.getUniformLocation(program, 'hueShift')!,
+ };
+ }, []);
+
+ useEffect(() => {
+ const canvas = canvasRef.current;
+ if (!canvas || glRef.current) return;
+ glRef.current = initGl(canvas);
+ }, [initGl]);
+
+ useEffect(() => {
+ const ctx = glRef.current;
+ if (!ctx) return;
+ const {
+ gl,
+ resLoc,
+ evolveProgressLoc,
+ retractProgressLoc,
+ seedLoc,
+ retractSeedLoc,
+ hueShiftLoc,
+ } = ctx;
+
+ const normalized = frame / (durationInFrames - 1);
+ const evolveProgress = Math.min(1, normalized * 2);
+ const retractProgress = Math.max(0, normalized * 2 - 1);
+
+ gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
+ gl.clearColor(0, 0, 0, 0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ gl.uniform1f(evolveProgressLoc, evolveProgress);
+ gl.uniform1f(retractProgressLoc, retractProgress);
+ gl.uniform1f(seedLoc, seed);
+ gl.uniform1f(retractSeedLoc, seed + 42.0);
+ gl.uniform1f(hueShiftLoc, hueShift);
+ gl.uniform2f(resLoc, gl.canvas.width, gl.canvas.height);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+ }, [frame, durationInFrames, seed, hueShift]);
+
+ return (
+ <AbsoluteFill>
+ <canvas ref={canvasRef} width={width} height={height} />
+ </AbsoluteFill>
+ );
};
/*
- * @description Renders a light leak effect as a Sequence.
+ * @description Renders a WebGL-based light leak effect as a Sequence.
* @see [Documentation](https://www.remotion.dev/docs/light-leaks/light-leak)
*/
-export const LightLeak: React.FC<LightLeakProps> = ({children, ...props}) => {
- return <Sequence {...props}>{children}</Sequence>;
+export const LightLeak: React.FC<LightLeakProps> = ({
+ seed = 0,
+ hueShift = 0,
+ ...sequenceProps
+}) => {
+ if (typeof seed !== 'number' || !Number.isFinite(seed)) {
+ throw new TypeError(
+ `"seed" must be a finite number, but got ${JSON.stringify(seed)}`,
+ );
+ }
+
+ if (typeof hueShift !== 'number' || !Number.isFinite(hueShift)) {
+ throw new TypeError(
+ `"hueShift" must be a finite number, but got ${JSON.stringify(hueShift)}`,
+ );
+ }
+
+ if (hueShift < 0 || hueShift > 360) {
+ throw new RangeError(
+ `"hueShift" must be between 0 and 360, but got ${hueShift}`,
+ );
+ }
+
+ return (
+ <Sequence {...sequenceProps}>
+ <LightLeakCanvas seed={seed} hueShift={hueShift} />
+ </Sequence>
+ );
};