Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: remotion-best-practices3description: Best practices for Remotion - Video creation in React4metadata:5tags: remotion, video, react, animation, composition6---78## When to use910Use this skills whenever you are dealing with Remotion code to obtain the domain-specific knowledge.1112## New project setup1314When in an empty folder or workspace with no existing Remotion project, scaffold one using:1516```bash17npx create-video@latest --yes --blank --no-tailwind my-video18```1920Replace `my-video` with a suitable project name.2122## Designing a video2324Animate properties using `useCurrentFrame()` and `interpolate()`. Use Easing to customize the timing of the animation.2526```tsx27import { useCurrentFrame, Easing } from "remotion";2829export const FadeIn = () => {30const frame = useCurrentFrame();31const { fps } = useVideoConfig();3233const opacity = interpolate(frame, [0, 2 * fps], [0, 1], {34extrapolateRight: "clamp",35extrapolateLeft: "clamp",36easing: Easing.bezier(0.16, 1, 0.3, 1),37});3839return <div style={{ opacity }}>Hello World!</div>;40};41```4243CSS transitions or animations are FORBIDDEN - they will not render correctly.44Tailwind animation class names are FORBIDDEN - they will not render correctly.4546Place assets in the `public/` folder at your project root.4748Use `staticFile()` to reference files from the `public/` folder.4950Add images using the `<Img>` component:5152```tsx53import { Img, staticFile } from "remotion";5455export const MyComposition = () => {56return <Img src={staticFile("logo.png")} style={{ width: 100, height: 100 }} />;57};58```5960Add videos using the `<Video>` component from `@remotion/media`:6162```tsx63import { Video } from "@remotion/media";64import { staticFile } from "remotion";6566export const MyComposition = () => {67return <Video src={staticFile("video.mp4")} style={{ opacity: 0.5 }} />;68};69```7071Add audio using the `<Audio>` component from `@remotion/media`:7273```tsx74import { Audio } from "@remotion/media";75import { staticFile } from "remotion";7677export const MyComposition = () => {78return <Audio src={staticFile("audio.mp3")} />;79};80```8182Assets can be also referenced as remote URLs:8384```tsx85import { Video } from "@remotion/media";8687export const MyComposition = () => {88return <Video src="https://remotion.media/video.mp4" />89};90```9192To delay content wrap it in `<Sequence>` and use `from`.93To limit the duration of an element, use `durationInFrames` of `<Sequence>`.94`<Sequence>` by default is an absolute fill. For inline content, use `layout="none"`.9596```tsx97import { Sequence } from "remotion";9899export const Title = () => {100const frame = useCurrentFrame();101const { fps } = useVideoConfig();102103const opacity = interpolate(frame, [0, 2 * fps], [0, 1], {104extrapolateRight: "clamp",105extrapolateLeft: "clamp",106easing: Easing.bezier(0.16, 1, 0.3, 1),107});108109return <div style={{ opacity }}>Title</div>;110};111112export const Subtitle = () => {113return <div>Subtitle</div>;114};115116const Main = () => {117const {fps} = useVideoConfig();118119return (120<AbsoluteFill>121<Sequence>122<Background />123</Sequence>124<Sequence from={1 * fps} durationInFrames={2 * fps} layout="none">125<Title />126</Sequence>127<Sequence from={2 * fps} durationInFrames={2 * fps} layout="none">128<Subtitle />129</Sequence>130</AbsoluteFill>131);132}133```134135The width, height, fps, and duration of a video is defined in `src/Root.tsx`:136137```tsx138import { Composition } from "remotion";139import { MyComposition } from "./MyComposition";140141export const RemotionRoot = () => {142return (143<Composition144id="MyComposition"145component={MyComposition}146durationInFrames={100}147fps={30}148width={1080}149height={1080}150/>151);152};153```154155Metadata can also be calculated dynamically:156157```tsx158import { Composition, CalculateMetadataFunction } from "remotion";159import { MyComposition, MyCompositionProps } from "./MyComposition";160161const calculateMetadata: CalculateMetadataFunction<162MyCompositionProps163> = async ({ props, abortSignal }) => {164const data = await fetch(`https://api.example.com/video/${props.videoId}`, {165signal: abortSignal,166}).then((res) => res.json());167168return {169durationInFrames: Math.ceil(data.duration * 30),170props: {171...props,172videoUrl: data.url,173},174width: 1080,175height: 1080,176};177};178179export const RemotionRoot = () => {180return (181<Composition182id="MyComposition"183component={MyComposition}184fps={30}185width={1080}186height={1080}187defaultProps={{ videoId: "abc123" }}188calculateMetadata={calculateMetadata}189/>190);191};192```193194## Starting preview195196Start the Remotion Studio to preview a video:197198```bash199npx remotion studio200```201202## Optional: one-frame render check203204You can render a single frame with the CLI to sanity-check layout, colors, or timing.205Skip it for trivial edits, pure refactors, or when you already have enough confidence from Studio or prior renders.206207```bash208npx remotion still [composition-id] --scale=0.25 --frame=30209```210211At 30 fps, `--frame=30` is the one-second mark (`--frame` is zero-based).212213## Captions214215When dealing with captions or subtitles, load the [./rules/subtitles.md](./rules/subtitles.md) file for more information.216217## Using FFmpeg218219For some video operations, such as trimming videos or detecting silence, FFmpeg should be used. Load the [./rules/ffmpeg.md](./rules/ffmpeg.md) file for more information.220221## Silence detection222223When needing to detect and trim silent segments from video or audio files, load the [./rules/silence-detection.md](./rules/silence-detection.md) file.224225## Audio visualization226227When needing to visualize audio (spectrum bars, waveforms, bass-reactive effects), load the [./rules/audio-visualization.md](./rules/audio-visualization.md) file for more information.228229## Sound effects230231When needing to use sound effects, load the [./rules/sfx.md](./rules/sfx.md) file for more information.232233## 3D content234235See [rules/3d.md](rules/3d.md) for 3D content in Remotion using Three.js and React Three Fiber.236237## Advanced audio238239See [rules/audio.md](rules/audio.md) for advanced audio features like trimming, volume, speed, pitch.240241## Dynamic duration, dimensions and data242243See [rules/calculate-metadata.md](rules/calculate-metadata.md) for dynamically set composition duration, dimensions, and props.244245## Advanced compositions246247See [rules/compositions.md](rules/compositions.md) for how to define stills, folders, default props and for how to nest compositions.248249## Google Fonts250251Is the recommended way to load fonts in Remotion. See [rules/google-fonts.md](rules/google-fonts.md) for how to load Google Fonts.252253## Local fonts254255See [rules/local-fonts.md](rules/local-fonts.md) for how to load local fonts.256257## Getting audio duration258259See [rules/get-audio-duration.md](rules/get-audio-duration.md) for getting the duration of an audio file in seconds with Mediabunny.260261## Getting video dimensions262263See [rules/get-video-dimensions.md](rules/get-video-dimensions.md) for getting the width and height of a video file with Mediabunny.264265## Getting video duration266267See [rules/get-video-duration.md](rules/get-video-duration.md) for getting the duration of a video file in seconds with Mediabunny.268269## GIFs270271See [rules/gifs.md](rules/gifs.md) for how to display GIFs synchronized with Remotion's timeline.272273## Advanced Images274275See [rules/images.md](rules/images.md) for sizing and positioning images, dynamic image paths, and getting image dimensions.276277## Light leaks278279See [rules/light-leaks.md](rules/light-leaks.md) for light leak overlay effects using `@remotion/light-leaks`.280281## Lottie animations282283See [rules/lottie.md](rules/lottie.md) for embedding Lottie animations in Remotion.284285## HTML in canvas286287See [rules/html-in-canvas.md](rules/html-in-canvas.md) if you need to render HTML into a `<canvas>` to apply 2D or WebGL effects via `<HtmlInCanvas>`.288289## Measuring DOM nodes290291See [rules/measuring-dom-nodes.md](rules/measuring-dom-nodes.md) for measuring DOM element dimensions in Remotion.292293## Measuring text294295See [rules/measuring-text.md](rules/measuring-text.md) for measuring text dimensions, fitting text to containers, and checking overflow.296297## Advanced sequencing298299See [rules/sequencing.md](rules/sequencing.md) for more sequencing patterns - delay, trim, limit duration of items.300301## TailwindCSS302303See [rules/tailwind.md](rules/tailwind.md) for using TailwindCSS in Remotion.304305## Text animations306307See [rules/text-animations.md](rules/text-animations.md) for typography and text animation patterns.308309## Advanced timing310311See [rules/timing.md](rules/timing.md) for advanced timing with `interpolate` and Bézier easing, and springs.312313## Transitions314315See [rules/transitions.md](rules/transitions.md) for scene transition patterns.316317## Transparent videos318319See [rules/transparent-videos.md](rules/transparent-videos.md) for rendering out a video with transparency.320321## Trimming322323See [rules/trimming.md](rules/trimming.md) for trimming patterns - cutting the beginning or end of animations.324325## Advanced Videos326327See [rules/videos.md](rules/videos.md) for advanced knowledge about embedding videos - trimming, volume, speed, looping, pitch.328329## Parameterized videos330331See [rules/parameters.md](rules/parameters.md) for making a composition parametrizable by adding a Zod schema.332333## Maps334335For simple maps with little flyovers, consider using static map images.336For complex maps with animated routes or flyovers, load the maps rule: [rules/maplibre.md](rules/maplibre.md)337338## Voiceover339340See [rules/voiceover.md](rules/voiceover.md) for adding AI-generated voiceover to Remotion compositions using ElevenLabs TTS.341