🎥 Make videos programmatically with React
improve <Video> docs
Jonny Burgere7f919685969
diff --git a/packages/docs/docs/freeze.md b/packages/docs/docs/freeze.mdindex 44b246798f..78c324f456 100644--- a/packages/docs/docs/freeze.md+++ b/packages/docs/docs/freeze.md@@ -47,5 +47,5 @@ const MyVideo = () => {## See also- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/freeze.tsx)-- [`<Video/>` Playback speed](/docs/video#controlling-playback-speed)+- [`<Video/>` Playback speed](/docs/video#playbackrate)- [`useCurrentFrame()`](/docs/use-current-frame)diff --git a/packages/docs/docs/offthreadvideo.md b/packages/docs/docs/offthreadvideo.mdindex 62e884cd9d..852a8654d0 100644--- a/packages/docs/docs/offthreadvideo.md+++ b/packages/docs/docs/offthreadvideo.md@@ -5,7 +5,7 @@ title: "<OffthreadVideo>"_Available from Remotion 3.0.11_-This component imports and displays a video, similar to [`<Video/>`](/docs/video), but during rendering, extracts the exact frame from the video and displays it in a `<Img>` tag. This extraction process happens outside the browser using FFMPEG.+This component imports and displays a video, similar to [`<Video/>`](/docs/video), but during rendering, extracts the exact frame from the video and displays it in a [`<Img>`](/docs/img) tag. This extraction process happens outside the browser using FFMPEG.This component was designed to combat limitations of the default `<Video>` element. See: [`<Video>` vs `<OffthreadVideo>`](/docs/video-vs-offthreadvideo).@@ -15,25 +15,33 @@ This component was designed to combat limitations of the default `<Video>` elemeimport { AbsoluteFill, OffthreadVideo, staticFile } from "remotion";export const MyVideo = () => {- const video = staticFile("video.webm");-return (<AbsoluteFill>- <OffthreadVideo src={video} />+ <OffthreadVideo src={staticFile("video.webm")} /></AbsoluteFill>);};```-:::note-You can also pass a URL as a `src` to load a video remotely.-:::+You can load a video from an URL as well:++```tsx twoslash+import { AbsoluteFill, OffthreadVideo } from "remotion";+// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <OffthreadVideo src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" />+ </AbsoluteFill>+ );+};+```## Props-The props `volume`, `playbackRate` and `muted` are supported and work the same as in [`<Video>`](/docs/video).+The props [`volume`](/docs/video#volume), [`playbackRate`](/docs/video#playbackrate) and [`muted`](/docs/video#muted) are supported and work the same as in [`<Video>`](/docs/video).-The props `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.+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.### `imageFormat`@@ -44,7 +52,7 @@ With `png`, transparent videos (VP8, VP9, ProRes) can be displayed, however it i## 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 display it's 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.+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.## See alsodiff --git a/packages/docs/docs/video.md b/packages/docs/docs/video.mdindex fd952cc2b8..630d9a7e6c 100644--- a/packages/docs/docs/video.md+++ b/packages/docs/docs/video.md@@ -5,33 +5,30 @@ id: videoThis 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).-## API / Example+## API-Use an `import` or `require()` statement, a URL, or [`staticFile()`](/docs/staticfile) to load a video and pass it as the `src` prop.+[Put a video file into the `public/` folder](/docs/assets) and use [`staticFile()`](/docs/staticfile) to reference it.All the props that the native `<video>` element accepts (except `autoplay` and `controls`) will be forwarded (but of course not all are useful for Remotion). This means you can use all CSS to style the video.```tsx twoslash-import { AbsoluteFill, Video } from "remotion";-import video from "./video.webm";+import { AbsoluteFill, staticFile, Video } from "remotion";-export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill>- <Video src={video} />+ <Video src={staticFile("video.webm")} /></AbsoluteFill>);};```-## Remote video-You can load a video from an URL as well:```tsx twoslashimport { AbsoluteFill, Video } from "remotion";// ---cut----export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill><Video src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" />@@ -40,99 +37,89 @@ export const MyVideo = () => {};```-:::note-During render, Remotion will download the video to include its audio in the output. If you don't need the audio, you can add the `muted` prop.-:::+### `startFrom` / `endAt`++`<Video>` has two more helper props you can use:++- `startFrom` will remove a portion of the video at the beginning+- `endAt` will remove a portion of the video at the end-## Trim video+In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.-Use `startFrom` and `endAt` to define when the video should start and end. Both are optional and do not get forwarded to the native `<video>` element but tell Remotion which portion of the video to use.+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, Video } from "remotion";-import video from "./video.webm";+import { AbsoluteFill, staticFile, Video } from "remotion";// ---cut----export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill>- <Video- src={video}- startFrom={59} // If the video is 30fps, then it will start at 2s- endAt={120} // If the video is 30fps, then it will end at 4s- />+ <Video src={staticFile("video.webm")} startFrom={60} endAt={120} /></AbsoluteFill>);};```-## Style video+### `style`You can pass any style you can pass to a native `<video>` element. This is how you set it's size for example:```tsx twoslash-import { AbsoluteFill, Video } from "remotion";-import video from "./video.webm";+import { AbsoluteFill, staticFile, Video } from "remotion";// ---cut----export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill>- <Video src={video} style={{ height: 720, width: 1280 }} />+ <Video+ src={staticFile("video.webm")}+ style={{ height: 720, width: 1280 }}+ /></AbsoluteFill>);};```-## Codec support--Pay attention to the codec of the video that you are importing. During the render process, Chrome needs to support playing the video that you are embedding. If Remotion cannot find a preinstalled version of Chrome, it will download a Chromium executable which does not support the playback of H264 (common codec for MP4 videos). To work around this problem, you have multiple options:--- Tell Remotion which path for Chrome to use by using the command line flag `--browser-executable` or [configure](/docs/config#setbrowserexecutable) `Config.Puppeteer.setBrowserExecutable()` in a config file.-- Convert your videos to WebM before embedding them.--Prior to Remotion 1.5, Remotion will always use an internal Puppeteer binary and MP4 videos are therefore not supported.--If you would like Remotion to warn you when you import an MP4 video, you can turn on the `@remotion/no-mp4-import` ESLint rule.--## Controlling volume+### `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.```tsx twoslash title="Example using static volume"-import { AbsoluteFill, Video } from "remotion";-import video from "./video.webm";+import { AbsoluteFill, staticFile, Video } from "remotion";// ---cut----export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill>- <Video volume={0.5} src={video} />+ <Video volume={0.5} src={staticFile("video.webm")} /></AbsoluteFill>);};``````tsx twoslash title="Example of a fade in over 100 frames"-import { AbsoluteFill, interpolate, Video } from "remotion";-import video from "./video.webm";+import { AbsoluteFill, interpolate, staticFile, Video } from "remotion";// ---cut----export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill><Videovolume={(f) =>interpolate(f, [0, 100], [0, 1], { extrapolateLeft: "clamp" })}- src={video}+ src={staticFile("video.webm")}/></AbsoluteFill>);};```-## Controlling playback speed+### `playbackRate`_Available from v2.2_@@ -141,19 +128,50 @@ You can use the `playbackRate` prop to control the speed of the video. `1` is thWhile 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, interpolate, Video } from "remotion";-import video from "./video.webm";+import { AbsoluteFill, staticFile, Video } from "remotion";// ---cut----export const MyVideo = () => {+export const MyComposition = () => {return (<AbsoluteFill>- <Video playbackRate={2} src={video} />+ <Video playbackRate={2} src={staticFile("video.webm")} /></AbsoluteFill>);};```+### `muted`++You can drop the audio of the video by adding a `muted` prop:++```tsx twoslash+import { AbsoluteFill, Video } from "remotion";+// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <Video+ muted+ src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"+ />+ </AbsoluteFill>+ );+};+```++Remotion will download the whole video during render in order to mix its audio. If the video contains a silent audio track, you can add the muted property to signal to Remotion that it does not need to download the video and make the render more efficient.++## Codec support++Pay attention to the codec of the video that you are importing. During the render process, Chrome needs to support playing the video that you are embedding. If Remotion cannot find a preinstalled version of Chrome, it will download a Chromium executable which does not support the playback of H264 (common codec for MP4 videos). To work around this problem, you have multiple options:++- Tell Remotion which path for Chrome to use by using the command line flag `--browser-executable` or [configure](/docs/config#setbrowserexecutable) `Config.Puppeteer.setBrowserExecutable()` in a config file.+- Convert your videos to WebM before embedding them.++Prior to Remotion 1.5, Remotion will always use an internal Puppeteer binary and MP4 videos are therefore not supported.++If you would like Remotion to warn you when you import an MP4 video, you can turn on the `@remotion/no-mp4-import` ESLint rule.+## Alternative: `<OffthreadVideo>`[`<OffthreadVideo>`](/docs/offthreadvideo) is a drop-in alternative to `<Video>`. To decide which tag to use, see: [`<Video>` vs `<OffthreadVideo>`](/docs/video-vs-offthreadvideo)