π₯ Make videos programmatically with React
update docs
Jonny Burger11f163f04c21
diff --git a/packages/docs/docs/media-parser/TableOfContents.tsx b/packages/docs/docs/media-parser/TableOfContents.tsxindex 59ed457a51..d4454e781c 100644--- a/packages/docs/docs/media-parser/TableOfContents.tsx+++ b/packages/docs/docs/media-parser/TableOfContents.tsx@@ -45,7 +45,7 @@ export const MediaParserGuideTableOfContents: React.FC = () => {<div>Get embedded tags from video files</div></TOCItem><TOCItem link="/docs/media-parser/workers">- <strong>Parsing on Web Workers</strong>+ <strong>Web Workers</strong><div>Parse a media file in the browser on a separate thread.</div></TOCItem><TOCItem link="/docs/media-parser/download-and-parse">@@ -142,3 +142,16 @@ export const WritersTableOfContents: React.FC = () => {</div>);};++export const TypesTableOfContents: React.FC = () => {+ return (+ <div>+ <Grid>+ <TOCItem link="/docs/media-parser/types">+ <strong>{'TypeScript types'}</strong>+ <div>Reference for the types returned by Media Parser.</div>+ </TOCItem>+ </Grid>+ </div>+ );+};diff --git a/packages/docs/docs/media-parser/index.mdx b/packages/docs/docs/media-parser/index.mdxindex 881c65c1b8..4fb0c3d6af 100644--- a/packages/docs/docs/media-parser/index.mdx+++ b/packages/docs/docs/media-parser/index.mdx@@ -6,7 +6,7 @@ title: '@remotion/media-parser'import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-import {TableOfContents, MediaParserGuideTableOfContents, ReadersTableOfContents, WritersTableOfContents} from './TableOfContents';+import {TableOfContents, MediaParserGuideTableOfContents, ReadersTableOfContents, WritersTableOfContents, TypesTableOfContents} from './TableOfContents';_available from v4.0.190_@@ -21,7 +21,7 @@ Design goals:- [Support all major containers](/docs/media-parser/format-support): `.mp4`, `.mov`, `.webm`, `.mkv`, `.avi`, `.m3u8`, `.ts`, `.mp3`, `.wav`, `.aac`, `.m4a` and `.flac`.- [Easily get various information](/docs/media-parser/fields) from multimedia files-- [Work in the browser, and server runtimes](/docs/media-parser/runtime-support) (Node.js, Bun, Edge, etc.)+- [Work in the browser, Node.js and Bun](/docs/media-parser/runtime-support)- [Satisfy your query with minimal fetching](/docs/media-parser/fast-and-slow)- [Functional TypeScript API](/docs/media-parser/parse-media)- [Be useful when passing unsupported media](/docs/media-parser/foreign-file-types)@@ -34,6 +34,53 @@ Design goals:<Installation pkg="@remotion/media-parser" />+## Hello World++Get metadata from a video file - [over 20 different fields are supported.](/docs/media-parser/fields)++```tsx twoslash title="Get the duration and codec of a video"+import {parseMedia} from '@remotion/media-parser';++const {durationInSeconds, videoCodec} = await parseMedia({+ 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](/docs/media-parser/webcodecs).++```tsx twoslash title="Extract samples from a video"+import {parseMedia} from '@remotion/media-parser';++await parseMedia({+ src: 'https://parser.media/video.mp4',+ onVideoTrack: ({track}) => {+ // Get information about the+ console.log(track.width);+ console.log(track.height);+ return (sample) => {+ // Retrieve samples as they are extracted+ console.log(sample.timestamp); // 0+ console.log(sample.data); // Uint8Array(12345)+ };+ },+});+```++<details>+<summary>What are samples?</summary>++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.++</details>+## Guide<MediaParserGuideTableOfContents />@@ -56,22 +103,22 @@ Choose how to store files downloaded using [`downloadAndParseMedia()`](/docs/med<WritersTableOfContents />-## How does this compare to FFmpeg?+## Types-FFmpeg generally is a more mature software and carries more capabilities.-We advise you to use it always if you don't need to call it from JavaScript.+<TypesTableOfContents />-We built `@remotion/media-parser` with the focus on making it work well on the web:+## How does this compare to FFmpeg?-- Importing this library is a lot lighter than FFmpeg.wasm, which loads at least 10MB.-- Functional, promise-based API-- Direct integration and intentional usage of JavaScript APIs like `fetch()`, `File`, `Worker`, `AbortController`, `node:fs`, resizable `ArrayBuffer`-- Samples are returned in a WebCodecs-compatible format, which makes it easier to decode them in the browser with full hardware acceleration.+- 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?-We aim to support more container formats than MP4Box.js, so that multimedia files of any kind can be passed in.-MP4Box.js focuses on the ISO Base Media Format and supports reading more boxes, however it does not support reading other container formats.+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](/docs/media-parser/format-support), with the goal that it can handle arbitrary user-provided media files.## Thank youdiff --git a/packages/docs/docs/media-parser/runtime-support.mdx b/packages/docs/docs/media-parser/runtime-support.mdxindex 57ef73cb7e..33e805098f 100644--- a/packages/docs/docs/media-parser/runtime-support.mdx+++ b/packages/docs/docs/media-parser/runtime-support.mdx@@ -6,13 +6,11 @@ slug: /media-parser/runtime-supportcrumb: '@remotion/media-parser'----`@remotion/media-parser` works in the Browser, Node.js and Bun.+[`@remotion/media-parser`](/docs/media-parser) works in the Browser, Node.js and Bun.-However, all of these require some quite modern versions (considered modern as of August 2024).+## Runtime versions-## For parsing--For parsing a video, the following minimum versions are required:+The following minimum versions are required:- Node.js: 20.0.0- Bun 1.0.0@@ -21,7 +19,7 @@ For parsing a video, the following minimum versions are required:- Safari 16.4- Firefox 128-### Feature detection+## Feature detectionUse this to check if the runtime supports `parseMedia()`:@@ -29,14 +27,20 @@ Use this to check if the runtime supports `parseMedia()`:const canUseMediaParser = typeof fetch === 'function' && typeof new ArrayBuffer().resize === 'function';```-## For using WebCodecs+## WebCodecs support-WebCodecs support is not tied to `@remotion/media-parser` itself, but if you use it to extract samples, you need to use the following minimum versions:+WebCodecs support is not tied to `@remotion/media-parser` itself, but if you use it to decode video and audio, you :- Chrome 94- Edge 94-- Safari 16.4 - No support for `AudioDecoder`-- Firefox - No support, but in development+- Firefox 130+- Safari - Technology Preview++:::warning+Safari does have video-only support, but will add audio support later in 2025. Last updated May 9th 2025.+:::++See also: [Can I use WebCodecs?](https://caniuse.com/webcodecs)## See also