Skip to content

🎥 Make videos programmatically with React

move to lottie

Jonny Burger899f55f91c7e
diff --git a/packages/docs/public/Utope-nature-5s.mp3 b/packages/docs/public/Utope-nature-5s.mp3
deleted file mode 100644
index 23f5e2de20..0000000000
Binary files a/packages/docs/public/Utope-nature-5s.mp3 and /dev/null differ
diff --git a/packages/docs/public/fire-0.5x.webm b/packages/docs/public/fire-0.5x.webm
deleted file mode 100644
index 353f82996c..0000000000
Binary files a/packages/docs/public/fire-0.5x.webm and /dev/null differ
diff --git a/packages/docs/public/fire-1x.webm b/packages/docs/public/fire-1x.webm
deleted file mode 100644
index 0dde1ab309..0000000000
Binary files a/packages/docs/public/fire-1x.webm and /dev/null differ
diff --git a/packages/docs/public/fire-2x.webm b/packages/docs/public/fire-2x.webm
deleted file mode 100644
index 063ecb35fb..0000000000
Binary files a/packages/docs/public/fire-2x.webm and /dev/null differ
diff --git a/packages/docs/public/melting-0.5x.webm b/packages/docs/public/melting-0.5x.webm
deleted file mode 100644
index b55e358096..0000000000
Binary files a/packages/docs/public/melting-0.5x.webm and /dev/null differ
diff --git a/packages/docs/public/melting-1x.webm b/packages/docs/public/melting-1x.webm
deleted file mode 100644
index bd746d55bb..0000000000
Binary files a/packages/docs/public/melting-1x.webm and /dev/null differ
diff --git a/packages/docs/public/melting-2x.webm b/packages/docs/public/melting-2x.webm
deleted file mode 100644
index 123898955e..0000000000
Binary files a/packages/docs/public/melting-2x.webm and /dev/null differ
diff --git a/packages/docs/public/partying-face-0.5x.webm b/packages/docs/public/partying-face-0.5x.webm
deleted file mode 100644
index 813deb2456..0000000000
Binary files a/packages/docs/public/partying-face-0.5x.webm and /dev/null differ
diff --git a/packages/docs/public/partying-face-1x.webm b/packages/docs/public/partying-face-1x.webm
deleted file mode 100644
index ec0fbd1ee5..0000000000
Binary files a/packages/docs/public/partying-face-1x.webm and /dev/null differ
diff --git a/packages/docs/public/partying-face-2x.webm b/packages/docs/public/partying-face-2x.webm
deleted file mode 100644
index ccfa08e3c8..0000000000
Binary files a/packages/docs/public/partying-face-2x.webm and /dev/null differ
diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
index fda62da25e..70739b7703 100644
--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx
@@ -143,7 +143,7 @@ export const HomepageVideoComp: React.FC<DemoPlayerProps> = ({
b.free();
c.free();
};
- }, [audioSrc]);
+ }, []);
return (
<AbsoluteFill
diff --git a/packages/docs/src/remotion/HomepageVideo/emoji/DisplayedEmoji.tsx b/packages/docs/src/remotion/HomepageVideo/emoji/DisplayedEmoji.tsx
index 440b07b691..92d57a5e02 100644
--- a/packages/docs/src/remotion/HomepageVideo/emoji/DisplayedEmoji.tsx
+++ b/packages/docs/src/remotion/HomepageVideo/emoji/DisplayedEmoji.tsx
@@ -1,38 +1,70 @@
import type {EmojiName} from '@remotion/animated-emoji';
-import {AnimatedEmoji, getAvailableEmojis} from '@remotion/animated-emoji';
-import React from 'react';
-import {useVideoConfig} from 'remotion';
+import type {LottieAnimationData} from '@remotion/lottie';
+import {getLottieMetadata, Lottie} from '@remotion/lottie';
+import React, {useEffect, useMemo, useState} from 'react';
+import {
+ cancelRender,
+ continueRender,
+ delayRender,
+ useVideoConfig,
+} from 'remotion';
export const DisplayedEmoji: React.FC<{
readonly emoji: EmojiName;
}> = ({emoji}) => {
- const partyDuration = getAvailableEmojis().find(
- (e) => e.name === emoji,
- )!.durationInSeconds;
+ const [data, setData] = useState<LottieAnimationData | null>(null);
const {durationInFrames, fps} = useVideoConfig();
- const ratio = durationInFrames / fps / partyDuration;
- const closestInteger = Math.round(ratio);
+ const src = useMemo(() => {
+ if (emoji === 'melting') {
+ return 'https://fonts.gstatic.com/s/e/notoemoji/latest/1fae0/lottie.json';
+ }
+
+ if (emoji === 'partying-face') {
+ return 'https://fonts.gstatic.com/s/e/notoemoji/latest/1f973/lottie.json';
+ }
+
+ if (emoji === 'fire') {
+ return 'https://fonts.gstatic.com/s/e/notoemoji/latest/1f525/lottie.json';
+ }
+
+ throw new Error('Unknown emoji');
+ }, [emoji]);
+
+ const [handle] = useState(() => delayRender());
+
+ useEffect(() => {
+ fetch(src)
+ .then((res) => res.json())
+ .then((json) => {
+ setData(json);
+ continueRender(handle);
+ })
+ .catch((err) => {
+ cancelRender(err);
+ });
+ }, [handle, src]);
+
+ if (!data) {
+ return null;
+ }
+
+ const animDurtion = getLottieMetadata(data)?.durationInSeconds as number;
+ const ratio = durationInFrames / fps / animDurtion;
+ const closestInteger = ratio;
const closestRatio = closestInteger / ratio;
return (
- <AnimatedEmoji
+ <Lottie
style={{
height: 100,
width: '100%',
display: 'flex',
justifyContent: 'center',
}}
- emoji={emoji}
- scale="0.5"
+ loop
+ animationData={data}
playbackRate={closestRatio}
- onError={(e) => {
- if (e.message.includes('PIPELINE_ERROR')) {
- return;
- }
-
- throw e;
- }}
/>
);
};
diff --git a/packages/docs/static/Utope-nature-5s.mp3 b/packages/docs/static/Utope-nature-5s.mp3
deleted file mode 100644
index 23f5e2de20..0000000000
Binary files a/packages/docs/static/Utope-nature-5s.mp3 and /dev/null differ
diff --git a/packages/docs/static/fire-0.5x.mp4 b/packages/docs/static/fire-0.5x.mp4
deleted file mode 100644
index d2353e0500..0000000000
Binary files a/packages/docs/static/fire-0.5x.mp4 and /dev/null differ
diff --git a/packages/docs/static/fire-0.5x.webm b/packages/docs/static/fire-0.5x.webm
deleted file mode 100644
index 353f82996c..0000000000
Binary files a/packages/docs/static/fire-0.5x.webm and /dev/null differ
diff --git a/packages/docs/static/fire-1x.mp4 b/packages/docs/static/fire-1x.mp4
deleted file mode 100644
index c63ca60a6e..0000000000
Binary files a/packages/docs/static/fire-1x.mp4 and /dev/null differ
diff --git a/packages/docs/static/fire-1x.webm b/packages/docs/static/fire-1x.webm
deleted file mode 100644
index 0dde1ab309..0000000000
Binary files a/packages/docs/static/fire-1x.webm and /dev/null differ
diff --git a/packages/docs/static/fire-2x.mp4 b/packages/docs/static/fire-2x.mp4
deleted file mode 100644
index 539b380440..0000000000
Binary files a/packages/docs/static/fire-2x.mp4 and /dev/null differ
diff --git a/packages/docs/static/fire-2x.webm b/packages/docs/static/fire-2x.webm
deleted file mode 100644
index 063ecb35fb..0000000000
Binary files a/packages/docs/static/fire-2x.webm and /dev/null differ
diff --git a/packages/docs/static/melting-0.5x.mp4 b/packages/docs/static/melting-0.5x.mp4
deleted file mode 100644
index 6580477532..0000000000
Binary files a/packages/docs/static/melting-0.5x.mp4 and /dev/null differ
diff --git a/packages/docs/static/melting-0.5x.webm b/packages/docs/static/melting-0.5x.webm
deleted file mode 100644
index b55e358096..0000000000
Binary files a/packages/docs/static/melting-0.5x.webm and /dev/null differ
diff --git a/packages/docs/static/melting-1x.mp4 b/packages/docs/static/melting-1x.mp4
deleted file mode 100644
index 3de3f3eb71..0000000000
Binary files a/packages/docs/static/melting-1x.mp4 and /dev/null differ
diff --git a/packages/docs/static/melting-1x.webm b/packages/docs/static/melting-1x.webm
deleted file mode 100644
index bd746d55bb..0000000000
Binary files a/packages/docs/static/melting-1x.webm and /dev/null differ
diff --git a/packages/docs/static/melting-2x.mp4 b/packages/docs/static/melting-2x.mp4
deleted file mode 100644
index 717e5cf375..0000000000
Binary files a/packages/docs/static/melting-2x.mp4 and /dev/null differ
diff --git a/packages/docs/static/melting-2x.webm b/packages/docs/static/melting-2x.webm
deleted file mode 100644
index 123898955e..0000000000
Binary files a/packages/docs/static/melting-2x.webm and /dev/null differ
diff --git a/packages/docs/static/partying-face-0.5x.mp4 b/packages/docs/static/partying-face-0.5x.mp4
deleted file mode 100644
index 3cf97a8bcf..0000000000
Binary files a/packages/docs/static/partying-face-0.5x.mp4 and /dev/null differ
diff --git a/packages/docs/static/partying-face-0.5x.webm b/packages/docs/static/partying-face-0.5x.webm
deleted file mode 100644
index 813deb2456..0000000000
Binary files a/packages/docs/static/partying-face-0.5x.webm and /dev/null differ
diff --git a/packages/docs/static/partying-face-1x.mp4 b/packages/docs/static/partying-face-1x.mp4
deleted file mode 100644
index 70ff4504a6..0000000000
Binary files a/packages/docs/static/partying-face-1x.mp4 and /dev/null differ
diff --git a/packages/docs/static/partying-face-1x.webm b/packages/docs/static/partying-face-1x.webm
deleted file mode 100644
index ec0fbd1ee5..0000000000
Binary files a/packages/docs/static/partying-face-1x.webm and /dev/null differ
diff --git a/packages/docs/static/partying-face-2x.mp4 b/packages/docs/static/partying-face-2x.mp4
deleted file mode 100644
index a3c9c5d854..0000000000
Binary files a/packages/docs/static/partying-face-2x.mp4 and /dev/null differ
diff --git a/packages/docs/static/partying-face-2x.webm b/packages/docs/static/partying-face-2x.webm
deleted file mode 100644
index ccfa08e3c8..0000000000
Binary files a/packages/docs/static/partying-face-2x.webm and /dev/null differ