Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/get-audio-duration.md
1---2name: get-audio-duration3description: Getting the duration of an audio file in seconds with Mediabunny4metadata:5tags: duration, audio, length, time, seconds, mp3, wav6---78# Getting audio duration with Mediabunny910Mediabunny can extract the duration of an audio file. It works in browser, Node.js, and Bun environments.1112## Getting audio duration1314```tsx title="get-audio-duration.ts"15import { Input, ALL_FORMATS, UrlSource } from "mediabunny";1617export const getAudioDuration = async (src: string) => {18const input = new Input({19formats: ALL_FORMATS,20source: new UrlSource(src, {21getRetryDelay: () => null,22}),23});2425const durationInSeconds = await input.computeDuration();26return durationInSeconds;27};28```2930## Usage3132```tsx33const duration = await getAudioDuration("https://remotion.media/audio.mp3");34console.log(duration); // e.g. 180.5 (seconds)35```3637## Using with staticFile in Remotion3839Make sure to wrap the file path in `staticFile()`:4041```tsx42import { staticFile } from "remotion";4344const duration = await getAudioDuration(staticFile("audio.mp3"));45```4647## In Node.js and Bun4849Use `FileSource` instead of `UrlSource`:5051```tsx52import { Input, ALL_FORMATS, FileSource } from "mediabunny";5354const input = new Input({55formats: ALL_FORMATS,56source: new FileSource(file), // File object from input or drag-drop57});58```59