SkillsMar 29, 2026·1 min read

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.

TL;DR
Use Mediabunny to reliably get video file duration in seconds for dynamic Remotion compositions.
§01

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.

§02

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.

§03

How to use

  1. Install the Remotion skills collection:
npx skills add remotion-dev/skills
  1. The rule activates automatically when your AI assistant detects video duration queries in a Remotion project.
  1. Use the provided pattern to read video duration before configuring your composition.
§04

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

Related on TokRepo

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.

§06

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

Why do I need video duration in Remotion?+

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.

What video formats are supported?+

getVideoMetadata supports common video formats including MP4, WebM, and MOV. The function reads metadata headers to extract duration, width, height, and other properties.

Can I get duration from local files?+

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.

What is Mediabunny?+

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.

Does this work during rendering?+

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)
🙏

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

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

Related Assets