Skip to content

🎥 Make videos programmatically with React

`@remotion/motion-blur`: Add `<HtmlInCanvasMotionBlur>` for sampled HTML blur

JonnyBurger2a44f6a49d8f
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsx
index 85ac6d06c1..72c9e63e96 100644
--- a/packages/core/src/HtmlInCanvas.tsx
+++ b/packages/core/src/HtmlInCanvas.tsx
@@ -359,6 +359,8 @@ export type HtmlInCanvasProps = Omit<InteractiveBaseProps, 'children'> &
readonly onPaint?: HtmlInCanvasOnPaint;
readonly onInit?: HtmlInCanvasOnInit;
readonly pixelDensity?: HtmlInCanvasPixelDensity;
+ // captureElementImage() only accepts immediate children of the layout canvas.
+ readonly _remotionInternalCanvasSiblings?: React.ReactNode;
};
/* eslint-enable react/require-default-props */
@@ -369,6 +371,7 @@ type HtmlInCanvasContentProps = {
readonly height: number;
readonly effects: EffectsProp;
readonly children: React.ReactNode;
+ readonly canvasSiblings: React.ReactNode | null;
readonly onPaint: HtmlInCanvasOnPaint | undefined;
readonly onInit: HtmlInCanvasOnInit | undefined;
readonly pixelDensity: HtmlInCanvasPixelDensity | undefined;
@@ -386,6 +389,7 @@ const HtmlInCanvasContent = forwardRef<
height,
effects,
children,
+ canvasSiblings,
onPaint,
onInit,
pixelDensity,
@@ -716,6 +720,7 @@ const HtmlInCanvasContent = forwardRef<
<div ref={divRef} style={innerStyle}>
{children}
</div>
+ {canvasSiblings}
</canvas>
</HtmlInCanvasAncestorContext.Provider>
);
@@ -739,6 +744,7 @@ const HtmlInCanvasInner = forwardRef<
onPaint,
onInit,
pixelDensity,
+ _remotionInternalCanvasSiblings,
controls,
style,
cropLeft,
@@ -792,6 +798,7 @@ const HtmlInCanvasInner = forwardRef<
onPaint={onPaint}
onInit={onInit}
pixelDensity={pixelDensity}
+ canvasSiblings={_remotionInternalCanvasSiblings ?? null}
controls={controls}
style={croppedStyle ?? undefined}
>
diff --git a/packages/core/src/test/html-in-canvas.test.tsx b/packages/core/src/test/html-in-canvas.test.tsx
index fba22e9a09..3bbde5d0d3 100644
--- a/packages/core/src/test/html-in-canvas.test.tsx
+++ b/packages/core/src/test/html-in-canvas.test.tsx
@@ -303,6 +303,32 @@ test('<HtmlInCanvas> registers its canvas for outline selection', async () => {
expect(registeredSequences[0]?.refForOutline?.current).toBe(canvas);
});
+test('<HtmlInCanvas> renders internal capture siblings directly in the canvas', () => {
+ const {container} = render(
+ <SequenceTestWrapper onRegisterSequence={() => undefined}>
+ <HtmlInCanvas
+ width={120}
+ height={80}
+ _remotionInternalCanvasSiblings={
+ <div data-testid="second-sample">Second sample</div>
+ }
+ >
+ <div data-testid="first-sample">First sample</div>
+ </HtmlInCanvas>
+ </SequenceTestWrapper>,
+ );
+
+ const canvas = container.querySelector('canvas');
+ expect(canvas).not.toBeNull();
+ expect(canvas?.children.length).toBe(2);
+ expect(
+ canvas?.children[0]?.querySelector('[data-testid="first-sample"]'),
+ ).not.toBeNull();
+ expect(canvas?.children[1]?.getAttribute('data-testid')).toBe(
+ 'second-sample',
+ );
+});
+
test('<HtmlInCanvas> applies crop props to its canvas', () => {
const {container} = render(
<SequenceTestWrapper onRegisterSequence={() => undefined}>
diff --git a/packages/docs/components/demos/MotionBlurDemo.tsx b/packages/docs/components/demos/MotionBlurDemo.tsx
new file mode 100644
index 0000000000..68221ba6eb
--- /dev/null
+++ b/packages/docs/components/demos/MotionBlurDemo.tsx
@@ -0,0 +1,112 @@
+import {
+ CameraMotionBlur,
+ HtmlInCanvasMotionBlur,
+ Trail,
+} from '@remotion/motion-blur';
+import React from 'react';
+import {
+ AbsoluteFill,
+ interpolate,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+import {HtmlInCanvasDocsVideoFallback} from './HtmlInCanvasDocsVideoFallback';
+import {useHtmlInCanvasDocsDemoBranch} from './useHtmlInCanvasDocsDemoBranch';
+
+const MovingArtwork: React.FC = () => {
+ const frame = useCurrentFrame();
+ const x = interpolate(frame, [0, 45, 90], [-180, 990, -180]);
+
+ return (
+ <div
+ style={{
+ position: 'absolute',
+ left: x,
+ top: 175,
+ width: 180,
+ height: 180,
+ borderRadius: 32,
+ background: 'linear-gradient(135deg, #ffe064, #ff735c)',
+ boxShadow: '0 18px 50px #0008',
+ transform: `rotate(${frame * 4}deg)`,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ color: '#2d1830',
+ fontFamily: 'sans-serif',
+ fontSize: 110,
+ fontWeight: 800,
+ }}
+ >
+ M
+ </div>
+ );
+};
+
+const MotionBlurScene: React.FC<{
+ readonly variant: 'trail' | 'camera' | 'html-in-canvas';
+}> = ({variant}) => {
+ const {width, height} = useVideoConfig();
+ const artwork = <MovingArtwork />;
+ const blurred =
+ variant === 'trail' ? (
+ <Trail layers={12} lagInFrames={0.14} trailOpacity={0.8}>
+ {artwork}
+ </Trail>
+ ) : variant === 'camera' ? (
+ <CameraMotionBlur samples={8} shutterAngle={180}>
+ {artwork}
+ </CameraMotionBlur>
+ ) : (
+ <HtmlInCanvasMotionBlur
+ width={width}
+ height={height}
+ samples={8}
+ shutterAngle={180}
+ >
+ {artwork}
+ </HtmlInCanvasMotionBlur>
+ );
+
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: '#171626',
+ backgroundImage:
+ 'linear-gradient(#ffffff0b 1px, transparent 1px), linear-gradient(90deg, #ffffff0b 1px, transparent 1px)',
+ backgroundSize: '60px 60px',
+ overflow: 'hidden',
+ }}
+ >
+ {blurred}
+ </AbsoluteFill>
+ );
+};
+
+export const MotionBlurTrailDocsDemo: React.FC = () => (
+ <MotionBlurScene variant="trail" />
+);
+
+export const MotionBlurCameraDocsDemo: React.FC = () => (
+ <MotionBlurScene variant="camera" />
+);
+
+export const MotionBlurHtmlInCanvasLiveDemo: React.FC = () => (
+ <MotionBlurScene variant="html-in-canvas" />
+);
+
+export const MotionBlurHtmlInCanvasDocsDemo: React.FC = () => {
+ const branch = useHtmlInCanvasDocsDemoBranch();
+
+ if (branch === 'pending') {
+ return <AbsoluteFill style={{backgroundColor: '#171626'}} />;
+ }
+
+ if (branch === 'fallback') {
+ return (
+ <HtmlInCanvasDocsVideoFallback relativeSrc="img/motion-blur-html-in-canvas.mp4" />
+ );
+ }
+
+ return <MotionBlurHtmlInCanvasLiveDemo />;
+};
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 787889bad6..af820a0247 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -35,6 +35,9 @@ import {
irisPresentationDemo,
lightLeakDemo,
linearBlurPresentationDemo,
+ motionBlurCameraDemo,
+ motionBlurHtmlInCanvasDemo,
+ motionBlurTrailDemo,
noiseDemo,
nonePresentationDemo,
opacityDemo,
@@ -49,12 +52,12 @@ import {
roughNotationBracketDemo,
roughNotationCircleDemo,
roughNotationCrossedOffDemo,
- roundedTextBoxDemo,
roughNotationHighlightDemo,
roughNotationPosterizedProgressDemo,
roughNotationPosterizedSeedDemo,
roughNotationStrikeThroughDemo,
roughNotationUnderlineDemo,
+ roundedTextBoxDemo,
scaleDemo,
shaderDemo,
skewDemo,
@@ -115,6 +118,9 @@ const dragPreviewSource: React.CSSProperties = {
};
const demos: DemoType[] = [
+ motionBlurTrailDemo,
+ motionBlurCameraDemo,
+ motionBlurHtmlInCanvasDemo,
htmlInCanvasDemo2DBlur,
htmlInCanvasDemoWebGL,
htmlInCanvasDemoWebGPU,
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index 6af614b487..2d4856278d 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -29,6 +29,11 @@ import {HtmlInCanvasDocsDemoWebGL} from './HtmlInCanvasDocsDemoWebGL';
import {HtmlInCanvasDocsDemoWebGPU} from './HtmlInCanvasDocsDemoWebGPU';
import {LightLeakDemoComp} from './LightLeakDemo';
import {LinearBlurDocsDemo} from './LinearBlurDemo';
+import {
+ MotionBlurCameraDocsDemo,
+ MotionBlurHtmlInCanvasDocsDemo,
+ MotionBlurTrailDocsDemo,
+} from './MotionBlurDemo';
import {NoiseComp} from './NoiseDemo';
import {PieDemo} from './Pie';
import {PolygonDemo} from './Polygon';
@@ -1699,3 +1704,42 @@ export const htmlInCanvasDemoWebGPU: DemoType = {
logLevel: 'trace',
options: [],
};
+
+export const motionBlurTrailDemo: DemoType = {
+ comp: MotionBlurTrailDocsDemo,
+ compHeight: 540,
+ compWidth: 960,
+ durationInFrames: 90,
+ fps: 30,
+ id: 'motion-blur-trail',
+ autoPlay: true,
+ controls: true,
+ logLevel: 'info',
+ options: [],
+};
+
+export const motionBlurCameraDemo: DemoType = {
+ comp: MotionBlurCameraDocsDemo,
+ compHeight: 540,
+ compWidth: 960,
+ durationInFrames: 90,
+ fps: 30,
+ id: 'motion-blur-camera',
+ autoPlay: true,
+ controls: true,
+ logLevel: 'info',
+ options: [],
+};
+
+export const motionBlurHtmlInCanvasDemo: DemoType = {
+ comp: MotionBlurHtmlInCanvasDocsDemo,
+ compHeight: 540,
+ compWidth: 960,
+ durationInFrames: 90,
+ fps: 30,
+ id: 'motion-blur-html-in-canvas',
+ autoPlay: true,
+ controls: true,
+ logLevel: 'info',
+ options: [],
+};
diff --git a/packages/docs/docs/motion-blur-guide.mdx b/packages/docs/docs/motion-blur-guide.mdx
new file mode 100644
index 0000000000..2dbae61f6d
--- /dev/null
+++ b/packages/docs/docs/motion-blur-guide.mdx
@@ -0,0 +1,51 @@
+---
+image: /generated/articles-docs-motion-blur-guide.png
+id: motion-blur-guide
+title: Motion blur
+crumb: 'Designing visuals'
+---
+
+# Motion blur
+
+Motion blur shows where an object moved during a frame. [`@remotion/motion-blur`](/docs/motion-blur/index) offers three ways to make it, from a visible trail to a sampled exposure.
+
+<Installation pkg="@remotion/motion-blur" />
+
+| Component | Appearance | Preview |
+| -------------------------------------------------------------------------- | ----------------------------------------------- | ----------------------- |
+| [`<Trail>`](/docs/motion-blur/trail) | Echoes of earlier positions | No special setup |
+| [`<CameraMotionBlur>`](/docs/motion-blur/camera-motion-blur) | Blended layers across part of a frame | No special setup |
+| [`<HtmlInCanvasMotionBlur>`](/docs/motion-blur/html-in-canvas-motion-blur) | Captured pixels averaged across part of a frame | Chrome 149+ with a flag |
+
+Animate the content inside the component with [`useCurrentFrame()`](/docs/use-current-frame). The component samples that animation at different times within a frame. See the [common mistake](/docs/motion-blur/common-mistake) if the blur does not follow your animation.
+
+## Trail
+
+[`<Trail>`](/docs/motion-blur/trail) repeats earlier positions behind the current one. Choose it for a stylized echo or a long streak. It does not aim to reproduce a camera exposure.
+
+<Demo type="motion-blur-trail" />
+
+Set `layers`, `lagInFrames`, and `trailOpacity` to control the number, spacing, and visibility of the echoes.
+
+## Camera motion blur
+
+[`<CameraMotionBlur>`](/docs/motion-blur/camera-motion-blur) blends several copies of the content sampled at different times. It works in regular browsers, but layered blending can change colors and opacity. Use a low `samples` value and inspect the result.
+
+<Demo type="motion-blur-camera" />
+
+Set `shutterAngle` to control the exposure length and `samples` to control smoothness.
+
+## HTML-in-canvas motion blur<AvailableFrom v="4.0.528" />
+
+[`<HtmlInCanvasMotionBlur>`](/docs/motion-blur/html-in-canvas-motion-blur) captures the HTML at multiple fractional frames and averages the pixels in a canvas. This is the state of the art for motion blur in Remotion: it preserves the appearance of the sampled content better than stacking translucent DOM copies.
+
+<Demo type="motion-blur-html-in-canvas" />
+
+Live preview requires Chrome 149 or later with `chrome://flags/#canvas-draw-element` enabled. See the [HTML-in-canvas setup](/docs/html-in-canvas#enabling-the-flag-in-chrome). Other browsers show a rendered video of the demo. Remotion's bundled Chrome supports rendering without manual flag setup. [Nested HTML-in-canvas components](/docs/html-in-canvas#nested-html-in-canvas) are not supported yet.
+
+Set `width` and `height` to the canvas size. Like the camera variant, `shutterAngle` controls exposure length and `samples` controls smoothness. See the [component reference](/docs/motion-blur/html-in-canvas-motion-blur) for defaults and ranges.
+
+## See also
+
+- [`@remotion/motion-blur`](/docs/motion-blur/index)
+- [HTML-in-canvas](/docs/html-in-canvas)
diff --git a/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx b/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
new file mode 100644
index 0000000000..d10c24a541
--- /dev/null
+++ b/packages/docs/docs/motion-blur/html-in-canvas-motion-blur.mdx
@@ -0,0 +1,85 @@
+---
+image: /generated/articles-docs-motion-blur-html-in-canvas-motion-blur.png
+title: '<HtmlInCanvasMotionBlur>'
+slug: html-in-canvas-motion-blur
+crumb: '@remotion/motion-blur'
+---
+
+# &lt;HtmlInCanvasMotionBlur&gt;<AvailableFrom v="4.0.528" />
+
+<ExperimentalBadge>
+ <p>This component uses the experimental HTML-in-canvas browser API.</p>
+</ExperimentalBadge>
+
+`<HtmlInCanvasMotionBlur>` averages snapshots of its children at different points within a frame. It works during preview in a [supported Chrome browser](/docs/html-in-canvas#enabling-the-flag-in-chrome).
+
+```tsx twoslash title="MyComposition.tsx"
+import {HtmlInCanvasMotionBlur} from '@remotion/motion-blur';
+import {useCurrentFrame, useVideoConfig} from 'remotion';
+
+const MovingBox = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <div
+ style={{
+ position: 'absolute',
+ left: frame * 10,
+ top: 300,
+ width: 120,
+ height: 120,
+ backgroundColor: '#ff6b6b',
+ }}
+ />
+ );
+};
+
+export const MyComposition = () => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <HtmlInCanvasMotionBlur width={width} height={height} samples={8} shutterAngle={180}>
+ <MovingBox />
+ </HtmlInCanvasMotionBlur>
+ );
+};
+```
+
+## Props
+
+### `children`
+
+The content to blur. Animate it with [`useCurrentFrame()`](/docs/use-current-frame) so it can be sampled between frames.
+
+### `width`
+
+The canvas width in pixels. Must be a positive integer. Use the composition width from [`useVideoConfig()`](/docs/use-video-config) to cover the full frame.
+
+### `height`
+
+The canvas height in pixels. Must be a positive integer. Use the composition height from [`useVideoConfig()`](/docs/use-video-config) to cover the full frame.
+
+### `samples?`
+
+How many snapshots are averaged. Default: `8`. Accepts an integer from `1` to `64`. Higher values make the blur smoother but cost more work during preview and rendering. `1` produces a sharp image.
+
+### `shutterAngle?`
+
+How long the exposure is, expressed as an angle from `0` to `360`. Default: `180`. At `180`, samples span half a frame centered on the current frame. At `0`, no motion blur is applied. Samples outside the composition are clamped to its first or last frame.
+
+## Preview and rendering
+
+For preview in Studio or a Player, use Chrome 149 or later and enable `chrome://flags/#canvas-draw-element`. See the [HTML-in-canvas setup guide](/docs/html-in-canvas#enabling-the-flag-in-chrome). Remotion's bundled Chrome enables the feature for rendering.
+
+Nested [`<HtmlInCanvas>`](/docs/remotion/html-in-canvas) components are currently unsupported, so children of `<HtmlInCanvasMotionBlur>` cannot contain another `<HtmlInCanvas>` component. Client-side rendering uses the built-in DOM composer for compositions containing this component; [HTML-in-canvas frame capture](/docs/client-side-rendering/html-in-canvas) falls back to that composer.
+
+## Compatibility
+
+<CompatibilityTable chrome firefox={false} safari={false} nodejs="" bun="" serverlessFunctions="" clientSideRendering serverSideRendering player studio hideServers />
+
+## See also
+
+- [Motion blur guide](/docs/motion-blur-guide)
+- [`<CameraMotionBlur>`](/docs/motion-blur/camera-motion-blur)
+- [HTML-in-canvas](/docs/html-in-canvas)
+- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx)
diff --git a/packages/docs/docs/motion-blur/index.mdx b/packages/docs/docs/motion-blur/index.mdx
index 8da6a49181..a81b11f87a 100644
--- a/packages/docs/docs/motion-blur/index.mdx
+++ b/packages/docs/docs/motion-blur/index.mdx
@@ -7,6 +7,8 @@ title: '@remotion/motion-blur'
Higher order components that create a motion blur and trail effects.
+See [Motion blur](/docs/motion-blur-guide) for a comparison of the three approaches and live demos.
+
import {TableOfContents} from './table-of-contents';
<Installation pkg="@remotion/motion-blur" />
diff --git a/packages/docs/docs/motion-blur/table-of-contents.tsx b/packages/docs/docs/motion-blur/table-of-contents.tsx
index c6c4e13b36..5ca775d6ab 100644
--- a/packages/docs/docs/motion-blur/table-of-contents.tsx
+++ b/packages/docs/docs/motion-blur/table-of-contents.tsx
@@ -14,6 +14,10 @@ export const TableOfContents: React.FC = () => {
<strong>{'<CameraMotionBlur>'}</strong>
<div>Add a natural camera motion blur effect to children</div>
</TOCItem>
+ <TOCItem link="/docs/motion-blur/html-in-canvas-motion-blur">
+ <strong>{'<HtmlInCanvasMotionBlur>'}</strong>
+ <div>Sample HTML across a frame for motion blur</div>
+ </TOCItem>
</Grid>
</div>
);
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index 72e20713c3..9e89ffd325 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -565,6 +565,7 @@ const sidebars: SidebarsConfig = {
items: [
'motion-blur/trail',
'motion-blur/camera-motion-blur',
+ 'motion-blur/html-in-canvas-motion-blur',
'motion-blur/common-mistake',
],
},
@@ -1156,6 +1157,7 @@ const sidebars: SidebarsConfig = {
'assets',
'fonts',
'transitioning',
+ 'motion-blur-guide',
'html-in-canvas',
'shaders',
'effects',
@@ -1586,8 +1588,8 @@ const sidebars: SidebarsConfig = {
'miscellaneous/pexels',
'lovable-for-motion-graphics',
],
- },
- {
+ },
+ {
type: 'category',
label: 'Terminology',
link: {
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 9745f09866..7085b75d20 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -5085,6 +5085,15 @@ export const articles = [
noAi: false,
slug: 'miscellaneous/video-formats',
},
+ {
+ id: 'motion-blur-guide',
+ title: 'Motion blur',
+ relativePath: 'docs/motion-blur-guide.mdx',
+ compId: 'articles-docs-motion-blur-guide',
+ crumb: 'Designing visuals',
+ noAi: false,
+ slug: 'motion-blur-guide',
+ },
{
id: 'motion-blur/camera-motion-blur',
title: '<CameraMotionBlur>',
@@ -5103,6 +5112,15 @@ export const articles = [
noAi: false,
slug: 'motion-blur/common-mistake',
},
+ {
+ id: 'motion-blur/html-in-canvas-motion-blur',
+ title: '<HtmlInCanvasMotionBlur>',
+ relativePath: 'docs/motion-blur/html-in-canvas-motion-blur.mdx',
+ compId: 'articles-docs-motion-blur-html-in-canvas-motion-blur',
+ crumb: '@remotion/motion-blur',
+ noAi: false,
+ slug: 'motion-blur/html-in-canvas-motion-blur',
+ },
{
id: 'motion-blur/index',
title: '@remotion/motion-blur',
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index 50522e36c2..3eaa11c2c5 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -2,6 +2,7 @@ import {experts} from '@remotion/promo-pages/dist/experts/experts-data.js';
import {CreateVideoInternals} from 'create-video';
import React from 'react';
import {Composition, Folder, Still} from 'remotion';
+import {MotionBlurHtmlInCanvasLiveDemo} from '../../components/demos/MotionBlurDemo';
import {EffectsBarrelDistortionPreview} from '../../components/effects/effects-barrel-distortion-preview';
import {EffectsBlurPreview} from '../../components/effects/effects-blur-preview';
import {EffectsBrightnessPreview} from '../../components/effects/effects-brightness-preview';
@@ -139,6 +140,14 @@ const DEFAULT_THERMAL_PALETTE = [
export const RemotionRoot: React.FC = () => {
return (
<>
+ <Composition
+ id="motion-blur-html-in-canvas-demo"
+ component={MotionBlurHtmlInCanvasLiveDemo}
+ durationInFrames={90}
+ fps={30}
+ width={960}
+ height={540}
+ />
<Folder name="elements">
<Composition
id="elements-install-playground"
diff --git a/packages/docs/static/generated/articles-docs-motion-blur-guide.png b/packages/docs/static/generated/articles-docs-motion-blur-guide.png
new file mode 100644
index 0000000000..6d43ef34e5
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-motion-blur-guide.png differ
diff --git a/packages/docs/static/generated/articles-docs-motion-blur-html-in-canvas-motion-blur.png b/packages/docs/static/generated/articles-docs-motion-blur-html-in-canvas-motion-blur.png
new file mode 100644
index 0000000000..bdcb711c26
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-motion-blur-html-in-canvas-motion-blur.png differ
diff --git a/packages/docs/static/img/motion-blur-html-in-canvas.mp4 b/packages/docs/static/img/motion-blur-html-in-canvas.mp4
new file mode 100644
index 0000000000..858984b45a
Binary files /dev/null and b/packages/docs/static/img/motion-blur-html-in-canvas.mp4 differ
diff --git a/packages/example/src/HtmlInCanvas/index.tsx b/packages/example/src/HtmlInCanvas/index.tsx
index 5d181047d1..5f10f31730 100644
--- a/packages/example/src/HtmlInCanvas/index.tsx
+++ b/packages/example/src/HtmlInCanvas/index.tsx
@@ -38,6 +38,7 @@ export {
} from './linear-blur-doc';
export {HtmlInCanvasDocsMinimalWebGL} from './minimal-docs-webgl';
export {HtmlInCanvasDocsMinimalWebGPU} from './minimal-docs-webgpu';
+export {HtmlInCanvasMotionBlurExample} from './motion-blur';
export {HtmlInCanvasPixelDensity} from './pixel-density';
export {HtmlInCanvasPrivacy} from './privacy';
export {HtmlInCanvasReactSvg} from './react-svg';
diff --git a/packages/example/src/HtmlInCanvas/motion-blur.tsx b/packages/example/src/HtmlInCanvas/motion-blur.tsx
new file mode 100644
index 0000000000..c4a4061f7d
--- /dev/null
+++ b/packages/example/src/HtmlInCanvas/motion-blur.tsx
@@ -0,0 +1,124 @@
+import {HtmlInCanvasMotionBlur} from '@remotion/motion-blur';
+import React from 'react';
+import {interpolate, useCurrentFrame} from 'remotion';
+
+const panelWidth = 560;
+const panelHeight = 430;
+
+const MovingArtwork: React.FC = () => {
+ const frame = useCurrentFrame();
+ const x = interpolate(frame, [0, 25, 50, 75], [-130, 330, 0, 330], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+ const rotation = interpolate(frame, [0, 75], [-25, 350], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+
+ return (
+ <div style={{position: 'relative', width: panelWidth, height: panelHeight}}>
+ <div
+ style={{
+ position: 'absolute',
+ left: x,
+ top: 116,
+ width: 230,
+ height: 170,
+ borderRadius: 32,
+ background: 'linear-gradient(135deg, #ffcf4a, #fb547a)',
+ boxShadow: '0 20px 45px #0008',
+ rotate: `${rotation}deg`,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ color: '#1a1730',
+ fontFamily: 'sans-serif',
+ fontSize: 72,
+ fontWeight: 900,
+ }}
+ >
+ Aa
+ </div>
+ <div
+ style={{
+ position: 'absolute',
+ left: panelWidth - x - 120,
+ top: 280,
+ width: 92,
+ height: 92,
+ borderRadius: '50%',
+ backgroundColor: '#60e3f1',
+ opacity: 0.7,
+ }}
+ />
+ </div>
+ );
+};
+
+const Panel: React.FC<{label: string; children: React.ReactNode}> = ({
+ label,
+ children,
+}) => {
+ return (
+ <div>
+ <div
+ style={{
+ fontFamily: 'sans-serif',
+ fontSize: 26,
+ fontWeight: 700,
+ marginBottom: 16,
+ color: '#f7f5ff',
+ }}
+ >
+ {label}
+ </div>
+ <div
+ style={{
+ position: 'relative',
+ width: panelWidth,
+ height: panelHeight,
+ overflow: 'hidden',
+ borderRadius: 24,
+ backgroundColor: '#211d39',
+ backgroundImage:
+ 'linear-gradient(45deg, #ffffff13 25%, transparent 25%, transparent 75%, #ffffff13 75%), linear-gradient(45deg, #ffffff13 25%, transparent 25%, transparent 75%, #ffffff13 75%)',
+ backgroundSize: '32px 32px',
+ backgroundPosition: '0 0, 16px 16px',
+ }}
+ >
+ {children}
+ </div>
+ </div>
+ );
+};
+
+export const HtmlInCanvasMotionBlurExample: React.FC = () => {
+ return (
+ <div
+ style={{
+ width: 1280,
+ height: 720,
+ backgroundColor: '#100d22',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ gap: 40,
+ }}
+ >
+ <Panel label="Original">
+ <MovingArtwork />
+ </Panel>
+ <Panel label="HTML-in-canvas motion blur">
+ <HtmlInCanvasMotionBlur
+ width={panelWidth}
+ height={panelHeight}
+ shutterAngle={180}
+ samples={8}
+ >
+ <MovingArtwork />
+ </HtmlInCanvasMotionBlur>
+ </Panel>
+ </div>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index c8bc3ebba6..e613550f96 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -89,6 +89,7 @@ import {
HtmlInCanvasDocsDemo2DBlur,
HtmlInCanvasDocsMinimalWebGL,
HtmlInCanvasDocsMinimalWebGPU,
+ HtmlInCanvasMotionBlurExample,
HtmlInCanvasPixelDensity,
HtmlInCanvasPrivacy,
HtmlInCanvasReactSvg,
@@ -1237,6 +1238,14 @@ export const Index: React.FC = () => {
durationInFrames={100}
/>
<Folder name="html-in-canvas">
+ <Composition
+ id="html-in-canvas-motion-blur"
+ component={HtmlInCanvasMotionBlurExample}
+ fps={30}
+ height={720}
+ width={1280}
+ durationInFrames={76}
+ />
<Composition
id="html-in-canvas-changing-size"
component={HtmlInCanvasDemo}
diff --git a/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
new file mode 100644
index 0000000000..6d96c85187
--- /dev/null
+++ b/packages/motion-blur/src/HtmlInCanvasMotionBlur.tsx
@@ -0,0 +1,140 @@
+import React, {useCallback} from 'react';
+import {
+ Freeze,
+ HtmlInCanvas,
+ type HtmlInCanvasOnPaint,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+
+export type HtmlInCanvasMotionBlurProps = {
+ readonly children: React.ReactNode;
+ readonly width: number;
+ readonly height: number;
+ readonly shutterAngle?: number;
+ readonly samples?: number;
+};
+
+/**
+ * Experimental motion blur that averages separately captured HTML-in-canvas
+ * snapshots of the children at fractional frames. Preview requires Chrome with
+ * the experimental HTML-in-canvas flag enabled. Nested HtmlInCanvas components
+ * are currently unsupported.
+ */
+export const HtmlInCanvasMotionBlur: React.FC<HtmlInCanvasMotionBlurProps> = ({
+ children,
+ width,
+ height,
+ shutterAngle = 180,
+ samples = 8,
+}) => {
+ const frame = useCurrentFrame();
+ const {durationInFrames} = useVideoConfig();
+
+ if (!Number.isInteger(samples) || samples < 1 || samples > 64) {
+ throw new TypeError(
+ `"samples" must be an integer between 1 and 64, but got ${String(samples)}`,
+ );
+ }
+
+ if (
+ typeof shutterAngle !== 'number' ||
+ !Number.isFinite(shutterAngle) ||
+ shutterAngle < 0 ||
+ shutterAngle > 360
+ ) {
+ throw new TypeError(
+ `"shutterAngle" must be between 0 and 360, but got ${String(shutterAngle)}`,
+ );
+ }
+
+ const actualSamples = shutterAngle === 0 ? 1 : samples;
+ const shutterInFrames = shutterAngle / 360;
+
+ const onPaint: HtmlInCanvasOnPaint = useCallback(
+ ({canvas, element, elementImage}) => {
+ const context = canvas.getContext('2d');
+ if (!context) {
+ throw new Error('Failed to acquire 2D context for motion blur');
+ }
+
+ const layoutCanvas = element.parentElement;
+ if (!(layoutCanvas instanceof HTMLCanvasElement)) {
+ throw new Error('Failed to find the HTML-in-canvas layout canvas');
+ }
+
+ const captureElements = Array.from(layoutCanvas.children);
+ if (
+ captureElements.length !== actualSamples ||
+ captureElements[0] !== element
+ ) {
+ throw new Error('Motion blur samples are not ready to paint');
+ }
+
+ context.reset();
+ context.globalCompositeOperation = 'lighter';
+ context.globalAlpha = 1 / actualSamples;
+
+ for (const [index, sampleElement] of captureElements.entries()) {
+ const image =
+ index === 0
+ ? elementImage
+ : layoutCanvas.captureElementImage(sampleElement);
+ try {
+ const sampleTransform = context.drawElementImage(image, 0, 0);
+ if (index === Math.floor(actualSamples / 2)) {
+ (sampleElement as HTMLElement).style.transform =
+ sampleTransform.toString();
+ }
+ } finally {
+ if (index !== 0) {
+ image.close();
+ }
+ }
+ }
+ },
+ [actualSamples],
+ );
+
+ const sampleElements = Array.from({length: actualSamples}, (_, index) => {
+ const sampleFrame = Math.max(
+ 0,
+ Math.min(
+ durationInFrames - 1,
+ frame + ((index + 0.5) / actualSamples - 0.5) * shutterInFrames,
+ ),
+ );
+
+ return (
+ <div
+ key={index}
+ aria-hidden={index !== Math.floor(actualSamples / 2)}
+ // Each sample has its own paint record so it can be captured separately.
+ {...{drawable: ''}}
+ style={{
+ position: 'absolute',
+ inset: 0,
+ width,
+ height,
+ isolation: 'isolate',
+ pointerEvents:
+ index === Math.floor(actualSamples / 2) ? 'auto' : 'none',
+ }}
+ >
+ <Freeze frame={sampleFrame}>{children}</Freeze>
+ </div>
+ );
+ });
+
+ // The root wrapper holds the first sample. The rest must be canvas children.
+ return (
+ <HtmlInCanvas
+ width={width}
+ height={height}
+ onPaint={onPaint}
+ _remotionInternalCanvasSiblings={sampleElements.slice(1)}
+ >
+ {sampleElements[0]}
+ </HtmlInCanvas>
+ );
+};
diff --git a/packages/motion-blur/src/index.ts b/packages/motion-blur/src/index.ts
index 1488a4cc3f..9e880b83ee 100644
--- a/packages/motion-blur/src/index.ts
+++ b/packages/motion-blur/src/index.ts
@@ -1,2 +1,6 @@
export {CameraMotionBlur, CameraMotionBlurProps} from './CameraMotionBlur';
+export {
+ HtmlInCanvasMotionBlur,
+ HtmlInCanvasMotionBlurProps,
+} from './HtmlInCanvasMotionBlur';
export {Trail, TrailProps} from './Trail';
diff --git a/packages/skills/skills/remotion-markup/SKILL.md b/packages/skills/skills/remotion-markup/SKILL.md
index 92b07a85cf..3719de7d34 100644
--- a/packages/skills/skills/remotion-markup/SKILL.md
+++ b/packages/skills/skills/remotion-markup/SKILL.md
@@ -246,6 +246,10 @@ See [cropping.md](cropping.md) if needing to crop the visible rectangle of a com
See [transitions.md](transitions.md) for scene transition patterns.
+## Motion blur
+
+When adding motion blur or a movement trail, read [motion-blur.md](motion-blur.md) to choose the right component and handle preview support.
+
## Visual and pixel effects
When creating a visual effect, consider whether it is feasible using CSS and HTML, or whether a shader is needed.
diff --git a/packages/skills/skills/remotion-markup/motion-blur.md b/packages/skills/skills/remotion-markup/motion-blur.md
new file mode 100644
index 0000000000..b233930931
--- /dev/null
+++ b/packages/skills/skills/remotion-markup/motion-blur.md
@@ -0,0 +1,85 @@
+# Motion blur
+
+Use `@remotion/motion-blur` for frame-driven motion blur. Install it with `npx remotion add @remotion/motion-blur`.
+
+## Choose an approach
+
+| Component | Use when | Tradeoff |
+| -------------------------- | ----------------------------------------------------- | ------------------------------------------------ |
+| `<Trail>` | You want visible echoes or a stylized streak | It is a trail, not a camera exposure |
+| `<CameraMotionBlur>` | You need camera-like blur in regular browser previews | Translucent layers can change colors and opacity |
+| `<HtmlInCanvasMotionBlur>` | You want the most faithful sampled HTML blur | Experimental Chrome support; more work per frame |
+
+`<HtmlInCanvasMotionBlur>` is the state of the art in Remotion for blurring animated HTML. It captures the content at fractional frames and averages its pixels in a canvas. Prefer it when the preview browser supports HTML-in-canvas; use `<CameraMotionBlur>` when broader browser preview support matters.
+
+All three components render multiple versions of their children at different times. Put the animation and its `useCurrentFrame()` call **inside** the blur component. Do not calculate the animated position in a parent and pass an already computed style into it. Use frame-driven animation, not CSS `animation` or `transition`.
+
+## `<Trail>`
+
+`layers` is the number of past copies, `lagInFrames` is the delay between copies and `trailOpacity` controls their strength. Absolutely position the content so copies do not affect each other's layout.
+
+```tsx
+import {Trail} from '@remotion/motion-blur';
+import {useCurrentFrame} from 'remotion';
+
+const MovingBox = () => {
+ const frame = useCurrentFrame();
+ return (
+ <div
+ style={{
+ position: 'absolute',
+ left: frame * 10,
+ top: 200,
+ width: 120,
+ height: 120,
+ backgroundColor: '#ff6b6b',
+ }}
+ />
+ );
+};
+
+export const MyComposition = () => (
+ <Trail layers={12} lagInFrames={0.15} trailOpacity={0.8}>
+ <MovingBox />
+ </Trail>
+);
+```
+
+The next examples reuse `MovingBox` from above.
+
+## `<CameraMotionBlur>`
+
+`shutterAngle` controls exposure length, from `0` to `360` degrees; the default is `180`. `samples` controls smoothness; the default is `10`. Start with 5 to 10 samples and inspect colors because this component blends translucent DOM layers. Absolutely position its children.
+
+```tsx
+import {CameraMotionBlur} from '@remotion/motion-blur';
+
+export const CameraBlur = () => (
+ <CameraMotionBlur shutterAngle={180} samples={8}>
+ <MovingBox />
+ </CameraMotionBlur>
+);
+```
+
+## `<HtmlInCanvasMotionBlur>`
+
+Available from Remotion 4.0.528. Supply the canvas `width` and `height`, usually from `useVideoConfig()`. `shutterAngle` defaults to `180` and accepts `0` to `360`; `0` disables blur. `samples` defaults to `8` and must be an integer from `1` to `64`. More samples can smooth the blur but increase preview and render cost.
+
+```tsx
+import {HtmlInCanvasMotionBlur} from '@remotion/motion-blur';
+import {useVideoConfig} from 'remotion';
+
+export const HtmlInCanvasBlur = () => {
+ const {width, height} = useVideoConfig();
+
+ return (
+ <HtmlInCanvasMotionBlur width={width} height={height} samples={8} shutterAngle={180}>
+ <MovingBox />
+ </HtmlInCanvasMotionBlur>
+ );
+};
+```
+
+For live preview, use Chrome 149 or later and enable `chrome://flags/#canvas-draw-element`. Remotion's bundled Chrome enables the feature during rendering. Do not nest this component with another `<HtmlInCanvas>` component; nested HTML-in-canvas is unsupported. Tell the user about the preview requirement when choosing this variant.
+
+See the [motion blur guide](https://www.remotion.dev/docs/motion-blur-guide) and the [`<HtmlInCanvasMotionBlur>` reference](https://www.remotion.dev/docs/motion-blur/html-in-canvas-motion-blur).