Skip to content

Repository files navigation

video-size NPM version NPM downloads Build Status

Get the width and height of a video.

Install

Install with npm:

$ npm install --save video-size

Get the width, height, and display orientation of a video file using ffprobe.

Install

npm install video-size
pnpm add video-size
yarn add video-size

Requirements

video-size shells out to ffprobe, so FFmpeg needs to be installed and ffprobe needs to be available on your PATH.

Usage

import videoSize from 'video-size';

const dimensions = await videoSize('video.mp4');

console.log(dimensions);
// { width: 1280, height: 720, orientation: 'landscape' }

Sync Usage

import videoSize from 'video-size';

const dimensions = videoSize.sync('video.mp4');

console.log(dimensions);
// { width: 1280, height: 720, orientation: 'landscape' }

The sync function is also available as a named export:

import { sync as videoSizeSync } from 'video-size';

const dimensions = videoSizeSync('video.mp4');

API

videoSize(filepath)

Returns a promise for the dimensions of the first video stream in filepath.

const dimensions = await videoSize('video.mp4');

videoSize.sync(filepath)

Returns the dimensions of the first video stream in filepath.

const dimensions = videoSize.sync('video.mp4');

isVideoFile(filepath)

Returns true when filepath has a supported video extension.

import { isVideoFile } from 'video-size';

isVideoFile('clip.mp4');
// true

isVideoFile('notes.txt');
// false

VIDEO_EXTS

A Set of supported video extensions, including mp4, mov, m4v, mkv, mpeg, mpg, webm, avi, flv, 3gp, 3g2, ts, m2t, m2ts, and mts.

import { VIDEO_EXTS } from 'video-size';

VIDEO_EXTS.has('mp4');
// true

Result

Both async and sync APIs return a VideoDimensions object:

interface VideoDimensions {
  width: number;
  height: number;
  orientation: 'landscape' | 'portrait' | null;
}

width and height are the encoded dimensions reported by ffprobe.

orientation is based on the display dimensions. Rotation metadata is respected, so a rotated video can be reported as portrait even when the encoded width is greater than the encoded height. Square videos return null.

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2026, Jon Schlinkert. MIT


This file was generated by verb-generate-readme, v0.1.31, on May 16, 2026.

Releases

Used by

Contributors

Languages