SkillsMar 29, 2026·2 min read

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.

TL;DR
Use calculateMetadata to dynamically set Remotion composition duration, dimensions, and props based on input data.
§01

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.

§02

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.

§03

How to use

  1. Install the Remotion skills:
npx skills add remotion-dev/skills
  1. The rule activates automatically when working with calculateMetadata in a Remotion project.
  1. 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),
  };
};
§04

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}
  />
);
§05

Related on TokRepo

§06

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

When does calculateMetadata run?+

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.

Can calculateMetadata fetch data from APIs?+

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.

How do I handle errors in calculateMetadata?+

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.

Can I change props inside calculateMetadata?+

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.

Does calculateMetadata work with the Remotion Player?+

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
🙏

Source & Thanks

Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule: calculate-metadata

Part of the Remotion AI Skill collection on TokRepo.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets