🎥 Make videos programmatically with React
Update video.md
Jonny Burger966d6fc09ab3
diff --git a/packages/docs/docs/video.md b/packages/docs/docs/video.mdindex 9e37cc7123..251c18fd44 100644--- a/packages/docs/docs/video.md+++ b/packages/docs/docs/video.md@@ -3,31 +3,87 @@ title: <Video />id: video----This component allows you to include a video file in your Remotion project. While in the preview, the video will just play in a HTML5 `<video>` tag, during render, the exact frame needed will be extracted.+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).## API / Example-Use an import or require to load an video file and pass it as the `src` prop. 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.+Use an `import` or `require()` statement, a URL, or [`staticFile()`](/docs/staticfile) to load a video and pass it as the `src` prop.-`<Video>` also 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.+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.-`<Video>` has two more helper props: `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.+```tsx twoslash+import { AbsoluteFill, Video } from "remotion";+import video from "./video.webm";++export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video src={video} />+ </AbsoluteFill>+ );+};+```++## Remote video++You can load a video from an URL as well:++```tsx twoslash+import { AbsoluteFill, Video } from "remotion";+// ---cut---+export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video+ src={+ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"+ }+ />+ </AbsoluteFill>+ );+};+```++:::note+During render, Remotion will download the video to include it's audio in the output. If you don't need the audio, you can add the `muted` prop.+:::++## Trim video++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.```tsx twoslash-import { Video } from "remotion";+import { AbsoluteFill, Video } from "remotion";import video from "./video.webm";+// ---cut---export const MyVideo = () => {return (- <div>- <div>Hello World!</div>+ <AbsoluteFill><Videosrc={video}- startFrom={59} // if video is 30fps, then it will start at 2s- endAt={120} // if video is 30fps, then it will end at 4s- style={{ height: 1080 / 2, width: 1920 / 2 }}+ 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/>- </div>+ </AbsoluteFill>+ );+};+```++## Style video++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";++// ---cut---+export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video src={video} style={{ height: 720, width: 1280 }} />+ </AbsoluteFill>);};```@@ -45,7 +101,40 @@ If you would like Remotion to warn you when you import an MP4 video, you can tur## Controlling volume-You can use the `volume` prop to control the loudness of the audio coming from the video. See [Controlling audio](/docs/using-audio#controlling-volume) for more information.+`<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";++// ---cut---+export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video volume={0.5} src={video} />+ </AbsoluteFill>+ );+};+```++```tsx twoslash title="Example of a fade in over 100 frames"+import { AbsoluteFill, interpolate, Video } from "remotion";+import video from "./video.webm";++// ---cut---+export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video+ volume={(f) =>+ interpolate(f, [0, 100], [0, 1], { extrapolateLeft: "clamp" })+ }+ src={video}+ />+ </AbsoluteFill>+ );+};+```## Controlling playback speed@@ -55,6 +144,20 @@ 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 fade in over 100 frames"+import { AbsoluteFill, interpolate, Video } from "remotion";+import video from "./video.webm";++// ---cut---+export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video playbackRate={2} src={video} />+ </AbsoluteFill>+ );+};+```+## See also- [`<Audio />`](/docs/audio)