Skip to content

🎥 Make videos programmatically with React

write some docs

Jonny Burger583414a84548
diff --git a/packages/docs/docs/video-parser/TableOfContents.tsx b/packages/docs/docs/video-parser/TableOfContents.tsx
new file mode 100644
index 0000000000..3ccdd0839b
--- /dev/null
+++ b/packages/docs/docs/video-parser/TableOfContents.tsx
@@ -0,0 +1,16 @@
+import React from 'react';
+import {Grid} from '../../components/TableOfContents/Grid';
+import {TOCItem} from '../../components/TableOfContents/TOCItem';
+
+export const TableOfContents: React.FC = () => {
+ return (
+ <div>
+ <Grid>
+ <TOCItem link="/docs/video-parser/parse-media">
+ <strong>{'parseMedia()'}</strong>
+ <div>Parse a media file.</div>
+ </TOCItem>
+ </Grid>
+ </div>
+ );
+};
diff --git a/packages/docs/docs/video-parser/index.mdx b/packages/docs/docs/video-parser/index.mdx
new file mode 100644
index 0000000000..152a6cae25
--- /dev/null
+++ b/packages/docs/docs/video-parser/index.mdx
@@ -0,0 +1,37 @@
+---
+sidebar_label: Overview
+title: '@remotion/video-parser'
+---
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+import {TableOfContents} from './TableOfContents';
+
+_available from v4.0.190_
+
+This is an experimental package that parses video and other media files in order to extract relevant metadata.
+
+:::warning
+**Unstable API**: This package is experimental. We might change the API at any time, until we remove this notice.
+:::
+
+Design goals:
+
+- Work in the browser, and server runtimes (Node.js, Bun, Edge, etc.)
+- Stream the content, only download as much data as necessary
+- Functional TypeScript API
+- Solve problems that are relevant for Remotion users
+
+## Installation
+
+<Installation pkg="@remotion/video-parser" />
+
+## APIs
+
+The following APIs are available:
+
+<TableOfContents />
+
+## License
+
+[Remotion License](https://remotion.dev/license)
diff --git a/packages/docs/docs/video-parser/parse-media.mdx b/packages/docs/docs/video-parser/parse-media.mdx
new file mode 100644
index 0000000000..b1a87d2eb6
--- /dev/null
+++ b/packages/docs/docs/video-parser/parse-media.mdx
@@ -0,0 +1,94 @@
+---
+id: parse-media
+title: 'parseMedia()'
+slug: /video-parser/parse-media
+crumb: '@remotion/video-parser'
+---
+
+_Part of the [`@remotion/video-parser`](/docs/video-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
+
+```tsx twoslash title="Parsing a hosted video"
+// @module: es2022
+// @target: es2017
+import {parseMedia} from '@remotion/video-parser';
+
+const result = await parseMedia('https://example.com/my-video.mp4', {
+ durationInSeconds: true,
+ dimensions: true,
+});
+
+console.log(result.durationInSeconds); // 10
+console.log(result.dimensions); // {width: 1920, height: 1080}
+```
+
+```tsx twoslash title="Parsing a local file"
+// @module: es2022
+// @target: es2017
+import {parseMedia} from '@remotion/video-parser';
+import {nodeReader} from '@remotion/video-parser/node';
+
+const result = await parseMedia(
+ '/Users/jonnyburger/Downloads/my-video.mp4',
+ {
+ durationInSeconds: true,
+ dimensions: true,
+ },
+ 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.
+
+#### `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.
+
+### `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
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/video-parser/src/parse-media.ts)
+- [`@remotion/video-parser`](/docs/video-parser)
diff --git a/packages/docs/package.json b/packages/docs/package.json
index 38df11b796..24cc851e8b 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -60,6 +60,7 @@
"@remotion/enable-scss": "workspace:*",
"@remotion/three": "workspace:*",
"@remotion/transitions": "workspace:*",
+ "@remotion/video-parser": "workspace:*",
"@rive-app/canvas-advanced": "2.3.0",
"@shopify/react-native-skia": "^1.2.2",
"@swc/core": "^1.3.80",
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index accf979015..82748eab51 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -550,6 +550,15 @@ module.exports = {
'animated-emoji/get-available-emoji',
],
},
+ {
+ type: 'category',
+ label: '@remotion/video-parser',
+ link: {
+ type: 'doc',
+ id: 'video-parser/index',
+ },
+ items: ['video-parser/index', 'video-parser/parse-media'],
+ },
{
type: 'category',
label: '@remotion/install-whisper-cpp',
diff --git a/packages/video-parser/package.json b/packages/video-parser/package.json
index adbbed8567..0f2608e022 100644
--- a/packages/video-parser/package.json
+++ b/packages/video-parser/package.json
@@ -20,13 +20,13 @@
},
"exports": {
".": "./dist/index.js",
- "./config": "./dist/config/index.js",
+ "./node": "./dist/from-node.js",
"./package.json": "./package.json"
},
"typesVersions": {
">=1.0": {
- "config": [
- "dist/config/index.d.ts"
+ "node": [
+ "dist/from-node.d.ts"
]
}
},
diff --git a/packages/video-parser/src/index.ts b/packages/video-parser/src/index.ts
index 11d5b3b098..8ba891a78e 100644
--- a/packages/video-parser/src/index.ts
+++ b/packages/video-parser/src/index.ts
@@ -1 +1 @@
-export {parseMedia} from './get-video-metadata';
+export {parseMedia} from './parse-media';
diff --git a/packages/video-parser/src/get-video-metadata.ts b/packages/video-parser/src/parse-media.ts
similarity index 100%
rename from packages/video-parser/src/get-video-metadata.ts
rename to packages/video-parser/src/parse-media.ts
diff --git a/packages/video-parser/src/test/duration.test.ts b/packages/video-parser/src/test/duration.test.ts
index c7aca50cc3..c74ed84dde 100644
--- a/packages/video-parser/src/test/duration.test.ts
+++ b/packages/video-parser/src/test/duration.test.ts
@@ -1,7 +1,7 @@
import {RenderInternals} from '@remotion/renderer';
import {expect, test} from 'bun:test';
import {nodeReader} from '../from-node';
-import {parseMedia} from '../get-video-metadata';
+import {parseMedia} from '../parse-media';
test('Should get duration of video', async () => {
const parsed = await parseMedia(
diff --git a/packages/video-parser/src/test/matroska.test.ts b/packages/video-parser/src/test/matroska.test.ts
index ea37ccb143..6e79b6b827 100644
--- a/packages/video-parser/src/test/matroska.test.ts
+++ b/packages/video-parser/src/test/matroska.test.ts
@@ -1,7 +1,7 @@
import {RenderInternals} from '@remotion/renderer';
import {expect, test} from 'bun:test';
import {nodeReader} from '../from-node';
-import {parseMedia} from '../get-video-metadata';
+import {parseMedia} from '../parse-media';
test('Should get duration of AV1 video', async () => {
const parsed = await parseMedia(
diff --git a/packages/video-parser/src/test/parse-video.test.ts b/packages/video-parser/src/test/parse-video.test.ts
index c7dfd8cebe..05ee710296 100644
--- a/packages/video-parser/src/test/parse-video.test.ts
+++ b/packages/video-parser/src/test/parse-video.test.ts
@@ -1,7 +1,7 @@
import {RenderInternals} from '@remotion/renderer';
import {expect, test} from 'bun:test';
import {nodeReader} from '../from-node';
-import {parseMedia} from '../get-video-metadata';
+import {parseMedia} from '../parse-media';
test('Parse Big Buck bunny', async () => {
const data = await parseMedia(
diff --git a/packages/video-parser/src/test/parse-webm.test.ts b/packages/video-parser/src/test/parse-webm.test.ts
index b7235e7b6a..a1a8eb8f8c 100644
--- a/packages/video-parser/src/test/parse-webm.test.ts
+++ b/packages/video-parser/src/test/parse-webm.test.ts
@@ -1,7 +1,7 @@
import {RenderInternals} from '@remotion/renderer';
import {expect, test} from 'bun:test';
import {nodeReader} from '../from-node';
-import {parseMedia} from '../get-video-metadata';
+import {parseMedia} from '../parse-media';
test('should be able to parse a WebM', async () => {
const webm = await parseMedia(
diff --git a/packages/video-parser/src/test/stream-local.test.ts b/packages/video-parser/src/test/stream-local.test.ts
index adef7edd72..abc829deac 100644
--- a/packages/video-parser/src/test/stream-local.test.ts
+++ b/packages/video-parser/src/test/stream-local.test.ts
@@ -1,7 +1,7 @@
import {RenderInternals} from '@remotion/renderer';
import {expect, test} from 'bun:test';
import {nodeReader} from '../from-node';
-import {parseMedia} from '../get-video-metadata';
+import {parseMedia} from '../parse-media';
test('Should stream ISO base media', async () => {
const result = await parseMedia(
diff --git a/packages/video-parser/src/test/stream-remote.test.ts b/packages/video-parser/src/test/stream-remote.test.ts
index 365ecf13de..98e275d83f 100644
--- a/packages/video-parser/src/test/stream-remote.test.ts
+++ b/packages/video-parser/src/test/stream-remote.test.ts
@@ -1,5 +1,5 @@
import {expect, test} from 'bun:test';
-import {parseMedia} from '../get-video-metadata';
+import {parseMedia} from '../parse-media';
test('Should stream', async () => {
const result = await parseMedia(
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8b37b559b5..7682c15862 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -522,6 +522,9 @@ importers:
'@remotion/transitions':
specifier: workspace:*
version: link:../transitions
+ '@remotion/video-parser':
+ specifier: workspace:*
+ version: link:../video-parser
'@rive-app/canvas-advanced':
specifier: 2.3.0
version: 2.3.0