packages/docs/docs/media-parser/metadata.mdx
:::warning Deprecated in favor of getting metadata using Mediabunny. :::
parseMedia() is deprecated.
See Getting metadata using Mediabunny for the recommended way.
Using @remotion/media-parser, you can get metadata from a variety of media formats.
Specify the fields you would like to read and the URl as src.
This works in the browser as well as in Node.js and Bun.
import {parseMedia} from '@remotion/media-parser';
const result = await parseMedia({
src: 'https://remotion.media/video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
});
console.log(result.durationInSeconds); // 10
console.log(result.dimensions); // {width: 1920, height: 1080}
Use nodeReader to read a file from a filesystem.
This can be used in Node.js and Bun.
import {parseMedia} from '@remotion/media-parser';
import {nodeReader} from '@remotion/media-parser/node';
const result = await parseMedia({
src: '/tmp/video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
reader: nodeReader,
});
console.log(result.durationInSeconds); // 10
console.log(result.dimensions); // {width: 1920, height: 1080}
FileIf you take user uploads in the browser, they will be in the form of a File.
import {parseMedia} from '@remotion/media-parser';
// You would get this from a `<input type="file">`
const file = new File([], 'video.mp4');
const result = await parseMedia({
src: file,
fields: {
durationInSeconds: true,
dimensions: true,
},
});
console.log(result.durationInSeconds); // 10
console.log(result.dimensions); // {width: 1920, height: 1080}
You can read the duration, the dimensions, the framerate, the container format, the codecs, the ID3 tags and more information from a video file.
See Available Fields for a complete list.
import {parseMedia} from '@remotion/media-parser';
const result = await parseMedia({
src: 'https://remotion.media/video.mp4',
fields: {
durationInSeconds: true,
dimensions: true,
},
onDurationInSeconds: (durationInSeconds) => {
console.log(durationInSeconds); // 10
},
});
console.log(result.dimensions); // {width: 1920, height: 1080}