Remotion Rule: Get Video Duration
Remotion skill rule: Getting the duration of a video file in seconds with Mediabunny. Part of the official Remotion Agent Skill for programmatic video in React.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install 3ed09610-0041-40d0-8834-d19472bf8a2d --target codexRun after dry-run confirms the install plan.
What it is
This is a Remotion skill rule for getting the duration of a video file in seconds using Mediabunny. When building dynamic Remotion compositions that incorporate external video files, you need to know the video duration to set the composition length correctly. Mediabunny provides a reliable way to read this metadata.
The rule is part of the official Remotion Agent Skill collection for AI coding assistants (Claude Code, Cursor, OpenAI Codex) working on React-based programmatic video projects.
How it saves time or tokens
Without this rule, an AI assistant might suggest using ffprobe, a custom ffmpeg command, or unreliable JavaScript-based approaches to read video duration. Mediabunny is the recommended Remotion approach, handling format detection and metadata extraction consistently. The rule eliminates trial-and-error by providing the correct implementation on the first attempt.
How to use
- Install the Remotion skills collection:
npx skills add remotion-dev/skills
- The rule activates automatically when your AI assistant detects video duration queries in a Remotion project.
- Use the provided pattern to read video duration before configuring your composition.
Example
import { getVideoMetadata } from '@remotion/media-utils';
// Get video duration in a calculate-metadata function
export const calculateMetadata = async () => {
const metadata = await getVideoMetadata(
'https://example.com/video.mp4'
);
return {
durationInFrames: Math.ceil(metadata.durationInSeconds * 30),
fps: 30,
width: metadata.width,
height: metadata.height,
};
};
// Use in composition
import { Composition } from 'remotion';
import { MyVideo } from './MyVideo';
export const Root = () => {
return (
<Composition
id='MyVideo'
component={MyVideo}
calculateMetadata={calculateMetadata}
width={1920}
height={1080}
fps={30}
durationInFrames={1}
/>
);
};
Related on TokRepo
- AI Tools for Video — Video production tools
- Featured Workflows — Top-rated skills and workflows
This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.
For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.
Common pitfalls
- The getVideoMetadata function works with URLs and local file paths; ensure the video file is accessible from the build environment.
- Duration is returned in seconds (floating point); multiply by fps and ceil to get durationInFrames for Remotion compositions.
- Some video formats may not report duration in metadata headers; for these files, the function may need to download more of the file before returning.
Frequently Asked Questions
Remotion compositions require a fixed durationInFrames value. When incorporating external video files, you need to know their duration to set the composition length correctly, ensuring the video plays completely without being cut off or leaving empty frames.
getVideoMetadata supports common video formats including MP4, WebM, and MOV. The function reads metadata headers to extract duration, width, height, and other properties.
Yes. The function works with both URLs and local file paths. For local files, use the staticFile helper or an absolute path accessible during the build process.
Mediabunny refers to Remotion's media utilities package (@remotion/media-utils) which provides functions for reading video and audio metadata. getVideoMetadata is one of its primary functions.
Yes. The calculateMetadata function runs before rendering starts, providing the correct duration for the composition. It works in both development preview and production rendering.
Citations (3)
- Remotion Media Utils Docs— Remotion media-utils provides getVideoMetadata for reading video duration
- Remotion Composition Docs— Remotion compositions require durationInFrames for rendering
- Remotion Skills GitHub— Remotion Agent Skill for AI-assisted video development
Related on TokRepo
Source & Thanks
Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule:
get-video-duration
Part of the Remotion AI Skill collection on TokRepo.
Discussion
Related Assets
Remotion Rule: Text Animations
Remotion skill rule: Typography and text animation patterns for Remotion.. Part of the official Remotion Agent Skill for programmatic video in React.
Remotion Rule: Videos
Remotion skill rule: Embedding videos in Remotion - trimming, volume, speed, looping, pitch. Part of the official Remotion Agent Skill for programmatic video in React.
Remotion Rule: Timing
Remotion skill rule: Interpolation curves in Remotion - linear, easing, spring animations. Part of the official Remotion Agent Skill for programmatic video in React.
Remotion Rule: Transcribe Captions
Remotion skill rule: Transcribing audio to generate captions in Remotion. Part of the official Remotion Agent Skill for programmatic video in React.