@remotion/media-parser
available from v4.0.190
This is a package that parses video and audio files to extract metadata and samples.
Design goals:
- Support all major containers:
.mp4
,.mov
,.webm
,.mkv
,.avi
,.m3u8
,.ts
,.mp3
,.wav
,.aac
,.m4a
and.flac
. - Easily get various information from multimedia files
- Work in the browser, Node.js and Bun
- Satisfy your query with minimal fetching
- Functional TypeScript API
- Be useful when passing unsupported media
- Allow decoding video frames and audio samples using WebCodecs
- Pausable, resumable and cancellable
- Be able to seek to a different position in a media file
- No dependencies
Installation
- npm
- yarn
- pnpm
- bun
npm i --save-exact @remotion/media-parser@4.0.305
pnpm i @remotion/media-parser@4.0.305
bun i @remotion/media-parser@4.0.305
yarn --exact add @remotion/media-parser@4.0.305
Also update
remotion
and all `@remotion/*`
packages to the same version.Remove all
^
character in front of the version numbers of it as it can lead to a version conflict.Hello World
Get metadata from a video file - over 20 different fields are supported.
Get the duration and codec of a videotsx
import {parseMedia } from '@remotion/media-parser';const {durationInSeconds ,videoCodec } = awaitparseMedia ({src : 'https://parser.media/video.mp4',fields : {durationInSeconds : true,videoCodec : true,},});console .log (durationInSeconds ); // 5.056;console .log (videoCodec ); // 'h264';
Extract samples from a video file - supports WebCodecs.
Extract samples from a videotsx
import {parseMedia } from '@remotion/media-parser';awaitparseMedia ({src : 'https://parser.media/video.mp4',onVideoTrack : ({track }) => {// Get information about theconsole .log (track .width );console .log (track .height );return (sample ) => {// Retrieve samples as they are extractedconsole .log (sample .timestamp ); // 0console .log (sample .data ); // Uint8Array(12345)};},});
What are samples?
Samples contain audio or video data - but they are compressed using codecs like AAC for audio or H.264 for video.
You can turn audio samples into a waveform and video samples into images by decoding them.
Guide
parseMedia()
APIs
The following APIs are available:
1_000_000
) of WebCodecs as a constant.Readers
Choose the appropriate reader for your file source:
Writers
Choose how to store files downloaded using downloadAndParseMedia()
:
Types
How does this compare to FFmpeg?
- Media Parser specializes for JavaScript and on the web.
It is designed to embrace the language and make use of the APIs that JavaScript has to offer. - Unlike FFmpeg, Remotion Media Parser does not have functionality for decoding and encoding – it only parses media files.
Instead, we hope you combine it with WebCodecs, the native API built into browsers. - Media Parser has no command line interface and cannot be integrated into native applications.
How does this compare to MP4Box.js?
MP4Box.js does a better job at parsing the ISO Base Media Format (.mp4
, .m4a
, .mov
) and supports reading more information from it.
Remotion Media Parser supports more container formats, with the goal that it can handle arbitrary user-provided media files.
Thank you
![]() | Tella for boosting the development of @remotion/media-parser with $10.000! |