π₯ Make videos programmatically with React
new webcodecs articles
Jonny Burgerfe1eec89e69f
diff --git a/packages/docs/docs/webcodecs/convert-a-video.mdx b/packages/docs/docs/webcodecs/convert-a-video.mdxnew file mode 100644index 0000000000..a39d1d5a81--- /dev/null+++ b/packages/docs/docs/webcodecs/convert-a-video.mdx@@ -0,0 +1,115 @@+---+image: /generated/articles-docs-webcodecs-convert-a-video.png+id: convert-a-video+title: Convert a video+slug: /webcodecs/convert-a-video+crumb: '@remotion/webcodecs'+---++You can convert a video in the browser from one format to another using the [`convertMedia()`](/docs/convert-media) function from [`@remotion/webcodecs`](/docs/webcodecs).++import {LicenseDisclaimer} from './LicenseDisclaimer';+import {UnstableDisclaimer} from './UnstableDisclaimer';++<details>+ <summary>πΌ Important License Disclaimer</summary>+ <LicenseDisclaimer />+</details>++The following input formats are supported:++- MP4+- WebM+- AVI++The following output formats are supported:++- MP4+- WebM+- WAV++The following output video codecs are supported:++- VP8 (WebM only)+- VP9 (WebM only)+- H.264 (MP4 only)++The following output audio codecs are supported:++- Opus (WebM only)+- AAC (MP4 only)+- PCM (WAV only)++## Installation++Install the `@remotion/webcodecs` and `@remotion/media-parser` packages:++<Installation pkg="@remotion/webcodecs @remotion/media-parser" />+<br />+<details>+ <summary>π§ Unstable API</summary>+ <UnstableDisclaimer />+</details>++## Basic conversions++### Converting from an URL++(needs to be CORS-enabled)++```tsx twoslash title="Converting an MP4 to a WebM"+// @module: es2022+// @target: es2017+import {convertMedia} from '@remotion/webcodecs';++await convertMedia({+ src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',+ container: 'webm',+});+```++### Converting from a [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File):++```tsx twoslash title="Converting a file"+// @module: es2022+// @target: es2017++import {convertMedia} from '@remotion/webcodecs';+import {webFileReader} from '@remotion/media-parser/web-file';++// Get an actual file from an <input type="file"> element+const file = new File([], 'video.mp4');++await convertMedia({+ src: file,+ container: 'webm',+ reader: webFileReader,+});+```++## Specifying the output codec++You can specify the output codec by passing the [`videoCodec`](/docs/webcodecs/convert-media#videocodec) and [`audioCodec`](/docs/webcodecs/convert-media#audiocodec) options:++```tsx twoslash title="Converting to VP9"+// @module: es2022+// @target: es2017++import {convertMedia} from '@remotion/webcodecs';++await convertMedia({+ src: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',+ container: 'webm',+ videoCodec: 'vp9',+ audioCodec: 'opus',+});+```++## Advanced conversions++See [Track Transformation](/docs/webcodecs/track-transformation) for how you can get more control over the conversion.++## See also++- [`convertMedia()`](/docs/convert-media)+- [Rotate a video](/docs/webcodecs/rotate-a-video)diff --git a/packages/docs/docs/webcodecs/fix-a-mediarecorder-video.mdx b/packages/docs/docs/webcodecs/fix-a-mediarecorder-video.mdxnew file mode 100644index 0000000000..c5a70b3f76--- /dev/null+++ b/packages/docs/docs/webcodecs/fix-a-mediarecorder-video.mdx@@ -0,0 +1,122 @@+---+image: /generated/articles-docs-webcodecs-fix-a-mediarecorder-video.png+id: fix-mediarecorder-video+title: Fixing a MediaRecorder video+slug: /webcodecs/fix-mediarecorder-video+crumb: '@remotion/webcodecs'+---++When recording a video with the [`MediaRecorder`](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder) and [`getUserMedia()`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) API, a WebM file gets created that may have some playback and compatibility issues.++Namely, it:++- does not show the video duration in the browser+- can be slow to seek around+- does not play in all browsers (Safari)++To fix these issues, you should either re-encode or re-mux the video.++- **Re-encoding** will decode and re-encode the frames (if you want to a different codec).+ It will be slower, but allows to use a more compatible format like MP4.+- **Re-muxing** will leave the frames, but disassemble and reassemble the file to allow for seeking points and duration metadata to be inserted.+ It is very fast, but does not allow for codec changes.++## Why does this happen?++The reason is that while recording, browsers open a file and append video chunks to the end.+However, the important metadata such as duration and seeking points should be at the beginning of the file for them to be useful.++By placing the metadata at the beginning, the video player has the information it needs to seek around the video and display the duration.++## Re-encoding on the server++The traditional way is to use a server and run [FFmpeg](https://ffmpeg.org) on it:++```sh+ffmpeg -i input.webm -c:v libx264 -c:a aac output.mp4+```++or for re-muxing:++```sh+ffmpeg -i input.webm -c copy output.webm+```++## Re-encoding using `@remotion/webcodecs`++You can also re-encode the video in the browser using the new and experimental [`@remotion/webcodecs`](/docs/webcodecs) package.++```tsx twoslash title="Re-encoding a video"+// @module: es2022+// @target: es2017++import {convertMedia} from '@remotion/webcodecs';+import {webFileReader} from '@remotion/media-parser/web-file';++// The video get from the MediaRecorder as a Blob+const blob = new Blob([], {type: 'video/webm'});++await convertMedia({+ src: blob,+ container: 'mp4',+ videoCodec: 'h264',+ audioCodec: 'aac',+ reader: webFileReader,+});+```++import {LicenseDisclaimer} from './LicenseDisclaimer';+import {UnstableDisclaimer} from './UnstableDisclaimer';++<details>+ <summary>πΌ Important License Disclaimer about `@remotion/webcodecs`</summary>+ <LicenseDisclaimer />+</details>+<details>+ <summary>π§ Unstable API</summary>+ <UnstableDisclaimer />+</details>++## Re-muxing using `@remotion/webcodecs`++Instead of re-encoding to an MP4, you can also re-mux the video to a new WebM file:++```tsx twoslash title="Re-muxing a video"+// @module: es2022+// @target: es2017++import {convertMedia} from '@remotion/webcodecs';+import {webFileReader} from '@remotion/media-parser/web-file';++// The video get from the MediaRecorder as a Blob+const blob = new Blob([], {type: 'video/webm'});++await convertMedia({+ src: blob,+ container: 'webm',+ reader: webFileReader,+});+```++[`convertMedia()`](/docs/webcodecs/convert-media) will move the metadata and seek information to the beginning of the video.++<details>+ <summary>πΌ Important License Disclaimer about `@remotion/webcodecs`</summary>+ <LicenseDisclaimer />+</details>+<details>+ <summary>π§ Unstable API</summary>+ <UnstableDisclaimer />+</details>++## Sample application++Use [remotion.dev/convert](https://remotion.dev/convert) to fix a MediaRecorder video online using WebCodecs.+See the [source code](https://github.com/remotion-dev/remotion/tree/main/packages/convert) for a reference on how to implement it.++## See also++- [`@remotion/webcodecs`](/docs/webcodecs)+- [Convert a video](/docs/webcodecs/convert-a-video)+- [`convertMedia()`](/docs/webcodecs/convert-media)+- [`@remotion/media-parser`](/docs/media-parser)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 384145b90f..39ad75cb05 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -576,7 +576,6 @@ module.exports = {items: ['webcodecs/index','webcodecs/track-transformation',- 'webcodecs/rotate-a-video','webcodecs/convert-media','webcodecs/get-available-containers','webcodecs/can-reencode-audio-track',@@ -855,7 +854,7 @@ module.exports = {},{type: 'category',- label: 'Cloud Run (Alpha)',+ label: 'Cloud Run',link: {type: 'doc',id: 'cloudrun-alpha',@@ -875,6 +874,15 @@ module.exports = {'cloudrun/uninstall',],},+ {+ type: 'category',+ label: 'WebCodecs',+ items: [+ 'webcodecs/convert-a-video',+ 'webcodecs/rotate-a-video',+ 'webcodecs/fix-mediarecorder-video',+ ],+ },{type: 'category',label: 'Building apps',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 276322cd93..32b6c0cd0a 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -3361,6 +3361,20 @@ export const articles = [compId: 'articles-docs-webcodecs-can-copy-video-track',crumb: '@remotion/webcodecs',},+ {+ id: 'fix-mediarecorder-video',+ title: 'Fixing a MediaRecorder video',+ relativePath: 'docs/webcodecs/fix-a-mediarecorder-video.mdx',+ compId: 'articles-docs-webcodecs-fix-a-mediarecorder-video',+ crumb: '@remotion/webcodecs',+ },+ {+ id: 'convert-a-video',+ title: 'Convert a video',+ relativePath: 'docs/webcodecs/convert-a-video.mdx',+ compId: 'articles-docs-webcodecs-convert-a-video',+ crumb: '@remotion/webcodecs',+ },{id: 'track-transformation',title: 'Track Transformation',diff --git a/packages/docs/static/generated/articles-docs-webcodecs-convert-a-video.png b/packages/docs/static/generated/articles-docs-webcodecs-convert-a-video.pngnew file mode 100644index 0000000000..b6b2d57430Binary files /dev/null and b/packages/docs/static/generated/articles-docs-webcodecs-convert-a-video.png differdiff --git a/packages/docs/static/generated/articles-docs-webcodecs-fix-a-mediarecorder-video.png b/packages/docs/static/generated/articles-docs-webcodecs-fix-a-mediarecorder-video.pngnew file mode 100644index 0000000000..cb408855b4Binary files /dev/null and b/packages/docs/static/generated/articles-docs-webcodecs-fix-a-mediarecorder-video.png differ