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.
rules/compositions.md
1---2name: compositions3description: Defining compositions, stills, folders, default props and dynamic metadata4metadata:5tags: composition, still, folder, props, metadata6---78A `<Composition>` defines the component, width, height, fps and duration of a renderable video.910It normally is placed in the `src/Root.tsx` file.1112```tsx13import { Composition } from "remotion";14import { MyComposition } from "./MyComposition";1516export const RemotionRoot = () => {17return (18<Composition19id="MyComposition"20component={MyComposition}21durationInFrames={100}22fps={30}23width={1080}24height={1080}25/>26);27};28```2930## Default Props3132Pass `defaultProps` to provide initial values for your component.33Values must be JSON-serializable (`Date`, `Map`, `Set`, and `staticFile()` are supported).3435```tsx36import { Composition } from "remotion";37import { MyComposition, MyCompositionProps } from "./MyComposition";3839export const RemotionRoot = () => {40return (41<Composition42id="MyComposition"43component={MyComposition}44durationInFrames={100}45fps={30}46width={1080}47height={1080}48defaultProps={49{50title: "Hello World",51color: "#ff0000",52} satisfies MyCompositionProps53}54/>55);56};57```5859Use `type` declarations for props rather than `interface` to ensure `defaultProps` type safety.6061## Folders6263Use `<Folder>` to organize compositions in the sidebar.64Folder names can only contain letters, numbers, and hyphens.6566```tsx67import { Composition, Folder } from "remotion";6869export const RemotionRoot = () => {70return (71<>72<Folder name="Marketing">73<Composition id="Promo" /* ... */ />74<Composition id="Ad" /* ... */ />75</Folder>76<Folder name="Social">77<Folder name="Instagram">78<Composition id="Story" /* ... */ />79<Composition id="Reel" /* ... */ />80</Folder>81</Folder>82</>83);84};85```8687## Stills8889Use `<Still>` for single-frame images. It does not require `durationInFrames` or `fps`.9091```tsx92import { Still } from "remotion";93import { Thumbnail } from "./Thumbnail";9495export const RemotionRoot = () => {96return (97<Still id="Thumbnail" component={Thumbnail} width={1280} height={720} />98);99};100```101102## Calculate Metadata103104Use `calculateMetadata` to make dimensions, duration, or props dynamic based on data.105106```tsx107import { Composition, CalculateMetadataFunction } from "remotion";108import { MyComposition, MyCompositionProps } from "./MyComposition";109110const calculateMetadata: CalculateMetadataFunction<111MyCompositionProps112> = async ({ props, abortSignal }) => {113const data = await fetch(`https://api.example.com/video/${props.videoId}`, {114signal: abortSignal,115}).then((res) => res.json());116117return {118durationInFrames: Math.ceil(data.duration * 30),119props: {120...props,121videoUrl: data.url,122},123};124};125126export const RemotionRoot = () => {127return (128<Composition129id="MyComposition"130component={MyComposition}131durationInFrames={100} // Placeholder, will be overridden132fps={30}133width={1080}134height={1080}135defaultProps={{ videoId: "abc123" }}136calculateMetadata={calculateMetadata}137/>138);139};140```141142The function can return `props`, `durationInFrames`, `width`, `height`, `fps`, and codec-related defaults. It runs once before rendering begins.143144## Nesting compositions within another145146To add a composition within another composition, you can use the `<Sequence>` component with a `width` and `height` prop to specify the size of the composition.147148```tsx149<AbsoluteFill>150<Sequence width={COMPOSITION_WIDTH} height={COMPOSITION_HEIGHT}>151<CompositionComponent />152</Sequence>153</AbsoluteFill>154```155