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-dimensions.md
1---2name: get-video-dimensions3description: Getting the width and height of a video file with Mediabunny4metadata:5tags: dimensions, width, height, resolution, size, video6---78# Getting video dimensions with Mediabunny910Mediabunny can extract the width and height of a video file. It works in browser, Node.js, and Bun environments.1112## Getting video dimensions1314```tsx15import { Input, ALL_FORMATS, UrlSource } from "mediabunny";1617export const getVideoDimensions = async (src: string) => {18const input = new Input({19formats: ALL_FORMATS,20source: new UrlSource(src, {21getRetryDelay: () => null,22}),23});2425const videoTrack = await input.getPrimaryVideoTrack();26if (!videoTrack) {27throw new Error("No video track found");28}2930return {31width: videoTrack.displayWidth,32height: videoTrack.displayHeight,33};34};35```3637## Usage3839```tsx40const dimensions = await getVideoDimensions("https://remotion.media/video.mp4");41console.log(dimensions.width); // e.g. 192042console.log(dimensions.height); // e.g. 108043```4445## Using with local files4647For local files, use `FileSource` instead of `UrlSource`:4849```tsx50import { Input, ALL_FORMATS, FileSource } from "mediabunny";5152const input = new Input({53formats: ALL_FORMATS,54source: new FileSource(file), // File object from input or drag-drop55});5657const videoTrack = await input.getPrimaryVideoTrack();58const width = videoTrack.displayWidth;59const height = videoTrack.displayHeight;60```6162## Using with staticFile in Remotion6364```tsx65import { staticFile } from "remotion";6667const dimensions = await getVideoDimensions(staticFile("video.mp4"));68```69