🎥 Make videos programmatically with React
simplify examples
Jonny Burger786c6a785488
diff --git a/bun.lock b/bun.lockindex cbe97914e4..e78daedfcd 100644--- a/bun.lock+++ b/bun.lock@@ -1271,6 +1271,7 @@"@remotion/bundler": "workspace:*","@remotion/cli": "workspace:*","@remotion/eslint-config-internal": "workspace:*",+ "@remotion/google-fonts": "workspace:*","@remotion/lottie": "workspace:*","@remotion/shapes": "workspace:*","@remotion/three": "workspace:*",diff --git a/packages/skills/package.json b/packages/skills/package.jsonindex 7bdf580b7a..76fd7626bd 100644--- a/packages/skills/package.json+++ b/packages/skills/package.json@@ -19,6 +19,7 @@"@remotion/three": "workspace:*","@remotion/cli": "workspace:*","@typescript/native-preview": "catalog:",- "@remotion/lottie": "workspace:*"+ "@remotion/lottie": "workspace:*",+ "@remotion/google-fonts": "workspace:*"}}diff --git a/packages/skills/skills/remotion/rules/assets/charts-bar-chart.tsx b/packages/skills/skills/remotion/rules/assets/charts-bar-chart.tsxindex 0094d1b546..1313ebf598 100644--- a/packages/skills/skills/remotion/rules/assets/charts-bar-chart.tsx+++ b/packages/skills/skills/remotion/rules/assets/charts-bar-chart.tsx@@ -1,5 +1,8 @@+import {loadFont} from '@remotion/google-fonts/Inter';import {AbsoluteFill, spring, useCurrentFrame, useVideoConfig} from 'remotion';+const {fontFamily} = loadFont();+const COLOR_BAR = '#D4AF37';const COLOR_TEXT = '#ffffff';const COLOR_MUTED = '#888888';@@ -141,7 +144,7 @@ export const MyAnimation = () => {padding: 60,display: 'flex',flexDirection: 'column',- fontFamily: 'Inter, sans-serif',+ fontFamily,}}><Title>Gold Price 2024</Title>diff --git a/packages/skills/skills/remotion/rules/assets/text-animations-text-rotation.tsx b/packages/skills/skills/remotion/rules/assets/text-animations-text-rotation.tsxdeleted file mode 100644index 5381360e55..0000000000--- a/packages/skills/skills/remotion/rules/assets/text-animations-text-rotation.tsx+++ /dev/null@@ -1,74 +0,0 @@-import {- AbsoluteFill,- interpolate,- useCurrentFrame,- useVideoConfig,-} from 'remotion';--const WORDS = ['This is a', 'Text rotation example', 'using Remotion!'];--const FONT_SIZE = 120;-const FONT_WEIGHT = 'bold';-const COLOR_TEXT = '#eee';-const COLOR_BACKGROUND = '#1a1a2e';-const BLUR_AMOUNT = 10;--export const MyAnimation = () => {- const frame = useCurrentFrame();- const {fps} = useVideoConfig();-- const WORD_DURATION = 2 * fps;- const FADE_IN_DURATION = 0.5 * fps;- const FADE_OUT_START = 1.5 * fps;-- const currentWordIndex = Math.floor(frame / WORD_DURATION) % WORDS.length;- const frameInWord = frame % WORD_DURATION;-- // Fade in/out animation- const opacity = interpolate(- frameInWord,- [0, FADE_IN_DURATION, FADE_OUT_START, WORD_DURATION],- [0, 1, 1, 0],- {extrapolateRight: 'clamp'},- );-- // Scale animation- const scale = interpolate(- frameInWord,- [0, FADE_IN_DURATION, FADE_OUT_START, WORD_DURATION],- [0.8, 1, 1, 1.2],- {extrapolateRight: 'clamp'},- );-- // Blur animation- const blur = interpolate(- frameInWord,- [0, FADE_IN_DURATION, FADE_OUT_START, WORD_DURATION],- [BLUR_AMOUNT, 0, 0, BLUR_AMOUNT],- {extrapolateRight: 'clamp'},- );-- return (- <AbsoluteFill- style={{- backgroundColor: COLOR_BACKGROUND,- justifyContent: 'center',- alignItems: 'center',- }}- >- <div- style={{- fontSize: FONT_SIZE,- fontWeight: FONT_WEIGHT,- color: COLOR_TEXT,- opacity,- transform: `scale(${scale})`,- filter: `blur(${blur}px)`,- fontFamily: 'system-ui, sans-serif',- }}- >- {WORDS[currentWordIndex]}- </div>- </AbsoluteFill>- );-};diff --git a/packages/skills/skills/remotion/rules/assets/text-animations-typewriter.tsx b/packages/skills/skills/remotion/rules/assets/text-animations-typewriter.tsxindex 9d2dbd3e74..89f62ea0e5 100644--- a/packages/skills/skills/remotion/rules/assets/text-animations-typewriter.tsx+++ b/packages/skills/skills/remotion/rules/assets/text-animations-typewriter.tsx@@ -15,6 +15,8 @@ const CHAR_FRAMES = 2;const CURSOR_BLINK_FRAMES = 16;const PAUSE_SECONDS = 1;+// Ideal composition size: 1280x720+const getTypedText = ({frame,fullText,diff --git a/packages/skills/skills/remotion/rules/assets/text-animations-word-carousel.tsx b/packages/skills/skills/remotion/rules/assets/text-animations-word-carousel.tsxdeleted file mode 100644index 2cfe637e43..0000000000--- a/packages/skills/skills/remotion/rules/assets/text-animations-word-carousel.tsx+++ /dev/null@@ -1,119 +0,0 @@-import {AbsoluteFill, interpolate, useCurrentFrame} from 'remotion';--/*- * Prefix text with rotating words that crossfade with blur.- */--export const MyAnimation = () => {- const frame = useCurrentFrame();-- const COLOR_TEXT = '#7b92c1';- const PREFIX = 'Created for';- const WORDS = ['Creators', 'Marketers', 'Developers', 'Everyone'];-- const PREFIX_FONT_SIZE = 80;- const WORD_FONT_SIZE = 80;- const PREFIX_WEIGHT = 300;- const WORD_WEIGHT = 700;- const WORD_GAP = 20;- const HOLD_DURATION = 32;- const FLIP_DURATION = 18;- const BLUR_AMOUNT = 6;-- const perStep = HOLD_DURATION + FLIP_DURATION;- const totalSteps = WORDS.length;- const currentStep = Math.floor(frame / perStep) % totalSteps;- const nextStep = (currentStep + 1) % totalSteps;- const phase = frame % perStep;- const isFlipping = phase >= HOLD_DURATION;- const flipProgress = isFlipping ? (phase - HOLD_DURATION) / FLIP_DURATION : 0;-- const outOpacity = interpolate(flipProgress, [0, 1], [1, 0], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- });- const inOpacity = interpolate(flipProgress, [0, 1], [0, 1], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- });- const outBlur = interpolate(flipProgress, [0, 1], [0, BLUR_AMOUNT], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- });- const inBlur = interpolate(flipProgress, [0, 1], [BLUR_AMOUNT, 0], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- });-- const longestWord = WORDS.reduce(- (a, b) => (a.length >= b.length ? a : b),- WORDS[0],- );-- return (- <AbsoluteFill- style={{- display: 'flex',- alignItems: 'center',- justifyContent: 'center',- fontFamily: 'Inter, sans-serif',- }}- >- <div- style={{- display: 'flex',- alignItems: 'baseline',- gap: WORD_GAP,- color: COLOR_TEXT,- }}- >- <div style={{fontSize: PREFIX_FONT_SIZE, fontWeight: PREFIX_WEIGHT}}>- {PREFIX}- </div>- <div- style={{- position: 'relative',- fontSize: WORD_FONT_SIZE,- fontWeight: WORD_WEIGHT,- }}- >- {/* Invisible width keeper */}- <div style={{visibility: 'hidden'}}>{longestWord}</div>- {/* Current word (fades out during flip) */}- {!isFlipping && (- <div style={{position: 'absolute', left: 0, top: 0}}>- {WORDS[currentStep]}- </div>- )}- {/* Crossfade during flip */}- {isFlipping && (- <>- <div- style={{- position: 'absolute',- left: 0,- top: 0,- opacity: outOpacity,- filter: `blur(${outBlur}px)`,- }}- >- {WORDS[currentStep]}- </div>- <div- style={{- position: 'absolute',- left: 0,- top: 0,- opacity: inOpacity,- filter: `blur(${inBlur}px)`,- }}- >- {WORDS[nextStep]}- </div>- </>- )}- </div>- </div>- </AbsoluteFill>- );-};diff --git a/packages/skills/skills/remotion/rules/assets/text-animations-word-highlight.tsx b/packages/skills/skills/remotion/rules/assets/text-animations-word-highlight.tsxindex a29b569536..e3929c58a1 100644--- a/packages/skills/skills/remotion/rules/assets/text-animations-word-highlight.tsx+++ b/packages/skills/skills/remotion/rules/assets/text-animations-word-highlight.tsx@@ -1,25 +1,70 @@-import {AbsoluteFill, spring, useCurrentFrame, useVideoConfig} from 'remotion';+import {loadFont} from '@remotion/google-fonts/Inter';+import React from 'react';+import {+ AbsoluteFill,+ spring,+ useCurrentFrame,+ useVideoConfig,+} from 'remotion';/** Highlight a word in a sentence with a spring-animated wipe effect.*/-export const MyAnimation = () => {+// Ideal composition size: 1280x720++const COLOR_BG = '#ffffff';+const COLOR_TEXT = '#000000';+const COLOR_HIGHLIGHT = '#A7C7E7';+const FULL_TEXT = 'This is Remotion.';+const HIGHLIGHT_WORD = 'Remotion';+const FONT_SIZE = 72;+const FONT_WEIGHT = 700;+const HIGHLIGHT_START_FRAME = 30;+const HIGHLIGHT_WIPE_DURATION = 18;++const {fontFamily} = loadFont();++const Highlight: React.FC<{+ word: string;+ color: string;+ delay: number;+ durationInFrames: number;+}> = ({word, color, delay, durationInFrames}) => {const frame = useCurrentFrame();const {fps} = useVideoConfig();- const COLOR_BG = '#ffffff';- const COLOR_TEXT = '#000000';- const COLOR_HIGHLIGHT = '#A7C7E7';-- const FULL_TEXT = 'This is Remotion.';- const HIGHLIGHT_WORD = 'Remotion';+ const highlightProgress = spring({+ fps,+ frame,+ config: {damping: 200},+ delay,+ durationInFrames,+ });+ const scaleX = Math.max(0, Math.min(1, highlightProgress));- const FONT_SIZE = 72;- const FONT_WEIGHT = 700;- const HIGHLIGHT_START_FRAME = 30;- const HIGHLIGHT_WIPE_DURATION = 18;+ return (+ <span style={{position: 'relative', display: 'inline-block'}}>+ <span+ style={{+ position: 'absolute',+ left: 0,+ right: 0,+ top: '50%',+ height: '1.05em',+ transform: `translateY(-50%) scaleX(${scaleX})`,+ transformOrigin: 'left center',+ backgroundColor: color,+ borderRadius: '0.18em',+ zIndex: 0,+ }}+ />+ <span style={{position: 'relative', zIndex: 1}}>{word}</span>+ </span>+ );+};+export const MyAnimation = () => {const highlightIndex = FULL_TEXT.indexOf(HIGHLIGHT_WORD);const hasHighlight = highlightIndex >= 0;const preText = hasHighlight ? FULL_TEXT.slice(0, highlightIndex) : FULL_TEXT;@@ -27,22 +72,13 @@ export const MyAnimation = () => {? FULL_TEXT.slice(highlightIndex + HIGHLIGHT_WORD.length): '';- const highlightProgress = spring({- fps,- frame: frame - HIGHLIGHT_START_FRAME,- config: {damping: 200, stiffness: 180},- durationInFrames: HIGHLIGHT_WIPE_DURATION,- });- const highlightScaleX = Math.max(0, Math.min(1, highlightProgress));-return (<AbsoluteFillstyle={{backgroundColor: COLOR_BG,- display: 'flex',alignItems: 'center',justifyContent: 'center',- fontFamily: 'Inter, sans-serif',+ fontFamily,}}><div@@ -50,32 +86,17 @@ export const MyAnimation = () => {color: COLOR_TEXT,fontSize: FONT_SIZE,fontWeight: FONT_WEIGHT,- lineHeight: 1.15,- whiteSpace: 'pre-wrap',}}>{hasHighlight ? (<><span>{preText}</span>- <span style={{position: 'relative', display: 'inline-block'}}>- <span- style={{- position: 'absolute',- left: 0,- right: 0,- top: '50%',- height: '1.05em',- transform: `translateY(-50%) scaleX(${highlightScaleX})`,- transformOrigin: 'left center',- backgroundColor: COLOR_HIGHLIGHT,- borderRadius: '0.18em',- zIndex: 0,- }}- />- <span style={{position: 'relative', zIndex: 1}}>- {HIGHLIGHT_WORD}- </span>- </span>+ <Highlight+ word={HIGHLIGHT_WORD}+ color={COLOR_HIGHLIGHT}+ delay={HIGHLIGHT_START_FRAME}+ durationInFrames={HIGHLIGHT_WIPE_DURATION}+ /><span>{postText}</span></>) : (diff --git a/packages/skills/src/Root.tsx b/packages/skills/src/Root.tsxindex ca4c410351..da094aa3cd 100644--- a/packages/skills/src/Root.tsx+++ b/packages/skills/src/Root.tsx@@ -1,21 +1,11 @@import {Composition} from 'remotion';import {MyAnimation as BarChartAnimation} from '../skills/remotion/rules/assets/charts-bar-chart';-import {MyAnimation as TextRotationAnimation} from '../skills/remotion/rules/assets/text-animations-text-rotation';import {MyAnimation as TypewriterAnimation} from '../skills/remotion/rules/assets/text-animations-typewriter';-import {MyAnimation as WordCarouselAnimation} from '../skills/remotion/rules/assets/text-animations-word-carousel';import {MyAnimation as WordHighlightAnimation} from '../skills/remotion/rules/assets/text-animations-word-highlight';export const RemotionRoot = () => {return (<>- <Composition- id="TextRotation"- component={TextRotationAnimation}- durationInFrames={180}- fps={30}- width={1920}- height={1080}- /><Compositionid="BarChart"component={BarChartAnimation}@@ -44,14 +34,6 @@ export const RemotionRoot = () => {width={1080}height={1080}/>- <Composition- id="WordCarousel"- component={WordCarouselAnimation}- durationInFrames={200}- fps={30}- width={1080}- height={1080}- /></>);};