Skip to main content

parseMedia()

Part of the @remotion/media-parser package. available from v4.0.190

warning

Unstable API: This package is experimental. We might change the API at any time, until we remove this notice.

Examples

Parsing a hosted video
tsx
import {parseMedia} from '@remotion/media-parser';
 
const result = await parseMedia({
src: 'https://example.com/my-video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
});
 
console.log(result.durationInSeconds); // 10
console.log(result.dimensions); // {width: 1920, height: 1080}
Parsing a hosted video
tsx
import {parseMedia} from '@remotion/media-parser';
 
const result = await parseMedia({
src: 'https://example.com/my-video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
});
 
console.log(result.durationInSeconds); // 10
console.log(result.dimensions); // {width: 1920, height: 1080}
Parsing a local file
tsx
import {parseMedia} from '@remotion/media-parser';
import {nodeReader} from '@remotion/media-parser/node';
 
const result = await parseMedia({
src: '/Users/jonnyburger/Downloads/my-video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
reader: nodeReader,
});
Parsing a local file
tsx
import {parseMedia} from '@remotion/media-parser';
import {nodeReader} from '@remotion/media-parser/node';
 
const result = await parseMedia({
src: '/Users/jonnyburger/Downloads/my-video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
reader: nodeReader,
});

API

warning

Unstable API: This package is experimental. We might change the API at any time, until we remove this notice.

src

Either a local file path, or a URL.
If you pass a local file path, you must also pass nodeReader as the reader argument.

fields

An object specifying which fields you'd like to receive.
Possible fields are:

dimensions

{width: number, height: number}

The dimensions of the video.
Any rotation is already applied - the dimensions are like a media player would show them.
Use unrotatedDimensions to get the dimensions before rotation.

durationInSeconds

number | null

The duration of the video in seconds.

boxes

The internal structure of the video. Unstable, internal data structure, refer to the TypeScript types to see what's inside.

fps

number | null

The frame rate of the video.

videoCodec

The video codec of the file.
If multiple video tracks are present, this will be the first video track.
One of "h264", "h265", "vp8", "vp9", "av1", "prores" or null (in case of an unknown codec).

audioCodec

The audio codec of the file.
If multiple audio tracks are present, this will be the first audio track.
One of 'aac', 'mp3', 'aiff', 'opus', 'pcm', 'unknown' (audio is there but not recognized) or null (in case of no audio detected).

tracks

Returns two arrays videoTracks and audioTracks.
The data structure of them is not yet stable.

unrotatedDimensions

{width: number, height: number}

The dimensions of the video before rotation.

rotation

number

The rotation of the video in degrees (e.g. -90 for a 90° counter-clockwise rotation).

reader

A reader interface.
Default value: webReader, which uses fetch() to read the video.
If you pass nodeReader, you must also pass a local file path as the src argument.

See also