Remotion Rule: Get Audio Duration
Remotion skill rule: Getting the duration of an audio file in seconds with Mediabunny. Part of the official Remotion Agent Skill for programmatic video in React.
What it is
This Remotion rule instructs AI coding agents on how to get the duration of an audio file in seconds using Mediabunny within Remotion projects. Knowing the exact audio duration is essential for synchronizing video compositions with background music, voiceovers, or sound effects.
The rule targets developers using AI assistants to build Remotion video projects that need frame-accurate audio synchronization.
How it saves time or tokens
Without this rule, AI agents often guess at audio durations or suggest incorrect APIs for measuring them. The rule provides the exact Mediabunny function call and demonstrates how to convert the duration into frame counts for Remotion compositions, eliminating debugging time.
How to use
- Add the Remotion audio duration rule to your project's AI configuration.
- Ask your AI assistant to create a composition that matches the length of an audio file.
- The agent uses Mediabunny to measure the duration and sets the composition's
durationInFramesaccordingly.
Example
import { getAudioDurationInSeconds } from '@remotion/media-utils';
import { Composition, Audio, staticFile } from 'remotion';
// Calculate composition duration from audio length
const fps = 30;
export const RemotionRoot: React.FC = () => {
return (
<Composition
id='AudioVideo'
component={AudioVideo}
fps={fps}
width={1920}
height={1080}
calculateMetadata={async () => {
const duration = await getAudioDurationInSeconds(
staticFile('voiceover.mp3')
);
return {
durationInFrames: Math.ceil(duration * fps),
};
}}
/>
);
};
const AudioVideo: React.FC = () => (
<Audio src={staticFile('voiceover.mp3')} />
);
Related on TokRepo
- AI Tools for Video -- video creation and editing tools for developers
- AI Tools for Automation -- automation tools for media workflows
Common pitfalls
getAudioDurationInSecondsis async and must be called insidecalculateMetadataor adelayRenderblock, not during render.- Supported formats depend on the browser and FFmpeg availability. MP3 and WAV are universally supported; OGG may not work in all environments.
- Audio files in the public directory must be referenced with
staticFile(). Direct file paths cause rendering failures in production.
Frequently Asked Questions
Remotion compositions require a fixed durationInFrames value. To match the composition length to an audio file, you need to measure the audio duration in seconds and multiply by the fps. Without this, the video may cut off early or have excess silence.
Mediabunny is the internal name for Remotion's media utilities package (@remotion/media-utils). It provides functions like getAudioDurationInSeconds and getVideoMetadata for measuring media file properties.
Yes. The @remotion/media-utils package also exports getVideoMetadata which returns duration, width, height, and fps of video files. The pattern is identical to audio duration measurement.
Yes, but remote URLs add network latency and potential CORS issues. For reliable rendering, prefer local audio files via staticFile(). If using remote URLs, ensure CORS headers are configured on the server.
getAudioDurationInSeconds returns the duration as reported by the browser's audio decoder, which is accurate to within a few milliseconds. This is precise enough for frame-level synchronization at standard video frame rates.
Citations (3)
- Remotion Audio Duration Docs— getAudioDurationInSeconds from @remotion/media-utils
- Remotion Dynamic Metadata Docs— calculateMetadata for dynamic composition duration
- Remotion GitHub— Official Remotion Agent Skill
Related on TokRepo
Source & Thanks
Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule:
get-audio-duration
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.