# 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. ## Install Save the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## Quick Use ```bash npx skills add remotion-dev/skills ``` This rule activates automatically when working with calculate metadata in a Remotion project. --- ## Intro Dynamically set composition duration, dimensions, and props. Part of the [Remotion AI Skill](https://tokrepo.com/en/workflows/57997ead-c8fa-409c-916f-28bbc0adc8d9) — the official Agent Skill for programmatic video creation in React. **Best for**: Developers using Remotion for calculate metadata **Works with**: Claude Code, OpenAI Codex, Cursor --- ## Rule Content # Using calculateMetadata Use `calculateMetadata` on a `` to dynamically set duration, dimensions, and transform props before rendering. ```tsx ``` ## Setting duration based on a video Use the [`getVideoDuration`](./get-video-duration.md) and [`getVideoDimensions`](./get-video-dimensions.md) skills to get the video duration and dimensions: ```tsx import { CalculateMetadataFunction } from "remotion"; import { getVideoDuration } from "./get-video-duration"; const calculateMetadata: CalculateMetadataFunction = async ({ props, }) => { const durationInSeconds = await getVideoDuration(props.videoSrc); return { durationInFrames: Math.ceil(durationInSeconds * 30), }; }; ``` ## Matching dimensions of a video Use the [`getVideoDimensions`](./get-video-dimensions.md) skill to get the video dimensions: ```tsx import { CalculateMetadataFunction } from "remotion"; import { getVideoDuration } from "./get-video-duration"; import { getVideoDimensions } from "./get-video-dimensions"; const calculateMetadata: CalculateMetadataFunction = async ({ props, }) => { const dimensions = await getVideoDimensions(props.videoSrc); return { width: dimensions.width, height: dimensions.height, }; }; ``` ## Setting duration based on multiple videos ```tsx const calculateMetadata: CalculateMetadataFunction = async ({ props, }) => { const metadataPromises = props.videos.map((video) => getVideoDuration(video.src), ); const allMetadata = await Promise.all(metadataPromises); const totalDuration = allMetadata.reduce( (sum, durationInSeconds) => sum + durationInSeconds, 0, ); return { durationInFrames: Math.ceil(totalDuration * 30), }; }; ``` ## Setting a default outName Set the default output filename based on props: ```tsx const calculateMetadata: CalculateMetadataFunction = async ({ props, }) => { return { defaultOutName: `video-${props.id}.mp4`, }; }; ``` ## Transforming props Fetch data or transform props before rendering: ```tsx const calculateMetadata: CalculateMetadataFunction = async ({ props, abortSignal, }) => { const response = await fetch(props.dataUrl, { signal: abortSignal }); const data = await response.json(); return { props: { ...props, fetchedData: data, }, }; }; ``` The `abortSignal` cancels stale requests when props change in the Studio. ## Return value All fields are optional. Returned values override the `` props: - `durationInFrames`: Number of frames - `width`: Composition width in pixels - `height`: Composition height in pixels - `fps`: Frames per second - `props`: Transformed props passed to the component - `defaultOutName`: Default output filename - `defaultCodec`: Default codec for rendering --- ## Source & Thanks > Created by [Remotion](https://github.com/remotion-dev). Licensed under MIT. > [remotion-dev/skills](https://github.com/remotion-dev/skills) — Rule: `calculate-metadata` Part of the [Remotion AI Skill](https://tokrepo.com/en/workflows/57997ead-c8fa-409c-916f-28bbc0adc8d9) collection on TokRepo. --- Source: https://tokrepo.com/en/workflows/994d2298-c7f5-4f57-a9e9-6a7d28dcc490 Author: Skill Factory