Skip to content

🎥 Make videos programmatically with React

improve OffthreadVideo, Video and Audio docs

Jonny Burgera984e20ba00c
diff --git a/packages/docs/docs/audio.md b/packages/docs/docs/audio.md
index 0a4eccf66b..c7b45714d3 100644
--- a/packages/docs/docs/audio.md
+++ b/packages/docs/docs/audio.md
@@ -127,15 +127,17 @@ export const MyVideo = () => {
### `toneFrequency`<AvailableFrom v="4.0.47"/>
-Allows you to adjust the pitch of the audio - will only be applied during rendering. It accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
-For example, a `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
-`toneFrequency` should be a positive number between `0.01` (representing the lowest assignable pitch) and `2` (representing the highest assignable pitch). If `toneFrequency` is not specified or null, it defaults to `1`, maintaining the original pitch.
+Adjust the pitch of the audio - will only be applied during rendering.
-## `acceptableTimeShiftInSeconds`<AvailableFrom v="3.2.42"/>
+Accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
+
+A `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
+
+### `acceptableTimeShiftInSeconds`<AvailableFrom v="3.2.42"/>
In the [Remotion Studio](/docs/terminology#remotion-studio) or in the [Remotion Player](/docs/player), Remotion will seek the audio if it gets too much out of sync with Remotion's internal time - be it due to the audio loading or the page being too slow to keep up in real-time. By default, a seek is triggered if `0.45` seconds of time shift is encountered. Using this prop, you can customize the threshold.
-## `allowAmplificationDuringRender`<AvailableFrom v="3.3.17"/>
+### `allowAmplificationDuringRender`<AvailableFrom v="3.3.17"/>
Make values for [`volume`](#volume) greater than `1` result in amplification during renders.
In the Remotion Studio, the volume will be limited to `1`, since the browser cannot amplify audio.
diff --git a/packages/docs/docs/offthreadvideo.md b/packages/docs/docs/offthreadvideo.md
index 14d2e4e763..fa2ff721ce 100644
--- a/packages/docs/docs/offthreadvideo.md
+++ b/packages/docs/docs/offthreadvideo.md
@@ -41,9 +41,37 @@ export const MyComposition = () => {
## Props
-The props [`volume`](/docs/video#volume), [`playbackRate`](/docs/video#playbackrate), [`muted`](/docs/video#muted) and [`acceptableTimeShiftInSeconds`](/docs/video#acceptabletimeshiftinseconds) are supported and work the same as in [`<Video>`](/docs/video).
+### `startFrom`
-The props [`onError`](/docs/img#onerror), `className` and `style` are supported and get passed to the underlying HTML element. Remember that during render, this is a `<img>` element, and during Preview, this is a `<video>` element.
+Will remove a portion of the video at the beginning.
+
+In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.
+
+By passing `startFrom={60}`, the playback starts immediately, but with the first 2 seconds of the video trimmed away.
+By passing `endAt={120}`, any video after the 4 second mark in the file will be trimmed away.
+
+The video will play the range from `00:02:00` to `00:04:00`, meaning the video will play for 2 seconds.
+
+```tsx twoslash
+import { AbsoluteFill, OffthreadVideo, staticFile } from "remotion";
+
+// ---cut---
+export const MyComposition = () => {
+ return (
+ <AbsoluteFill>
+ <OffthreadVideo
+ src={staticFile("video.webm")}
+ startFrom={60}
+ endAt={120}
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+### `endAt`
+
+Removes a portion of the video at the end. See [`startAt`](/docs/video#startfrom) for an explanation.
### `transparent`<AvailableFrom v="4.0.0" />
@@ -52,12 +80,42 @@ If set to `true`, frames will be extracted as PNG, enabling transparency but als
If set to `false`(_default_), frames will be extracted as bitmap (BMP), which is faster.
-### ~~`imageFormat` <AvailableFrom v="3.0.22" />~~
+### `volume`
-_removed in v4.0.0_
+Allows you to control the volume for the whole track or change it on a per-frame basis. Refer to the [using audio](/docs/using-audio#controlling-volume) guide to learn how to use it.
-Either `jpeg` or `png`. Default `jpeg`.
-With `png`, transparent videos (VP8, VP9, ProRes) can be displayed, however it is around 40% slower, with VP8 videos being [much slower](/docs/slow-method-to-extract-frame).
+```tsx twoslash title="Example using static volume"
+import { AbsoluteFill, OffthreadVideo, staticFile } from "remotion";
+
+// ---cut---
+export const MyComposition = () => {
+ return (
+ <AbsoluteFill>
+ <OffthreadVideo volume={0.5} src={staticFile("video.webm")} />
+ </AbsoluteFill>
+ );
+};
+```
+
+### `style`
+
+You can pass any style you can pass to a native HTML element. Keep in mind that during rendering, `<OffthreadVideo>` renders an [`<Img>`](/docs/img) tag, but a `<video>` tag is used during preview.
+
+```tsx twoslash
+import { AbsoluteFill, Img, staticFile } from "remotion";
+
+// ---cut---
+export const MyComposition = () => {
+ return (
+ <AbsoluteFill>
+ <Img
+ src={staticFile("video.webm")}
+ style={{ height: 720, width: 1280 }}
+ />
+ </AbsoluteFill>
+ );
+};
+```
### `allowAmplificationDuringRender`<AvailableFrom v="3.3.17" />
@@ -66,17 +124,85 @@ During Preview, the volume will be limited to `1`, since the browser cannot ampl
### `toneFrequency`<AvailableFrom v="4.0.47"/>
-Allows you to adjust the pitch of the audio - will only be applied during rendering. It accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
-For example, a `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
-`toneFrequency` should be a positive number between `0.01` (representing the lowest assignable pitch) and `2` (representing the highest assignable pitch). If `toneFrequency` is not specified or null, it defaults to `1`, maintaining the original pitch.
+Adjust the pitch of the audio - will only be applied during rendering.
+
+Accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
+
+A `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
### `onError`
Handle an error playing the video. From v3.3.89, if you pass an `onError` callback, then no exception will be thrown. Previously, the error could not be caught.
+### `playbackRate`<AvailableFrom v="2.2.0" />
+
+Controls the speed of the video. `1` is the default and means regular speed, `0.5` slows down the video so it's twice as long and `2` speeds up the video so it's twice as fast.
+
+While Remotion doesn't limit the range of possible playback speeds, in development mode the [`HTMLMediaElement.playbackRate`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate) API is used which throws errors on extreme values. At the time of writing, Google Chrome throws an exception if the playback rate is below `0.0625` or above `16`.
+
+```tsx twoslash title="Example of a video playing twice as fast"
+import { AbsoluteFill, OffthreadVideo, staticFile } from "remotion";
+
+// ---cut---
+export const MyComposition = () => {
+ return (
+ <AbsoluteFill>
+ <OffthreadVideo playbackRate={2} src={staticFile("video.webm")} />
+ </AbsoluteFill>
+ );
+};
+```
+
+### `muted`
+
+You can drop the audio of the video by adding a `muted` prop:
+
+```tsx twoslash title="Example of a muted video"
+import { AbsoluteFill, OffthreadVideo } from "remotion";
+// ---cut---
+export const MyComposition = () => {
+ return (
+ <AbsoluteFill>
+ <OffthreadVideo
+ muted
+ src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
+ />
+ </AbsoluteFill>
+ );
+};
+```
+
+### `acceptableTimeShiftInSeconds`<AvailableFrom v="3.2.42" />
+
+In the [Studio](/docs/terminology#remotion-studio) or in the [Remotion Player](/docs/player), Remotion will seek the video if it gets too much out of sync with Remotion's internal time - be it due to the video loading or the page being too slow to keep up in real-time. By default, a seek is triggered if `0.45` seconds of time shift is encountered. Using this prop, you can customize the threshold.
+
+### `allowAmplificationDuringRender`<AvailableFrom v="3.3.17" />
+
+Make values for [`volume`](#volume) greater than `1` result in amplification during renders.
+During Preview, the volume will be limited to `1`, since the browser cannot amplify audio.
+
+### `toneFrequency`<AvailableFrom v="4.0.47"/>
+
+Adjust the pitch of the audio - will only be applied during rendering.
+
+Accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
+
+A `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
+
+### ~~`imageFormat` <AvailableFrom v="3.0.22" />~~
+
+_removed in v4.0.0_
+
+Either `jpeg` or `png`. Default `jpeg`.
+With `png`, transparent videos (VP8, VP9, ProRes) can be displayed, however it is around 40% slower, with VP8 videos being [much slower](/docs/slow-method-to-extract-frame).
+
+### Other props
+
+The props [`onError`](/docs/img#onerror), `className` and `style` are supported and get passed to the underlying HTML element. Remember that during render, this is a `<img>` element, and during Preview, this is a `<video>` element.
+
## Performance tips
-Avoid embedding a video beyond it's end (for example: Rendering a 5 second video inside 10 second composition). To create parity with the `<Video>` element, the video still displays its last frame in that case. However, to fetch the last frame specifically is a significantly more expensive operation than a frame from a known timestamp.
+Only set `transparent` to `true` if you need transparency. It is slower than non-transparent frame extraction.
## Looping a video
diff --git a/packages/docs/docs/video.md b/packages/docs/docs/video.md
index 63685a8187..de983d5507 100644
--- a/packages/docs/docs/video.md
+++ b/packages/docs/docs/video.md
@@ -7,6 +7,8 @@ crumb: "API"
This component allows you to include a video file in your Remotion project. It wraps the native [`HTMLVideoElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement).
+Use [`<OffthreadVideo>`](/docs/offthreadvideo) by default instead which is in general faster.
+
## API
[Put a video file into the `public/` folder](/docs/assets) and use [`staticFile()`](/docs/staticfile) to reference it.
@@ -39,12 +41,11 @@ export const MyComposition = () => {
};
```
-### `startFrom` / `endAt`
+## Props
-`<Video>` has two more helper props you can use:
+### `startFrom`
-- `startFrom` will remove a portion of the video at the beginning
-- `endAt` will remove a portion of the video at the end
+Will remove a portion of the video at the beginning.
In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.
@@ -66,9 +67,13 @@ export const MyComposition = () => {
};
```
+### `endAt`
+
+Removes a portion of the video at the end. See [`startAt`](/docs/video#startfrom) for an explanation.
+
### `style`
-You can pass any style you can pass to a native `<video>` element. This is how you set it's size for example:
+You can pass any style you can pass to a native `<video>` element. For example, set its size:
```tsx twoslash
import { AbsoluteFill, staticFile, Video } from "remotion";
@@ -88,7 +93,7 @@ export const MyComposition = () => {
### `volume`
-`<Video>` accepts a `volume` prop which allows you to control the volume for the whole track or change it on a per-frame basis. Refer to the [using audio](/docs/using-audio#controlling-volume) guide to learn how to use it.
+Allows you to control the volume for the whole track or change it on a per-frame basis. Refer to the [using audio](/docs/using-audio#controlling-volume) guide to learn how to use it.
```tsx twoslash title="Example using static volume"
import { AbsoluteFill, staticFile, Video } from "remotion";
@@ -123,7 +128,7 @@ export const MyComposition = () => {
### `playbackRate`<AvailableFrom v="2.2.0" />
-You can use the `playbackRate` prop to control the speed of the video. `1` is the default and means regular speed, `0.5` slows down the video so it's twice as long and `2` speeds up the video so it's twice as fast.
+Controls the speed of the video. `1` is the default and means regular speed, `0.5` slows down the video so it's twice as long and `2` speeds up the video so it's twice as fast.
While Remotion doesn't limit the range of possible playback speeds, in development mode the [`HTMLMediaElement.playbackRate`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate) API is used which throws errors on extreme values. At the time of writing, Google Chrome throws an exception if the playback rate is below `0.0625` or above `16`.
@@ -159,9 +164,11 @@ export const MyComposition = () => {
};
```
+This has the benefit that Remotion will not have to download the video file during rendering in order to extract the audio from it.
+
### `loop`<AvailableFrom v="3.2.29" />
-You can use the `loop` prop to loop a video.
+Makes the video loop indefinitely.
```tsx twoslash title="Example of a looped video"
import { AbsoluteFill, Video } from "remotion";
@@ -189,9 +196,11 @@ During Preview, the volume will be limited to `1`, since the browser cannot ampl
### `toneFrequency`<AvailableFrom v="4.0.47"/>
-Allows you to adjust the pitch of the audio - will only be applied during rendering. It accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
-For example, a `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
-`toneFrequency` should be a positive number between `0.01` (representing the lowest assignable pitch) and `2` (representing the highest assignable pitch). If `toneFrequency` is not specified or null, it defaults to `1`, maintaining the original pitch.
+Adjust the pitch of the audio - will only be applied during rendering.
+
+Accepts a number between `0.01` and `2`, where `1` represents the original pitch. Values less than `1` will decrease the pitch, while values greater than `1` will increase it.
+
+A `toneFrequency` of 0.5 would lower the pitch by half, and a `toneFrequency` of `1.5` would increase the pitch by 50%.
### `onError`