Remotion Rule: Calculate Metadata
Remotion skill rule: Dynamically set composition duration, dimensions, and props. Part of the official Remotion Agent Skill for programmatic video in React.
What it is
The Calculate Metadata rule is part of the official Remotion Agent Skill for programmatic video creation in React. It teaches AI agents how to use the calculateMetadata API to dynamically set composition duration, dimensions, and props before rendering, based on external data like video files, API responses, or user input.
This rule targets developers using Remotion with AI coding agents (Claude Code, Cursor, Codex) who need compositions that adapt their properties based on runtime data.
How it saves time or tokens
Without calculateMetadata, you would hardcode duration and dimensions or write custom logic to fetch media metadata and pass it through multiple layers. The calculateMetadata API centralizes this in one async function attached to the Composition component. AI agents with this rule installed produce correct calculateMetadata implementations on the first attempt instead of generating incorrect patterns.
How to use
- Install the Remotion skills:
npx skills add remotion-dev/skills
- The rule activates automatically when working with calculateMetadata in a Remotion project.
- Define calculateMetadata on a Composition:
import { CalculateMetadataFunction } from 'remotion';
const calculateMetadata: CalculateMetadataFunction<Props> = async ({
props,
}) => {
const duration = await getVideoDuration(props.videoSrc);
return {
durationInFrames: Math.ceil(duration * 30),
};
};
Example
Setting composition duration based on a video file:
import { Composition, CalculateMetadataFunction } from 'remotion';
type Props = { videoSrc: string };
const calculateMetadata: CalculateMetadataFunction<Props> = async ({
props,
}) => {
const durationInSeconds = await getVideoDuration(props.videoSrc);
return {
durationInFrames: Math.ceil(durationInSeconds * 30),
width: 1920,
height: 1080,
};
};
export const Root = () => (
<Composition
id='MyVideo'
component={MyComponent}
durationInFrames={300}
fps={30}
width={1920}
height={1080}
defaultProps={{ videoSrc: 'https://example.com/video.mp4' }}
calculateMetadata={calculateMetadata}
/>
);
Related on TokRepo
- Featured workflows — discover more Remotion skills and video tools
- Coding tools — AI-assisted development tools
Common pitfalls
- The calculateMetadata function must return a plain object; returning a class instance or Promise-wrapped object causes silent failures
- Default values for durationInFrames, width, and height on the Composition component are still required even when calculateMetadata overrides them
- Async operations in calculateMetadata run during the render preparation phase; slow API calls delay the entire render pipeline
Frequently Asked Questions
calculateMetadata runs during render preparation, before any frames are rendered. It is called once per render and receives the current props. The returned values override the static durationInFrames, width, height, and props defined on the Composition component.
Yes. calculateMetadata is an async function. You can fetch data from APIs, read file metadata, or perform any async operation. The render waits for the function to resolve before proceeding.
Throw an error inside the function. Remotion catches it and displays the error in the Studio or CLI output. You can also use try/catch to provide fallback values for non-critical failures.
Yes. Return a props field in the result object to override or extend the default props. This is useful for enriching props with fetched data before the component renders.
Yes. The Remotion Player component supports calculateMetadata. It runs the function when the component mounts and updates the player dimensions and duration accordingly.
Citations (3)
- Remotion Docs— calculateMetadata API for dynamic composition properties
- Remotion GitHub— Remotion is a framework for programmatic video in React
- Remotion Skills— Remotion Agent Skill for AI-assisted video development
Related on TokRepo
Source & Thanks
Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule:
calculate-metadata
Part of the Remotion AI Skill collection on TokRepo.
Discussion
Related Assets
Claude-Flow — Multi-Agent Orchestration for Claude Code
Layers swarm and hive-mind multi-agent orchestration on top of Claude Code with 64 specialized agents, SQLite memory, and parallel execution.
ccusage — Real-Time Token Cost Tracker for Claude Code
CLI that reads ~/.claude logs and breaks down Claude Code token spend by day, session, and project — pluggable into your statusline.
SuperClaude — Workflow Framework for Claude Code
Adds 16+ slash commands, 9 cognitive personas, and a smart flag system to Claude Code in one pipx install.