Skip to content

🎥 Make videos programmatically with React

wip: new motion blur

Marcus Stenbeck6af3efa97c57
diff --git a/packages/docs/components/CameraMotionBlurExample/CameraMotionBlurExample.tsx b/packages/docs/components/CameraMotionBlurExample/CameraMotionBlurExample.tsx
new file mode 100644
index 0000000000..05a3e5df47
--- /dev/null
+++ b/packages/docs/components/CameraMotionBlurExample/CameraMotionBlurExample.tsx
@@ -0,0 +1,169 @@
+import { Player } from "@remotion/player";
+import React, { useState } from "react";
+import {
+ AbsoluteFill,
+ Freeze,
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+
+import { CameraMotionBlur } from "@remotion/motion-blur";
+
+const square: React.CSSProperties = {
+ height: 150,
+ width: 150,
+ background: `linear-gradient(217deg, rgba(255,0,0,1), rgba(255,0,0,0) 70.71%), linear-gradient(127deg, rgba(0,255,0,1), rgba(0,255,0,0) 70.71%), linear-gradient(336deg, rgba(0,0,255,1), rgba(0,0,255,0) 70.71%)`,
+ borderRadius: 14,
+ fontSize: 100,
+ fontWeight: "bold",
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+};
+
+const row: React.CSSProperties = {
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ flexWrap: "wrap",
+};
+
+const spacer: React.CSSProperties = {
+ width: 40,
+};
+
+export const Square: React.FC = () => {
+ const frame = useCurrentFrame();
+ const { fps, height } = useVideoConfig();
+ const spr = spring({
+ fps,
+ frame,
+ config: {
+ damping: 200,
+ },
+ durationInFrames: 60,
+ });
+
+ const rotate = interpolate(spr, [0, 1], [Math.PI, 0]);
+ const y = interpolate(spr, [0, 1], [height, 0]);
+
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ transform: `translateY(${y}px) rotate(${rotate}rad)`,
+ }}
+ >
+ <div style={square}>A</div>
+ </AbsoluteFill>
+ );
+};
+
+const MyComposition = ({
+ shutterAngle,
+ iterations,
+}: {
+ shutterAngle: number;
+ iterations: number;
+}) => {
+ return (
+ <AbsoluteFill
+ style={{
+ flexDirection: "row",
+ }}
+ >
+ <div style={{ flex: 1, position: "relative" }}>
+ <AbsoluteFill style={{ padding: 30 }}>
+ <h1>Still</h1>
+ </AbsoluteFill>
+ <Freeze frame={20}>
+ <CameraMotionBlur shutterAngle={shutterAngle} iterations={iterations}>
+ <Square />
+ </CameraMotionBlur>
+ </Freeze>
+ </div>
+ <div
+ style={{
+ width: 1,
+ background: "var(--ifm-color-emphasis-300)",
+ }}
+ />
+ <div style={{ flex: 1, position: "relative" }}>
+ <AbsoluteFill style={{ padding: 30 }}>
+ <h1>Animation</h1>
+ </AbsoluteFill>
+ <CameraMotionBlur shutterAngle={shutterAngle} iterations={iterations}>
+ <Square />
+ </CameraMotionBlur>
+ </div>
+ </AbsoluteFill>
+ );
+};
+
+export const CameraMotionBlurExample: React.FC = () => {
+ const [shutterAngle, setShutterAngle] = useState(180);
+ const [iterations, setIterations] = useState(10);
+
+ return (
+ <div>
+ <Player
+ component={MyComposition}
+ compositionWidth={1280}
+ compositionHeight={720}
+ durationInFrames={70}
+ fps={30}
+ style={{
+ width: "100%",
+ border: "1px solid var(--ifm-color-emphasis-300)",
+ borderRadius: "var(--ifm-pre-border-radius)",
+ }}
+ inputProps={{
+ shutterAngle,
+ iterations,
+ }}
+ autoPlay
+ loop
+ />
+ <br />
+ <div style={{ ...row, fontSize: 20 }}>
+ <label style={row}>
+ <input
+ type="range"
+ min={0}
+ max={360}
+ step={1}
+ value={shutterAngle}
+ style={{ width: 90, marginRight: 8, padding: 8 }}
+ onChange={(e) => setShutterAngle(Number(e.target.value))}
+ />
+ <code>
+ shutterAngle={"{"}
+ {shutterAngle}
+ {"}"}
+ </code>
+ </label>
+ <div style={spacer} />
+
+ <label style={row}>
+ <input
+ type="range"
+ min={1}
+ max={100}
+ step={1}
+ value={iterations}
+ style={{ width: 90, marginRight: 8 }}
+ onChange={(e) => setIterations(Number(e.target.value))}
+ />
+ <code>
+ iterations={"{"}
+ {iterations}
+ {"}"}
+ </code>
+ </label>
+ </div>
+ </div>
+ );
+};
diff --git a/packages/docs/components/TableOfContents/motion-blur.tsx b/packages/docs/components/TableOfContents/motion-blur.tsx
index 84586f7085..7bb0b1e4b5 100644
--- a/packages/docs/components/TableOfContents/motion-blur.tsx
+++ b/packages/docs/components/TableOfContents/motion-blur.tsx
@@ -6,9 +6,13 @@ export const TableOfContents: React.FC = () => {
return (
<div>
<Grid>
- <TOCItem link="/docs/motion-blur/motion-blur">
- <strong>{"<MotionBlur>"}</strong>
- <div>Add a motion blur effect to children</div>
+ <TOCItem link="/docs/motion-blur/trail">
+ <strong>{"<Trail>"}</strong>
+ <div>Add a trail effect to children</div>
+ </TOCItem>
+ <TOCItem link="/docs/motion-blur/camera-motion-blur">
+ <strong>{"<CameraMotionBlur>"}</strong>
+ <div>Add a natural camera motion blur effect to children</div>
</TOCItem>
</Grid>
</div>
diff --git a/packages/docs/components/MotionBlurExample/MotionBlurExample.tsx b/packages/docs/components/TrailExample/TrailExample.tsx
similarity index 74%
rename from packages/docs/components/MotionBlurExample/MotionBlurExample.tsx
rename to packages/docs/components/TrailExample/TrailExample.tsx
index 6bba24d568..fb11d3e8b0 100644
--- a/packages/docs/components/MotionBlurExample/MotionBlurExample.tsx
+++ b/packages/docs/components/TrailExample/TrailExample.tsx
@@ -9,19 +9,25 @@ import {
useVideoConfig,
} from "remotion";
-import { MotionBlur } from "@remotion/motion-blur";
+import { Trail } from "@remotion/motion-blur";
const square: React.CSSProperties = {
height: 150,
width: 150,
backgroundColor: "#0b84f3",
borderRadius: 14,
+ fontSize: 100,
+ fontWeight: "bold",
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
};
const row: React.CSSProperties = {
display: "flex",
flexDirection: "row",
alignItems: "center",
+ flexWrap: "wrap",
};
const spacer: React.CSSProperties = {
@@ -51,19 +57,21 @@ export const Square: React.FC = () => {
transform: `translateY(${y}px) rotate(${rotate}rad)`,
}}
>
- <div style={square} />
+ <div style={square}>A</div>
</AbsoluteFill>
);
};
const MyComposition = ({
- blurOpacity,
+ trailOpacity,
layers,
lagInFrames,
+ hideOriginal,
}: {
- blurOpacity: number;
+ trailOpacity: number;
layers: number;
lagInFrames: number;
+ hideOriginal: boolean;
}) => {
return (
<AbsoluteFill
@@ -76,13 +84,14 @@ const MyComposition = ({
<h1>Still</h1>
</AbsoluteFill>
<Freeze frame={38}>
- <MotionBlur
- blurOpacity={blurOpacity}
+ <Trail
+ trailOpacity={trailOpacity}
lagInFrames={lagInFrames}
layers={layers}
+ hideOriginal={hideOriginal}
>
<Square />
- </MotionBlur>
+ </Trail>
</Freeze>
</div>
<div
@@ -95,21 +104,23 @@ const MyComposition = ({
<AbsoluteFill style={{ padding: 30 }}>
<h1>Animation</h1>
</AbsoluteFill>
- <MotionBlur
- blurOpacity={blurOpacity}
+ <Trail
+ trailOpacity={trailOpacity}
lagInFrames={lagInFrames}
layers={layers}
+ hideOriginal={hideOriginal}
>
<Square />
- </MotionBlur>
+ </Trail>
</div>
</AbsoluteFill>
);
};
-export const MotionBlurExample: React.FC = () => {
- const [blurOpacity, setBlurOpacity] = useState(1);
+export const TrailExample: React.FC = () => {
+ const [trailOpacity, setTrailOpacity] = useState(1);
const [lagInFrames, setFrameDelay] = useState(0.3);
+ const [hideOriginal, setHideOriginal] = useState(false);
const [layers, setLayers] = useState(50);
return (
@@ -126,9 +137,10 @@ export const MotionBlurExample: React.FC = () => {
borderRadius: "var(--ifm-pre-border-radius)",
}}
inputProps={{
- blurOpacity,
+ trailOpacity,
lagInFrames,
layers,
+ hideOriginal,
}}
autoPlay
loop
@@ -158,13 +170,13 @@ export const MotionBlurExample: React.FC = () => {
min={0}
max={1}
step={0.05}
- value={blurOpacity}
+ value={trailOpacity}
style={{ width: 90, marginRight: 8 }}
- onChange={(e) => setBlurOpacity(Number(e.target.value))}
+ onChange={(e) => setTrailOpacity(Number(e.target.value))}
/>
<code>
- blurOpacity={"{"}
- {blurOpacity}
+ trailOpacity={"{"}
+ {trailOpacity}
{"}"}
</code>
</label>
@@ -186,6 +198,22 @@ export const MotionBlurExample: React.FC = () => {
{"}"}
</code>
</label>
+
+ <div style={spacer} />
+
+ <label style={row}>
+ <input
+ type="checkbox"
+ checked={hideOriginal}
+ style={{ marginRight: 8, padding: 8 }}
+ onChange={(e) => setHideOriginal(e.target.checked)}
+ />
+ <code>
+ hideOriginal={"{"}
+ {JSON.stringify(hideOriginal)}
+ {"}"}
+ </code>
+ </label>
</div>
</div>
);
diff --git a/packages/docs/docs/motion-blur/camera-motion-blur.md b/packages/docs/docs/motion-blur/camera-motion-blur.md
new file mode 100644
index 0000000000..4b2f1dfdb9
--- /dev/null
+++ b/packages/docs/docs/motion-blur/camera-motion-blur.md
@@ -0,0 +1,71 @@
+---
+title: "<CameraMotionBlur>"
+slug: camera-motion-blur
+---
+
+import { CameraMotionBlurExample } from "../../components/CameraMotionBlurExample/CameraMotionBlurExample";
+
+import {TableOfContents} from '../../components/TableOfContents/motion-blur';
+
+```twoslash include example
+const BlueSquare: React.FC = () => <div></div>
+// - BlueSquare
+```
+
+TODO
+
+For this technique to work, the children must be absolutely positioned so many layers can be created without influencing the layout.
+You can use the [`<AbsoluteFill>`](/docs/absolute-fill) component to absolutely position content.
+
+## API
+
+Wrap your content in `<CameraMotionBlur>` and optionally add the following props in addition.
+
+### `iterations (optional)`
+
+TODO
+
+### `shutterAngle (optional)`
+
+TODO
+
+## Example usage
+
+```tsx twoslash
+// @include: example-BlueSquare
+// ---cut---
+import { CameraMotionBlur } from "@remotion/motion-blur";
+import { AbsoluteFill } from "remotion";
+
+export const MyComposition = () => {
+ return (
+ <CameraMotionBlur>
+ <AbsoluteFill
+ style={{
+ backgroundColor: "white",
+ justifyContent: "center",
+ alignItems: "center",
+ }}
+ >
+ <BlueSquare />
+ </AbsoluteFill>
+ </CameraMotionBlur>
+ );
+};
+```
+
+## Demo
+
+<CameraMotionBlurExample />
+
+## Functions
+
+<TableOfContents />
+
+## Credits
+
+TODO
+
+## See also
+
+- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/motion-blur/src/CameraMotionBlur.tsx)
diff --git a/packages/docs/docs/motion-blur/index.md b/packages/docs/docs/motion-blur/index.md
index c3e427a7a9..61c4250c43 100644
--- a/packages/docs/docs/motion-blur/index.md
+++ b/packages/docs/docs/motion-blur/index.md
@@ -4,7 +4,7 @@ title: "@remotion/motion-blur"
_Available from v3.2.31_
-A high order component that creates a motion blur effect.
+Higher order components that create a motion blur and trail effects.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
diff --git a/packages/docs/docs/motion-blur/motion-blur.md b/packages/docs/docs/motion-blur/motion-blur.md
index 6922290e28..70131758c8 100644
--- a/packages/docs/docs/motion-blur/motion-blur.md
+++ b/packages/docs/docs/motion-blur/motion-blur.md
@@ -3,73 +3,8 @@ title: "<MotionBlur>"
slug: motion-blur
---
-import { MotionBlurExample } from "../../components/MotionBlurExample/MotionBlurExample";
-
import {TableOfContents} from '../../components/TableOfContents/motion-blur';
-```twoslash include example
-const BlueSquare: React.FC = () => <div></div>
-// - BlueSquare
-```
-
-The `<MotionBlur>` component duplicates it's children and adds a time offset to each layer in order to create a motion blur effect.
-
-For this technique to work, the children must be absolutely positioned so many layers can be created without influencing the layout.
-You can use the [`<AbsoluteFill>`](/docs/absolute-fill) component to absolutely position content.
-
-## API
-
-Wrap your content in `<MotionBlur>` and add the following props in addition.
-
-### `layers`
-
-How many layers are added below the content. Must be an integer
-
-### `lagInFrames`
-
-How many frames each layer is lagging behind the last one. Can also a floating point number.
-
-### `blurOpacity`
-
-The highest opacity of a layer. The lowest opacity is 0 and layers intbetween get interpolated.
-
-## Example usage
-
-```tsx twoslash
-// @include: example-BlueSquare
-// ---cut---
-import { MotionBlur } from "@remotion/motion-blur";
-import { AbsoluteFill } from "remotion";
-
-export const MyComposition = () => {
- return (
- <MotionBlur layers={50} lagInFrames={0.1} blurOpacity={1}>
- <AbsoluteFill
- style={{
- backgroundColor: "white",
- justifyContent: "center",
- alignItems: "center",
- }}
- >
- <BlueSquare />
- </AbsoluteFill>
- </MotionBlur>
- );
-};
-```
-
-## Demo
-
-<MotionBlurExample />
-
-## Functions
+_Deprecated_. Use `<Trail>` or `<CameraMotionBlur>` instead.
<TableOfContents />
-
-## Credits
-
-This technique was invented and first implemented by [@UmungoBungo](https://github.com/UmungoBungo).
-
-## See also
-
-- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/motion-blur/src/MotionBlur.tsx)
diff --git a/packages/docs/docs/motion-blur/trail.md b/packages/docs/docs/motion-blur/trail.md
new file mode 100644
index 0000000000..f5d7f3af07
--- /dev/null
+++ b/packages/docs/docs/motion-blur/trail.md
@@ -0,0 +1,82 @@
+---
+title: "<Trail>"
+slug: trail
+---
+
+import { TrailExample } from "../../components/TrailExample/TrailExample";
+
+import {TableOfContents} from '../../components/TableOfContents/motion-blur';
+
+```twoslash include example
+const BlueSquare: React.FC = () => <div></div>
+// - BlueSquare
+```
+
+The `<Trail>` component duplicates it's children and adds a time offset to each layer in order to create a trail effect.
+
+For this technique to work, the children must be absolutely positioned so many layers can be created without influencing the layout.
+You can use the [`<AbsoluteFill>`](/docs/absolute-fill) component to absolutely position content.
+
+## API
+
+Wrap your content in `<Trail>` and add the following props in addition.
+
+### `layers`
+
+How many layers are added below the content. Must be an integer
+
+### `lagInFrames`
+
+How many frames each layer is lagging behind the last one. Can also a floating point number.
+
+### `trailOpacity`
+
+The highest opacity of a layer. The lowest opacity is 0 and layers intbetween get interpolated.
+
+### `hideOriginal`
+
+Default: `false`
+
+- If `true` it will render the original children on top of the trail.
+- If `false` only the trail will be rendered.
+
+## Example usage
+
+```tsx twoslash
+// @include: example-BlueSquare
+// ---cut---
+import { Trail } from "@remotion/motion-blur";
+import { AbsoluteFill } from "remotion";
+
+export const MyComposition = () => {
+ return (
+ <Trail layers={50} lagInFrames={0.1} trailOpacity={1}>
+ <AbsoluteFill
+ style={{
+ backgroundColor: "white",
+ justifyContent: "center",
+ alignItems: "center",
+ }}
+ >
+ <BlueSquare />
+ </AbsoluteFill>
+ </Trail>
+ );
+};
+```
+
+## Demo
+
+<TrailExample />
+
+## Functions
+
+<TableOfContents />
+
+## Credits
+
+This technique was invented and first implemented by [@UmungoBungo](https://github.com/UmungoBungo).
+
+## See also
+
+- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/motion-blur/src/Trail.tsx)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 241b2ff57b..88af7c2469 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -150,7 +150,7 @@ module.exports = {
type: "doc",
id: "motion-blur/index",
},
- items: ["motion-blur/motion-blur"],
+ items: ["motion-blur/trail", "motion-blur/camera-motion-blur"],
},
{
type: "category",
diff --git a/packages/motion-blur/src/CameraMotionBlur.tsx b/packages/motion-blur/src/CameraMotionBlur.tsx
new file mode 100644
index 0000000000..11598aa804
--- /dev/null
+++ b/packages/motion-blur/src/CameraMotionBlur.tsx
@@ -0,0 +1,81 @@
+import React from 'react';
+import {AbsoluteFill, Freeze, useCurrentFrame} from 'remotion';
+
+export type CameraMotionBlurProps = {
+ children: React.ReactNode;
+ shutterAngle?: number;
+ iterations?: number;
+};
+
+export const CameraMotionBlur: React.FC<CameraMotionBlurProps> = ({
+ children,
+ shutterAngle = 180,
+ iterations = 10,
+}: CameraMotionBlurProps) => {
+ const currentFrame = useCurrentFrame();
+
+ if (
+ typeof iterations !== 'number' ||
+ Number.isNaN(iterations) ||
+ !Number.isFinite(iterations)
+ ) {
+ throw new TypeError(
+ `"iterations" must be a number, but got ${JSON.stringify(iterations)}`
+ );
+ }
+
+ if (iterations % 1 !== 0) {
+ throw new TypeError(
+ `"iterations" must be an integer, but got ${JSON.stringify(iterations)}`
+ );
+ }
+
+ if (iterations < 0) {
+ throw new TypeError(
+ `"iterations" must be non-negative, but got ${JSON.stringify(iterations)}`
+ );
+ }
+
+ if (
+ typeof shutterAngle !== 'number' ||
+ Number.isNaN(shutterAngle) ||
+ !Number.isFinite(shutterAngle)
+ ) {
+ throw new TypeError(
+ `"shutterAngle" must be a number, but got ${JSON.stringify(shutterAngle)}`
+ );
+ }
+
+ if (shutterAngle < 0 || shutterAngle > 360) {
+ throw new TypeError(
+ `"shutterAngle" must be between 0 and 360, but got ${JSON.stringify(
+ shutterAngle
+ )}`
+ );
+ }
+
+ const shutterFraction = shutterAngle / 360;
+
+ return (
+ <AbsoluteFill style={{isolation: 'isolate'}}>
+ {new Array(iterations).fill(true).map((_, i) => {
+ const iteration = i + 1;
+ const iterationFrameOffset = shutterFraction * (iteration / iterations);
+ return (
+ <AbsoluteFill
+ key={`frame-${i.toString()}`}
+ style={{
+ // @ts-ignore 'plus-lighter' is assignable, google "MDN plus-lighter"
+ mixBlendMode: 'plus-lighter',
+ opacity: 1 / iterations,
+ }}
+ >
+ <Freeze frame={currentFrame - iterationFrameOffset}>
+ {children}
+ </Freeze>
+ </AbsoluteFill>
+ );
+ })}
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/motion-blur/src/MotionBlur.tsx b/packages/motion-blur/src/MotionBlur.tsx
index 7cf896ff16..ed59e2d75e 100644
--- a/packages/motion-blur/src/MotionBlur.tsx
+++ b/packages/motion-blur/src/MotionBlur.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import {AbsoluteFill, Freeze, useCurrentFrame} from 'remotion';
+import {Trail} from './Trail';
export type MotionBlurProps = {
children: React.ReactNode;
@@ -9,35 +9,9 @@ export type MotionBlurProps = {
};
export const MotionBlur: React.FC<MotionBlurProps> = ({
- children,
- layers,
- lagInFrames,
blurOpacity,
+ ...rest
}: MotionBlurProps) => {
- const frame = useCurrentFrame();
-
- if (
- typeof layers !== 'number' ||
- Number.isNaN(layers) ||
- !Number.isFinite(layers)
- ) {
- throw new TypeError(
- `"layers" must be a number, but got ${JSON.stringify(layers)}`
- );
- }
-
- if (layers % 1 !== 0) {
- throw new TypeError(
- `"layers" must be an integer, but got ${JSON.stringify(layers)}`
- );
- }
-
- if (layers < 0) {
- throw new TypeError(
- `"layers" must be non-negative, but got ${JSON.stringify(layers)}`
- );
- }
-
if (
typeof blurOpacity !== 'number' ||
Number.isNaN(blurOpacity) ||
@@ -48,31 +22,5 @@ export const MotionBlur: React.FC<MotionBlurProps> = ({
);
}
- if (
- typeof lagInFrames !== 'number' ||
- Number.isNaN(lagInFrames) ||
- !Number.isFinite(lagInFrames)
- ) {
- throw new TypeError(
- `"lagInFrames" must be a number, but got ${JSON.stringify(lagInFrames)}`
- );
- }
-
- return (
- <AbsoluteFill>
- {new Array(layers).fill(true).map((_, i) => {
- return (
- <AbsoluteFill
- key={`frame-${i.toString()}`}
- style={{
- opacity: blurOpacity - ((i + 1) / layers) * blurOpacity,
- }}
- >
- <Freeze frame={frame - lagInFrames * i}>{children}</Freeze>
- </AbsoluteFill>
- );
- })}
- {children}
- </AbsoluteFill>
- );
+ return <Trail {...rest} trailOpacity={blurOpacity} />;
};
diff --git a/packages/motion-blur/src/Trail.tsx b/packages/motion-blur/src/Trail.tsx
new file mode 100644
index 0000000000..12d87540bf
--- /dev/null
+++ b/packages/motion-blur/src/Trail.tsx
@@ -0,0 +1,80 @@
+import React from 'react';
+import {AbsoluteFill, Freeze, useCurrentFrame} from 'remotion';
+
+export type TrailProps = {
+ children: React.ReactNode;
+ layers: number;
+ lagInFrames: number;
+ trailOpacity: number;
+ hideOriginal?: boolean;
+};
+
+export const Trail: React.FC<TrailProps> = ({
+ children,
+ layers,
+ lagInFrames,
+ trailOpacity,
+ hideOriginal = false,
+}: TrailProps) => {
+ const frame = useCurrentFrame();
+
+ if (
+ typeof layers !== 'number' ||
+ Number.isNaN(layers) ||
+ !Number.isFinite(layers)
+ ) {
+ throw new TypeError(
+ `"layers" must be a number, but got ${JSON.stringify(layers)}`
+ );
+ }
+
+ if (layers % 1 !== 0) {
+ throw new TypeError(
+ `"layers" must be an integer, but got ${JSON.stringify(layers)}`
+ );
+ }
+
+ if (layers < 0) {
+ throw new TypeError(
+ `"layers" must be non-negative, but got ${JSON.stringify(layers)}`
+ );
+ }
+
+ if (
+ typeof trailOpacity !== 'number' ||
+ Number.isNaN(trailOpacity) ||
+ !Number.isFinite(trailOpacity)
+ ) {
+ throw new TypeError(
+ `"trailOpacity" must be a number, but got ${JSON.stringify(trailOpacity)}`
+ );
+ }
+
+ if (
+ typeof lagInFrames !== 'number' ||
+ Number.isNaN(lagInFrames) ||
+ !Number.isFinite(lagInFrames)
+ ) {
+ throw new TypeError(
+ `"lagInFrames" must be a number, but got ${JSON.stringify(lagInFrames)}`
+ );
+ }
+
+ return (
+ <AbsoluteFill>
+ {new Array(layers).fill(true).map((_, i) => {
+ return (
+ <AbsoluteFill
+ key={`frame-${i.toString()}`}
+ style={{
+ opacity: trailOpacity - ((i + 1) / layers) * trailOpacity,
+ }}
+ >
+ <Freeze frame={frame - lagInFrames * i}>{children}</Freeze>
+ </AbsoluteFill>
+ );
+ })}
+ {!hideOriginal && children}
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/motion-blur/src/index.ts b/packages/motion-blur/src/index.ts
index cc70c36900..03b584d48a 100644
--- a/packages/motion-blur/src/index.ts
+++ b/packages/motion-blur/src/index.ts
@@ -1 +1,6 @@
+export {CameraMotionBlur, CameraMotionBlurProps} from './CameraMotionBlur';
+/**
+ * @deprecated `<MotionBlur/>` component is renamed to `<Trail/>`
+ */
export {MotionBlur, MotionBlurProps} from './MotionBlur';
+export {Trail, TrailProps} from './Trail';