Remotion Rule: Get Video Dimensions
Remotion skill rule: Getting the width and height of a video file with Mediabunny. Part of the official Remotion Agent Skill for programmatic video in React.
What it is
Remotion Rule: Get Video Dimensions is a skill rule within the official Remotion Agent Skill that provides patterns for programmatically getting and working with video dimensions in Remotion projects. It covers retrieving composition width and height, calculating aspect ratios, validating frame sizes, and handling dynamic resolution for responsive video output.
This rule is for developers building programmatic videos with Remotion who need to work with video dimensions dynamically. If you are creating videos for multiple platforms (YouTube, TikTok, Instagram) with different aspect ratios, this rule provides the patterns for handling resolution correctly.
How it saves time or tokens
Instead of hardcoding video dimensions throughout your Remotion project, this rule provides patterns for reading dimensions from composition config, calculating derived values, and adapting layouts to different aspect ratios. When using AI coding assistants, the rule activates automatically in Remotion projects, ensuring generated code uses the correct API for dimension access rather than hardcoded pixel values.
How to use
- Install the Remotion skills:
npx skills add remotion-dev/skills. - The video dimensions rule activates automatically when working with video sizing in Remotion.
- Use
useVideoConfig()to access width, height, fps, and duration in your components.
Example
import { useVideoConfig, Composition } from 'remotion';
// Access dimensions inside a component
export const MyVideo: React.FC = () => {
const { width, height, fps, durationInFrames } = useVideoConfig();
const aspectRatio = width / height;
return (
<div style={{ width, height, position: 'relative' }}>
<p>Resolution: {width}x{height}</p>
<p>Aspect Ratio: {aspectRatio.toFixed(2)}</p>
<p>Duration: {durationInFrames / fps}s</p>
</div>
);
};
// Define compositions with different dimensions
export const Root: React.FC = () => (
<>
<Composition id='youtube' component={MyVideo}
width={1920} height={1080} fps={30} durationInFrames={300} />
<Composition id='tiktok' component={MyVideo}
width={1080} height={1920} fps={30} durationInFrames={300} />
<Composition id='square' component={MyVideo}
width={1080} height={1080} fps={30} durationInFrames={300} />
</>
);
Related on TokRepo
- AI tools for video -- AI-powered video creation tools
- AI tools for design -- visual content creation tools
Common pitfalls
- Hardcoding pixel values instead of using useVideoConfig(). Hardcoded dimensions break when you render the same component at different resolutions or aspect ratios.
- Forgetting that useVideoConfig() is a React hook and must be called inside a component. It cannot be used in utility functions outside the component tree.
- Not accounting for pixel density. Remotion renders at 1x by default. If you need higher DPI output, adjust your composition dimensions accordingly rather than scaling after render.
Frequently Asked Questions
useVideoConfig() is a React hook that returns the current composition's width, height, fps, and durationInFrames. It is the standard way to access video dimensions inside Remotion components, ensuring your code adapts to different composition settings.
Yes. Define multiple Composition entries with different width and height values but the same component. Remotion renders the component at whatever resolution the composition specifies, and useVideoConfig() provides the current values.
Calculate the aspect ratio from useVideoConfig() and use it to adjust layouts. For example, switch between horizontal and vertical layouts based on whether width > height, enabling one component to serve YouTube (16:9) and TikTok (9:16) outputs.
Remotion renders to MP4 (H.264), WebM, GIF, and image sequences (PNG, JPEG). The output format is specified during rendering, independent of the composition dimensions. All formats respect the width and height from the composition config.
Yes. Use Remotion's parseMedia() function to read metadata from video files including width, height, duration, and codec. This is useful when building compositions that adapt to the dimensions of input media.
Citations (3)
- Remotion GitHub— Remotion enables programmatic video creation in React
- Remotion useVideoConfig Docs— useVideoConfig hook for accessing composition dimensions
- Remotion Composition Docs— Multiple compositions for multi-resolution output
Related on TokRepo
Source & Thanks
Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule:
get-video-dimensions
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.