Skip to content

πŸŽ₯ Make videos programmatically with React

Docs: Recommend @remotion/media for videos (#8902)

Jonny Burger4812452b8725
diff --git a/packages/docs/components/GreenscreenExamples/index.tsx b/packages/docs/components/GreenscreenExamples/index.tsx
index e72a048a9e..ae7b31b58d 100644
--- a/packages/docs/components/GreenscreenExamples/index.tsx
+++ b/packages/docs/components/GreenscreenExamples/index.tsx
@@ -1,6 +1,7 @@
+import {Video} from '@remotion/media';
import {Player} from '@remotion/player';
import React, {useCallback, useRef} from 'react';
-import {AbsoluteFill, OffthreadVideo, useVideoConfig} from 'remotion';
+import {AbsoluteFill, useVideoConfig} from 'remotion';
export const VideoOnCanvas: React.FC = () => {
const canvas = useRef<HTMLCanvasElement>(null);
@@ -27,7 +28,7 @@ export const VideoOnCanvas: React.FC = () => {
return (
<AbsoluteFill>
<AbsoluteFill>
- <OffthreadVideo
+ <Video
onVideoFrame={onVideoFrame}
style={{opacity: 0}}
trimBefore={300}
diff --git a/packages/docs/docs/video-manipulation.mdx b/packages/docs/docs/video-manipulation.mdx
index 1313b2e0a7..95671a1f62 100644
--- a/packages/docs/docs/video-manipulation.mdx
+++ b/packages/docs/docs/video-manipulation.mdx
@@ -8,7 +8,7 @@ crumb: 'How To'
import {VideoCanvasExamples} from '../components/GreenscreenExamples/index';
-You can draw frames of a [`<OffthreadVideo>`](/docs/offthreadvideo), [`<Video>`](/docs/media/video) or a [`<Html5Video>`](/docs/html5-video) onto a `<canvas>` element using the [`drawImage()`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage) API.
+You can draw frames of a [`<Video>` from `@remotion/media`](/docs/media/video), [`<OffthreadVideo>`](/docs/offthreadvideo) or a [`<Html5Video>`](/docs/html5-video) onto a `<canvas>` element using the [`drawImage()`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage) API.
:::note
During preview, makes use of the [`requestVideoFrameCallback()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/requestVideoFrameCallback) API.
@@ -17,18 +17,19 @@ Browser support: Firefox 130 (August 2024), Chrome 83, Safari 15.4.
## Basic example
-In this example, an [`<OffthreadVideo>`](/docs/offthreadvideo) is rendered and made invisible.
+In this example, a [`<Video>` from `@remotion/media`](/docs/media/video) is rendered and made invisible.
+
Every frame that is emitted is drawn to a Canvas and a grayscale [`filter`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter) is applied.
<VideoCanvasExamples />
<br />
```tsx twoslash
-import React, {useCallback, useEffect, useRef} from 'react';
-import {AbsoluteFill, useVideoConfig, OffthreadVideo} from 'remotion';
+import React, {useCallback, useRef} from 'react';
+import {Video} from '@remotion/media';
+import {AbsoluteFill, useVideoConfig} from 'remotion';
// ---cut---
export const VideoOnCanvas: React.FC = () => {
- const video = useRef<HTMLVideoElement>(null);
const canvas = useRef<HTMLCanvasElement>(null);
const {width, height} = useVideoConfig();
@@ -53,7 +54,7 @@ export const VideoOnCanvas: React.FC = () => {
return (
<AbsoluteFill>
<AbsoluteFill>
- <OffthreadVideo
+ <Video
// Hide the original video tag
style={{opacity: 0}}
onVideoFrame={onVideoFrame}
diff --git a/packages/docs/docs/video-tags.mdx b/packages/docs/docs/video-tags.mdx
index 430bd88257..93ef14f364 100644
--- a/packages/docs/docs/video-tags.mdx
+++ b/packages/docs/docs/video-tags.mdx
@@ -2,33 +2,33 @@
image: /generated/articles-docs-video-tags.png
id: video-tags
title: Comparison of video tags
-crumb: '<Video>, <Html5Video>, <OffthreadVideo>'
+crumb: '<Video>, <OffthreadVideo>, <Html5Video>'
---
We offer three components for embedding videos into your Remotion composition:
-- [`<OffthreadVideo />`](/docs/offthreadvideo) - **our recommendation for now**, based on a Rust-based frame extractor
+- [`<Video />`](/docs/media/video) from [`@remotion/media`](/docs/media) - **recommended for new code**, based on Mediabunny and WebCodecs
+- [`<OffthreadVideo />`](/docs/offthreadvideo) from [`remotion`](/docs/remotion) - based on a Rust-based frame extractor
- [`<Html5Video />`](/docs/html5-video) from [`remotion`](/docs/remotion) (previously named `<Video>`) - based on the HTML5 `<video>` element
-- [`<Video />`](/docs/media/video) from [`@remotion/media`](/docs/media) - a WebCodecs-based component, **soon to become the default**
This page offers a comparison to help you decide which tag to use.
-| | [`<OffthreadVideo />`](/docs/offthreadvideo) | [`<Html5Video />`](/docs/html5-video) <br/> [`<Html5Audio />`](/docs/html5-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>` | 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`, `.m3u8`, `.mkv`, `.mov`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` <br/><br/> Fallback to `<OffthreadVideo>` for unsupported containers |
-| **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** | [Chrome v142+, only during preview](/docs/hls) | [Only during preview](/docs/hls) | [βœ… Supported](/docs/hls) |
-| **CORS required** | No | No | Yes |
-| **Loopable** | ❌ | βœ… | βœ… |
-| **`playbackRate`** <br/> (Speed Change) | βœ… | βœ… | βœ… |
-| **`toneFrequency`** <br/> (Pitch Change) | Only during rendering | Only during rendering | Only during rendering |
-| **[Three.js texture](/docs/videos/as-threejs-texture)** | [`useOffthreadVideoTexture()`](/docs/use-offthread-video-texture) | [ `useVideoTexture()` ](/docs/use-video-texture) | [Snippet](/docs/videos/as-threejs-texture) - works best |
-| **[Client-side rendering](/docs/client-side-rendering)** | ❌ | ❌ | βœ… |
+| | [`<Video />`](/docs/media/video) <br/> [`<Audio />`](/docs/media/audio) (`@remotion/media`) | [`<OffthreadVideo />`](/docs/offthreadvideo) | [`<Html5Video />`](/docs/html5-video) <br/> [`<Html5Audio />`](/docs/html5-audio) <br/> (`remotion`) |
+| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
+| **Based on** | Mediabunny, WebCodecs | Rust + FFmpeg binary | HTML5 `<video>` tag |
+| **Frame-perfect** | βœ… | βœ… | ❌ Not guaranteed |
+| **Partial download of asset** | βœ… | ❌ | Only with `muted` prop |
+| **Preview** | WebCodecs | HTML5 `<video>` | HTML5 `<video>` |
+| **Render Speed** | <span style={{color: 'green', fontWeight: 'bold'}}> Fastest </span> | Fast | Medium |
+| **Supported containers** | `.aac`, `.flac`, `.m3u8`, `.mkv`, `.mov`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` <br/><br/> Fallback to `<OffthreadVideo>` for unsupported containers | `.aac`, `.avi`, `.caf`, `.flac`, `.flv`, `.m4a`, `.mkv`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` | `.aac`, `.flac`, `.m4a`, `.mkv`, `.mp3`, `.mp4`, `.ogg`, `.wav`, `.webm` |
+| **Supported codecs** | AAC, FLAC, H.264, MP3, Opus, VP8, VP9, Vorbis <br/><br/> Fallback to `<OffthreadVideo>` for unsupported 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 |
+| **HLS Support** | [βœ… Supported](/docs/hls) | [Chrome v142+, only during preview](/docs/hls) | [Only during preview](/docs/hls) |
+| **CORS required** | Yes | No | No |
+| **Loopable** | βœ… | ❌ | βœ… |
+| **`playbackRate`** <br/> (Speed Change) | βœ… | βœ… | βœ… |
+| **`toneFrequency`** <br/> (Pitch Change) | Only during rendering | Only during rendering | Only during rendering |
+| **[Three.js texture](/docs/videos/as-threejs-texture)** | [Snippet](/docs/videos/as-threejs-texture) - works best | [`useOffthreadVideoTexture()`](/docs/use-offthread-video-texture) | [ `useVideoTexture()` ](/docs/use-video-texture) |
+| **[Client-side rendering](/docs/client-side-rendering)** | βœ… | ❌ | ❌ |
## Using a different tag in preview and rendering
diff --git a/packages/docs/docs/videos/index.mdx b/packages/docs/docs/videos/index.mdx
index 8f00bde130..46549cbe78 100644
--- a/packages/docs/docs/videos/index.mdx
+++ b/packages/docs/docs/videos/index.mdx
@@ -5,14 +5,14 @@ sidebar_label: Adding a video
crumb: 'How To'
---
-You can embed existing videos into Remotion by using the [`<OffthreadVideo>`](/docs/offthreadvideo) component.
+You can embed existing videos into Remotion by using the [`<Video>` from `@remotion/media`](/docs/media/video) component.
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src="https://remotion.media/BigBuckBunny.mp4" />;
+ return <Video src="https://remotion.media/BigBuckBunny.mp4" />;
};
```
@@ -22,35 +22,39 @@ Put a file into the [`public` folder](/docs/terminology/public-dir) and referenc
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src={staticFile('video.mp4')} />;
+ return <Video src={staticFile('video.mp4')} />;
};
```
## Trimming
-By using the [`trimBefore`](/docs/offthreadvideo#trimbefore) prop, you can remove the first few seconds of the video.
+By using the [`trimBefore`](/docs/media/video#trimbefore) prop, you can remove the first few seconds of the video.
+
In the example below, the first two seconds of the video are skipped (assuming a composition FPS of 30).
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src={staticFile('video.mp4')} trimBefore={60} />;
+ return <Video src={staticFile('video.mp4')} trimBefore={60} />;
};
```
-Similarly, you can use [`trimAfter`](/docs/offthreadvideo#trimafter) to trim the end of the video.
+Similarly, you can use [`trimAfter`](/docs/media/video#trimafter) to trim the end of the video.
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src={staticFile('video.mp4')} trimBefore={60} trimAfter={120} />;
+ return <Video src={staticFile('video.mp4')} trimBefore={60} trimAfter={120} />;
};
```
@@ -61,12 +65,13 @@ In the example below, the video will start playing at frame 60.
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile, Sequence} from 'remotion';
+import {Video} from '@remotion/media';
+import {Sequence, staticFile} from 'remotion';
export const MyComp: React.FC = () => {
return (
<Sequence from={60}>
- <OffthreadVideo src={staticFile('video.mp4')} />
+ <Video src={staticFile('video.mp4')} />
</Sequence>
);
};
@@ -79,11 +84,12 @@ You'll find the properties `width`, `height`, `position`, `left`, `top`, `right`
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
return (
- <OffthreadVideo
+ <Video
src={staticFile('video.mp4')}
style={{
width: 640,
@@ -99,25 +105,27 @@ export const MyComp: React.FC = () => {
## Volume
-You can set the volume of the video using the [`volume`](/docs/offthreadvideo#volume) prop.
+You can set the volume of the video using the [`volume`](/docs/media/video#volume) prop.
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src={staticFile('video.mp4')} volume={0.5} />;
+ return <Video src={staticFile('video.mp4')} volume={0.5} />;
};
```
-You can also mute a video using the [`muted`](/docs/offthreadvideo#muted) prop.
+You can also mute a video using the [`muted`](/docs/media/video#muted) prop.
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src={staticFile('video.mp4')} muted />;
+ return <Video src={staticFile('video.mp4')} muted />;
};
```
@@ -125,14 +133,15 @@ See [Using Audio](/docs/audio/volume) for more ways you can control volume.
## Speed
-You can use the [`playbackRate`](/docs/offthreadvideo#playbackrate) prop to change the speed of the video.
+You can use the [`playbackRate`](/docs/media/video#playbackrate) prop to change the speed of the video.
```tsx twoslash
import React from 'react';
-import {OffthreadVideo, staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
export const MyComp: React.FC = () => {
- return <OffthreadVideo src={staticFile('video.mp4')} playbackRate={2} />;
+ return <Video src={staticFile('video.mp4')} playbackRate={2} />;
};
```
@@ -140,7 +149,19 @@ This only works if the speed is constant. See also: [Changing the speed of a vid
## Looping
-See: [Looping an `<OffthreadVideo>`](/docs/offthreadvideo#looping-a-offthreadvideo)
+Use the [`loop`](/docs/media/video#loop) prop to restart the video when it reaches the end.
+
+```tsx twoslash title="Looping a video"
+import React from 'react';
+import {Video} from '@remotion/media';
+import {staticFile} from 'remotion';
+
+export const MyComp: React.FC = () => {
+ return <Video src={staticFile('video.mp4')} loop />;
+};
+```
+
+To learn how looping interacts with `trimBefore` and `trimAfter`, see [Order of operations](/docs/audio/order-of-operations).
## GIFs
@@ -148,5 +169,6 @@ See: [Using GIFs](/docs/gif)
## See also
-- [`<OffthreadVideo>`](/docs/offthreadvideo)
+- [`<Video>` from `@remotion/media`](/docs/media/video)
+- [Comparison of video tags](/docs/video-tags)
- [Using Audio](/docs/using-audio)