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-video-duration.md
1---2name: get-video-duration3description: Getting the duration of a video file in seconds with Mediabunny4metadata:5tags: duration, video, length, time, seconds6---78# Getting video duration with Mediabunny910Mediabunny can extract the duration of a video file. It works in browser, Node.js, and Bun environments.1112## Getting video duration1314```tsx15import { Input, ALL_FORMATS, UrlSource } from "mediabunny";1617export const getVideoDuration = 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 getVideoDuration("https://remotion.media/video.mp4");34console.log(duration); // e.g. 10.5 (seconds)35```3637## Video files from the public/ directory3839Make sure to wrap the file path in `staticFile()`:4041```tsx42import { staticFile } from "remotion";4344const duration = await getVideoDuration(staticFile("video.mp4"));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});5859const durationInSeconds = await input.computeDuration();60```61