Skip to content

πŸŽ₯ Make videos programmatically with React

update docs

JonnyBurger8b492ac40d7d
diff --git a/packages/docs/docs/media/cache.mdx b/packages/docs/docs/media/cache.mdx
index cd19ba8c6c..92f914f2b3 100644
--- a/packages/docs/docs/media/cache.mdx
+++ b/packages/docs/docs/media/cache.mdx
@@ -1,4 +1,5 @@
---
+image: /generated/articles-docs-media-cache.png
title: In-memory cache for @remotion/media
sidebar_label: Cache
crumb: 'API - @remotion/media'
diff --git a/packages/docs/docs/media/fallback.mdx b/packages/docs/docs/media/fallback.mdx
index c0bf29943a..dc9ce3236b 100644
--- a/packages/docs/docs/media/fallback.mdx
+++ b/packages/docs/docs/media/fallback.mdx
@@ -1,4 +1,5 @@
---
+image: /generated/articles-docs-media-fallback.png
title: 'Fallback from @remotion/media to <OffthreadVideo> or <Audio>'
sidebar_label: 'Fallback to <OffthreadVideo>'
crumb: '@remotion/media'
diff --git a/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.mdx b/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.mdx
deleted file mode 100644
index 498fe9b26a..0000000000
--- a/packages/docs/docs/miscellaneous/snippets/offthread-video-while-rendering.mdx
+++ /dev/null
@@ -1,27 +0,0 @@
----
-image: /generated/articles-docs-miscellaneous-snippets-offthread-video-while-rendering.png
-title: '<OffthreadVideo /> while rendering'
-crumb: 'Snippets'
----
-
-The following component will only use [`<OffthreadVideo />`](/docs/offthreadvideo) while rendering, but [`<Video />`](/docs/video) in the Player.
-This is useful for attaching a `ref` to the [`<Video />`](/docs/video) tag.
-
-```tsx twoslash
-import {forwardRef} from 'react';
-import {OffthreadVideo, RemotionOffthreadVideoProps, useRemotionEnvironment, Video} from 'remotion';
-
-function OffthreadWhileRenderingRefForwardingFunction(props: RemotionOffthreadVideoProps, ref: React.Ref<HTMLVideoElement>) {
- const env = useRemotionEnvironment();
- const isPreview = !env.isRendering;
-
- if (isPreview) {
- const {imageFormat, ...otherProps} = props;
- return <Video ref={ref} {...otherProps} />;
- }
-
- return <OffthreadVideo {...props} />;
-}
-
-export const OffthreadVideoWhileRendering = forwardRef(OffthreadWhileRenderingRefForwardingFunction);
-```
diff --git a/packages/docs/docs/video-tags.mdx b/packages/docs/docs/video-tags.mdx
index 929d3fd80e..18867057d0 100644
--- a/packages/docs/docs/video-tags.mdx
+++ b/packages/docs/docs/video-tags.mdx
@@ -8,22 +8,44 @@ crumb: '<Video>, <OffthreadVideo>, @remotion/media'
We offer three components for embedding videos into your Remotion composition:
- [`<OffthreadVideo />`](/docs/offthreadvideo) - **our recommendation**, based on a Rust-based frame extractor
-- [`<Video />`](/docs/video) from `remotion` - based on the HTML5 `<video>` element
-- [`<Video />`](/docs/media/video) from `@remotion/media` - an experimental WebCodecs-based component, set to become the default
+- [`<Video />`](/docs/video) from [`remotion`](/docs/remotion) - based on the HTML5 `<video>` element
+- [`<Video />`](/docs/media/video) from [`@remotion/media`](/docs/media) - an experimental WebCodecs-based component, set to become the default
This page offers a comparison to help you decide which tag to use.
-| | [`<OffthreadVideo />`](/docs/offthreadvideo) | [`<Video />`](/docs/video) <br/> [`<Audio />`](/docs/audio) <br/> (`remotion`) | [`<Video />`](/docs/media/video) <br/> [`<Audio />`](/docs/media/audio) (`@remotion/media`) |
-| ---------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
-| **Based on** | Rust + FFmpeg binary | HTML5 `<video>` tag | Mediabunny, WebCodecs |
-| **Frame-perfect** | βœ… | ❌ Not guaranteed | βœ… |
-| **Partial download of asset** | ❌ | Only with `muted` prop | βœ… |
-| **Preview** | HTML5 `<video>` | HTML5 `<video>` | HTML5 `<video>` <br/> Soon: WebCodecs |
-| **Render Speed** | Fast | Medium | <span style={{color: 'green', fontWeight: 'bold'}}> Fastest </span> |
-| **Supported containers** | `.aac`, `.avi`, `.caf`, `.flac`, `.flv`, `.m4a`, `.mkv`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` | `.aac`, `.flac`, `.m4a`, `.mkv`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` | `.aac`, `.flac`, `.mkv`, `.mov`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` |
-| **Supported codecs** | AAC, AC3, AV1, FLAC, H.264, H.265, M4A, MP3, Opus, PCM, ProRes, VP8, VP9, Vorbis | AAC, FLAC, H.264, MP3, Opus, VP8, VP9, Vorbis | AAC, FLAC, H.264, MP3, Opus, VP8, VP9, Vorbis <br/><br/> Planned: Fallback to `<OffthreadVideo>` for unsupported codecs |
-| **HLS Support** | No | [Only during preview](/docs/miscellaneous/snippets/hls) | Planned |
-| **CORS required** | No | No | Yes |
-| **Loopable** | ❌ | βœ… | βœ… |
-| **`playbackRate`** <br/> (Speed Change) | βœ… | βœ… | Planned |
-| **`toneFrequency`** <br/> (Pitch Change) | Only during rendering | Only during rendering | Planned |
+| | [`<OffthreadVideo />`](/docs/offthreadvideo) | [`<Video />`](/docs/video) <br/> [`<Audio />`](/docs/audio) <br/> (`remotion`) | [`<Video />`](/docs/media/video) <br/> [`<Audio />`](/docs/media/audio) (`@remotion/media`) |
+| ---------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
+| **Based on** | Rust + FFmpeg binary | HTML5 `<video>` tag | Mediabunny, WebCodecs |
+| **Frame-perfect** | βœ… | ❌ Not guaranteed | βœ… |
+| **Partial download of asset** | ❌ | Only with `muted` prop | βœ… |
+| **Preview** | HTML5 `<video>` | HTML5 `<video>` | HTML5 `<video>` <br/> Soon: WebCodecs |
+| **Render Speed** | Fast | Medium | <span style={{color: 'green', fontWeight: 'bold'}}> Fastest </span> |
+| **Supported containers** | `.aac`, `.avi`, `.caf`, `.flac`, `.flv`, `.m4a`, `.mkv`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` | `.aac`, `.flac`, `.m4a`, `.mkv`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` | `.aac`, `.flac`, `.mkv`, `.mov`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` |
+| **Supported codecs** | AAC, AC3, AV1, FLAC, H.264, H.265, M4A, MP3, Opus, PCM, ProRes, VP8, VP9, Vorbis | AAC, FLAC, H.264, MP3, Opus, VP8, VP9, Vorbis | AAC, FLAC, H.264, MP3, Opus, VP8, VP9, Vorbis <br/><br/> Fallback to `<OffthreadVideo>` for unsupported codecs |
+| **HLS Support** | No | [Only during preview](/docs/miscellaneous/snippets/hls) | Planned |
+| **CORS required** | No | No | Yes |
+| **Loopable** | ❌ | βœ… | βœ… |
+| **`playbackRate`** <br/> (Speed Change) | βœ… | βœ… | Planned |
+| **`toneFrequency`** <br/> (Pitch Change) | Only during rendering | Only during rendering | Planned |
+
+## Using a different tag in preview and rendering
+
+Use the [`useRemotionEnvironment()`](/docs/use-remotion-environment) hook to render a different component in preview and rendering.
+
+```tsx twoslash title="OffthreadVideo during preview, @remotion/media during rendering"
+import {useRemotionEnvironment, OffthreadVideo, RemotionOffthreadVideoProps} from 'remotion';
+import {experimental_Video as Video, VideoProps} from '@remotion/media';
+
+const OffthreadWhileRenderingRefForwardingFunction: React.FC<{
+ offthreadVideoProps: RemotionOffthreadVideoProps;
+ videoProps: VideoProps;
+}> = ({offthreadVideoProps, videoProps}) => {
+ const env = useRemotionEnvironment();
+
+ if (!env.isRendering) {
+ return <OffthreadVideo {...offthreadVideoProps} />;
+ }
+
+ return <Video {...videoProps} />;
+};
+```
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index d5da5d3dd3..48eb6b7fc7 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1198,7 +1198,6 @@ const sidebars: SidebarsConfig = {
items: [
'miscellaneous/snippets/different-segments-at-different-speeds',
'miscellaneous/snippets/player-in-iframe',
- 'miscellaneous/snippets/offthread-video-while-rendering',
'miscellaneous/snippets/combine-compositions',
],
},
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index fbdde2bf19..e1ac95194a 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -3284,6 +3284,15 @@ export const articles = [
noAi: false,
slug: 'media/audio',
},
+ {
+ id: 'media/cache',
+ title: 'In-memory cache for @remotion/media',
+ relativePath: 'docs/media/cache.mdx',
+ compId: 'articles-docs-media-cache',
+ crumb: 'API - @remotion/media',
+ noAi: false,
+ slug: 'media/cache',
+ },
{
id: 'media/fallback',
title: 'Fallback from @remotion/media to <OffthreadVideo> or <Audio>',
@@ -3574,17 +3583,6 @@ export const articles = [
noAi: false,
slug: 'miscellaneous/snippets/jumpcuts',
},
- {
- id: 'miscellaneous/snippets/offthread-video-while-rendering',
- title: '<OffthreadVideo /> while rendering',
- relativePath:
- 'docs/miscellaneous/snippets/offthread-video-while-rendering.mdx',
- compId:
- 'articles-docs-miscellaneous-snippets-offthread-video-while-rendering',
- crumb: 'Snippets',
- noAi: false,
- slug: 'miscellaneous/snippets/offthread-video-while-rendering',
- },
{
id: 'miscellaneous/snippets/player-in-iframe',
title: 'Embedding a <Player> into an <iframe>',
diff --git a/packages/docs/static/generated/articles-docs-media-cache.png b/packages/docs/static/generated/articles-docs-media-cache.png
new file mode 100644
index 0000000000..a61c4e1621
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-media-cache.png differ
diff --git a/packages/docs/static/generated/articles-docs-media-fallback.png b/packages/docs/static/generated/articles-docs-media-fallback.png
new file mode 100644
index 0000000000..0bfe7bcddd
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-media-fallback.png differ
diff --git a/packages/docs/static/generated/articles-docs-miscellaneous-snippets-offthread-video-while-rendering.png b/packages/docs/static/generated/articles-docs-miscellaneous-snippets-offthread-video-while-rendering.png
deleted file mode 100644
index 24e1e9f393..0000000000
Binary files a/packages/docs/static/generated/articles-docs-miscellaneous-snippets-offthread-video-while-rendering.png and /dev/null differ
diff --git a/packages/docs/vercel.json b/packages/docs/vercel.json
index aa8a83c9d1..5376cc4c88 100644
--- a/packages/docs/vercel.json
+++ b/packages/docs/vercel.json
@@ -457,6 +457,11 @@
"source": "/investors",
"destination": "/docs/investors",
"permanent": false
+ },
+ {
+ "destination": "/docs/video-tags#using-a-different-tag-in-preview-and-rendering",
+ "permanent": false,
+ "source": "/docs/miscellaneous/snippets/offthread-video-while-rendering"
}
]
}