Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/example`: Add Rive to experimental controls showcase + effects testbed

Jonny Burgerf8d03fead494
diff --git a/packages/example/src/ExperimentalControls/index.tsx b/packages/example/src/ExperimentalControls/index.tsx
index 555e87b105..dcddaa275f 100644
--- a/packages/example/src/ExperimentalControls/index.tsx
+++ b/packages/example/src/ExperimentalControls/index.tsx
@@ -1,6 +1,7 @@
import {Gif} from '@remotion/gif';
import {LightLeak} from '@remotion/light-leaks';
import {Audio, Video} from '@remotion/media';
+import {RemotionRiveCanvas} from '@remotion/rive';
import {Starburst} from '@remotion/starburst';
import React from 'react';
import {
@@ -231,6 +232,17 @@ export const ExperimentalControlsShowcase: React.FC = () => {
<Tile title="Solid">
<Solid color="red" width={100} height={100} />
</Tile>
+ <Tile title="RemotionRiveCanvas">
+ <RemotionRiveCanvas
+ src="https://cdn.rive.app/animations/vehicles.riv"
+ style={{
+ width: '100%',
+ height: '100%',
+ translate: '0px 20px',
+ scale: 0.95,
+ }}
+ />
+ </Tile>
</div>
</AbsoluteFill>
);
diff --git a/packages/example/src/Rive/RiveEffects.tsx b/packages/example/src/Rive/RiveEffects.tsx
new file mode 100644
index 0000000000..d2d08946f1
--- /dev/null
+++ b/packages/example/src/Rive/RiveEffects.tsx
@@ -0,0 +1,210 @@
+import {blur} from '@remotion/effects/blur';
+import {halftone} from '@remotion/effects/halftone';
+import {tint} from '@remotion/effects/tint';
+import {wave} from '@remotion/effects/wave';
+import {RemotionRiveCanvas} from '@remotion/rive';
+import {StudioInternals} from '@remotion/studio';
+import React from 'react';
+import {AbsoluteFill, useCurrentFrame, useVideoConfig} from 'remotion';
+
+const RIVE_SRC = 'https://cdn.rive.app/animations/vehicles.riv';
+
+const Tile: React.FC<{
+ readonly title: string;
+ readonly subtitle: string;
+ readonly children: React.ReactNode;
+}> = ({title, subtitle, children}) => {
+ return (
+ <div
+ style={{
+ flex: 1,
+ display: 'flex',
+ flexDirection: 'column',
+ border: '1px solid #1f2937',
+ borderRadius: 12,
+ overflow: 'hidden',
+ backgroundColor: '#000',
+ minWidth: 0,
+ minHeight: 0,
+ }}
+ >
+ <div
+ style={{
+ padding: '10px 14px',
+ backgroundColor: '#0b1220',
+ borderBottom: '1px solid #1f2937',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 2,
+ }}
+ >
+ <div
+ style={{
+ fontFamily: 'monospace',
+ fontSize: 18,
+ color: '#f8fafc',
+ fontWeight: 700,
+ }}
+ >
+ {title}
+ </div>
+ <div
+ style={{
+ fontFamily: 'monospace',
+ fontSize: 12,
+ color: '#94a3b8',
+ }}
+ >
+ {subtitle}
+ </div>
+ </div>
+ <div
+ style={{
+ flex: 1,
+ position: 'relative',
+ overflow: 'hidden',
+ }}
+ >
+ {children}
+ </div>
+ </div>
+ );
+};
+
+const tileRiveStyle: React.CSSProperties = {
+ width: '100%',
+ height: '100%',
+};
+
+const AnimatedBlurRive: React.FC = () => {
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+
+ // Pulse the blur radius between 0 and 18px to verify that the canvas is
+ // redrawn when an effect parameter changes, even between Rive frames.
+ const t = (frame / fps) * Math.PI * 2 * 0.35;
+ const blurRadius = 9 + 9 * Math.sin(t);
+
+ return (
+ <RemotionRiveCanvas
+ src={RIVE_SRC}
+ style={tileRiveStyle}
+ _experimentalEffects={[blur({radius: blurRadius})]}
+ />
+ );
+};
+
+const AnimatedWaveRive: React.FC = () => {
+ const frame = useCurrentFrame();
+ const evolution = frame * 0.2;
+
+ return (
+ <RemotionRiveCanvas
+ src={RIVE_SRC}
+ style={tileRiveStyle}
+ _experimentalEffects={[
+ wave({
+ amplitude: 22,
+ wavelength: 180,
+ evolution,
+ sliceWidth: 4,
+ background: '#020617',
+ }),
+ ]}
+ />
+ );
+};
+
+const StackedRive: React.FC = () => {
+ const frame = useCurrentFrame();
+ const evolution = frame * 0.2;
+
+ return (
+ <RemotionRiveCanvas
+ src={RIVE_SRC}
+ style={tileRiveStyle}
+ _experimentalEffects={[
+ tint({color: '#ff5fa2', amount: 0.4}),
+ wave({
+ amplitude: 12,
+ wavelength: 160,
+ evolution,
+ sliceWidth: 4,
+ background: '#020617',
+ }),
+ blur({radius: 6}),
+ ]}
+ />
+ );
+};
+
+const Comp: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: '#020617',
+ padding: 24,
+ gap: 16,
+ display: 'flex',
+ flexDirection: 'column',
+ }}
+ >
+ <div
+ style={{
+ fontFamily: 'monospace',
+ fontSize: 28,
+ color: '#f8fafc',
+ fontWeight: 700,
+ }}
+ >
+ @remotion/rive effects testbed
+ </div>
+ <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
+ <Tile title="baseline" subtitle="no effects">
+ <RemotionRiveCanvas src={RIVE_SRC} style={tileRiveStyle} />
+ </Tile>
+ <Tile title="tint" subtitle="color: '#ff5fa2', amount: 0.6">
+ <RemotionRiveCanvas
+ src={RIVE_SRC}
+ style={tileRiveStyle}
+ _experimentalEffects={[tint({color: '#ff5fa2', amount: 0.6})]}
+ />
+ </Tile>
+ <Tile title="halftone" subtitle="circles, dotSize 12, on luminance">
+ <RemotionRiveCanvas
+ src={RIVE_SRC}
+ style={tileRiveStyle}
+ _experimentalEffects={[
+ halftone({
+ shape: 'circle',
+ dotSize: 12,
+ dotSpacing: 12,
+ color: '#000',
+ }),
+ ]}
+ />
+ </Tile>
+ </div>
+ <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
+ <Tile title="blur" subtitle="separable Gaussian, animated 0β†’18">
+ <AnimatedBlurRive />
+ </Tile>
+ <Tile title="wave" subtitle="amplitude 22, evolution from frame">
+ <AnimatedWaveRive />
+ </Tile>
+ <Tile title="tint + wave + blur" subtitle="effect chain">
+ <StackedRive />
+ </Tile>
+ </div>
+ </AbsoluteFill>
+ );
+};
+
+export const RiveEffectsTestbed = StudioInternals.createComposition({
+ component: Comp,
+ id: 'rive-effects-testbed',
+ width: 1920,
+ height: 1080,
+ durationInFrames: 300,
+ fps: 30,
+});
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 15657c48c2..b920c55756 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -86,6 +86,7 @@ import ReactSvg from './ReactSvg';
import InfinityVideo from './ReallyLongVideo';
import RemoteVideo from './RemoteVideo';
import {RetryDelayRender} from './RetryDelayRender';
+import {RiveEffectsTestbed} from './Rive/RiveEffects';
import RiveVehicle from './Rive/RiveExample';
import {ScalePath} from './ScalePath';
import {SchemaTest, schemaTestSchema} from './SchemaTest';
@@ -1663,6 +1664,7 @@ export const Index: React.FC = () => {
}}
durationInFrames={150}
/>
+ <RiveEffectsTestbed />
</Folder>
<Folder name="Premount">
<Composition