🎥 Make videos programmatically with React
final
Hunain Ahmed71ba0f1561a8
diff --git a/packages/docs/components/TableOfContents/api.tsx b/packages/docs/components/TableOfContents/api.tsxindex a845aaa543..13bcf89da5 100644--- a/packages/docs/components/TableOfContents/api.tsx+++ b/packages/docs/components/TableOfContents/api.tsx@@ -1,5 +1,6 @@import React from 'react';import {TableOfContents as AnimatedEmojiTableOfContents} from '../../docs/animated-emoji/TableOfContents';+import { TableOfContents as NewVideoTableOfContents } from '../../docs/new-video/table-of-contents';import {TableOfContents as CaptionsTableOfContents} from '../../docs/captions/TableOfContents';import {TableOfContents as EnableScssTableOfContents} from '../../docs/enable-scss/TableOfContents';import {TableOfContents as FontsTableOfContents} from '../../docs/fonts-api/TableOfContents';@@ -59,6 +60,11 @@ export const TableOfContents: React.FC = () => {etc.</p><RemotionTableOfContents />+ <h2>@remotion/new-video</h2>+ <p>+ The experimental <code><NewVideo /></code> for embedding videos.+ </p>+ <NewVideoTableOfContents /><h2>@remotion/bundler</h2><p>Create a Webpack bundle from Node.JS </p><BundlerTableOfContents />diff --git a/packages/docs/docs/new-video/index.mdx b/packages/docs/docs/new-video/index.mdxnew file mode 100644index 0000000000..4f5b84556c--- /dev/null+++ b/packages/docs/docs/new-video/index.mdx@@ -0,0 +1,303 @@+---+image: /generated/articles-docs-new-video-index.png+title: '<NewVideo>'+crumb: 'API'+---++:::warning+**Experimental Tag**: This tag is currently under development and experimental phase, which means that it can still be used but the API is unstable.+:::++This component imports and displays a video, similar to [`<OffthreadVideo/>`](/docs/offthreadvideo) but during rendering, extracts the exact frame from the video using [`extractFrames()`](/docs/webcodecs/extract-frames) and displays it in a `<canvas>` tag, this ensures that the video is rendered with high accuracy and supports a wide range of codecs more reliably, significantly reducing the [flickering issues](/docs/flickering).++## Example++```tsx twoslash+import {AbsoluteFill, staticFile} from 'remotion';+import {NewVideo} from '@remotion/new-video'++export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <NewVideo src={staticFile('video.webm')} />+ </AbsoluteFill>+ );+};+```++You can load a video from an URL as well:++```tsx twoslash+import {AbsoluteFill} from 'remotion';+import {NewVideo} from '@remotion/new-video'+// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" />+ </AbsoluteFill>+ );+};+```++## Props++### `src`++The URL of the video to be rendered. Can be a remote URL or a local file referenced with [`staticFile()`](/docs/staticfile).++### `trimBefore?`<AvailableFrom v="4.0.319"/>++Will remove a portion of the video at the beginning (left side).++In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.++By passing `trimBefore={60}`, the playback starts immediately, but with the first 2 seconds of the video trimmed away.+By passing `trimAfter={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.++For exact behavior, see: [Order of operations](/docs/audio/order-of-operations).++```tsx twoslash+import {AbsoluteFill, staticFile} from 'remotion';+import {NewVideo} from '@remotion/new-video'++// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo src={staticFile('video.webm')} trimBefore={60} trimAfter={120} />+ </AbsoluteFill>+ );+};+```++### `trimAfter?`<AvailableFrom v="4.0.319"/>++Removes a portion of the video at the end (right side). See [`trimBefore`](/docs/new-video#trimbefore) for an explanation.++### ~~`startFrom?`~~++:::note Deprecated+This prop has been renamed to [`trimBefore`](#trimbefore) in 4.0.319. It will continue to work but you cannot use it together with the new prop.+:::++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.++For exact behavior, see: [Order of operations](/docs/audio/order-of-operations).++```tsx twoslash+import {AbsoluteFill, staticFile} from 'remotion';+import {NewVideo} from '@remotion/new-video';++// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo src={staticFile('video.webm')} startFrom={60} endAt={120} />+ </AbsoluteFill>+ );+};+```++### ~~`endAt?`~~++:::note Deprecated+This prop has been renamed to [`trimAfter`](#trimafter) in 4.0.319. It will continue to work but you cannot use it together with the new prop.+:::++Removes a portion of the video at the end. See [`startFrom`](/docs/new-video#startfrom) for an explanation.++### `volume?`++Allows you to control the volume for the whole track or change it on a per-frame basis. Refer to the [using audio](/docs/audio/volume) guide to learn how to use it.++```tsx twoslash title="Example using static volume"+import {AbsoluteFill, staticFile} from 'remotion';+import {NewVideo} from '@remotion/new-video'++// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo volume={0.5} src={staticFile('video.webm')} />+ </AbsoluteFill>+ );+};+```++```tsx twoslash title="Example of a ramp up over 100 frames"+import {AbsoluteFill, interpolate, staticFile} from 'remotion';+import {NewVideo} from '@remotion/new-video';++// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo volume={(f) => interpolate(f, [0, 100], [0, 1], {extrapolateLeft: 'clamp'})} src={staticFile('video.webm')} />+ </AbsoluteFill>+ );+};+```++By default, volumes between 0 and 1 are supported, where in iOS Safari, the volume is always 1.+See [Volume Limitations](/docs/audio/volume#limitations) for more information.++### `loopVolumeCurveBehavior?`<AvailableFrom v="4.0.142" />++Controls the `frame` which is returned when using the [`volume`](#volume) callback function and wrapping `OffthreadVideo` in a [`<Loop>`](/docs/loop).++Can be either `"repeat"` (default, start from 0 on each iteration) or `"extend"` (keep increasing frames).++### `style?`++You can pass any style you can pass to a native HTML element. Keep in mind that during rendering, `<NewVideo>` renders a `canvas` 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>+ );+};+```++### `name?`<AvailableFrom v="4.0.71"/>++A name and that will be shown as the label of the sequence in the timeline of the Remotion Studio. This property is purely for helping you keep track of items in the timeline.++### `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%.++### `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, staticFile} from 'remotion';+import {NewVideo} from '@remotion/new-video';+++// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo 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';+import {NewVideo} from '@remotion/new-video';+// ---cut---+export const MyComposition = () => {+ return (+ <AbsoluteFill>+ <NewVideo muted src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" />+ </AbsoluteFill>+ );+};+```++### `acceptableTimeShiftInSeconds?`<AvailableFrom v="3.2.42" />++In the [Studio](/docs/terminology/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.++### `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%.++### `pauseWhenBuffering?`<AvailableFrom v="4.0.111"/>++If set to `true` and the video is loading, the Player will enter into the [native buffering state](/docs/player/buffer-state). The default is `false`, but will become `true` in Remotion 5.0.+++### `showInTimeline?`<AvailableFrom v="4.0.122"/>++If set to `false`, no layer will be shown in the timeline of the Remotion Studio. The default is `true`.++### `delayRenderTimeoutInMilliseconds?`<AvailableFrom v="4.0.150" />++Customize the [timeout](/docs/delay-render#modifying-the-timeout) of the [`delayRender()`](/docs/delay-render) call that this component makes.++### `delayRenderRetries?`<AvailableFrom v="4.0.178" />++Customize the [number of retries](/docs/delay-render#retrying) of the [`delayRender()`](/docs/delay-render) call that this component makes.++### `onAutoPlayError?`<AvailableFrom v="4.0.187" />++A callback function that gets called when the video fails to play due to autoplay restrictions.+If you don't pass a callback, the video will be muted and be retried once.+This prop is useful if you want to handle the error yourself, e.g. for pausing the Player.+Read more here about [autoplay restrictions](/docs/player/autoplay).++### `onVideoFrame?`<AvailableFrom v="4.0.190" />++A callback function that gets called when a frame is extracted from the video.+Useful for [video manipulation](/docs/video-manipulation).+The callback is called with a [`CanvasImageSource`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource) object.+During preview, this is a `HTMLVideoElement` object, during rendering, it is an `HTMLImageElement`.++### `crossOrigin?`<AvailableFrom v="4.0.190" />++Corresponds to the [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin) attribute of the `<video>` element.+One of `"anonymous"`, `"use-credentials"` or `undefined`.+Default: `"anonymous"` if `onVideoFrame` is specified, `undefined`, otherwise.++### `useWebAudioApi?`<AvailableFrom v="4.0.306" />++Enable the [Web Audio API](/docs/audio/volume#limitations) for the video tag.++### ~~`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).++### ~`allowAmplificationDuringRender?`<AvailableFrom v="3.3.17" />~++Deprecated since v4.0.279: This prop intended to opt into setting the volume to a value higher than one, even though it would only apply during render.++The option does not make sense anymore, because it is now possible to set the volume higher than `1`.+To prevent synthetic amplification, set a volume not higher than 1.+++## See also++- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/new-video/src/new-video.tsx)+- [`<Video />`](/docs/video)+- [`<OffthreadVideo>`](/docs/offthreadvideo)diff --git a/packages/docs/docs/new-video/table-of-contents.tsx b/packages/docs/docs/new-video/table-of-contents.tsxnew file mode 100644index 0000000000..f921da75fc--- /dev/null+++ b/packages/docs/docs/new-video/table-of-contents.tsx@@ -0,0 +1,16 @@+import React from "react";+import { Grid } from "../../components/TableOfContents/Grid";+import { TOCItem } from "../../components/TableOfContents/TOCItem";++export const TableOfContents: React.FC = () => {+ return (+ <div>+ <Grid>+ <TOCItem link="/docs/new-video">+ <strong>{"<NewVideo>"}</strong>+ <div>Tag for reliable and accurate video embedding</div>+ </TOCItem>+ </Grid>+ </div>+ );+};diff --git a/packages/docs/package.json b/packages/docs/package.jsonindex c5db87a94d..2af32481b8 100644--- a/packages/docs/package.json+++ b/packages/docs/package.json@@ -34,6 +34,7 @@"@remotion/svg-3d-engine": "workspace:*","@remotion/animated-emoji": "workspace:*","@remotion/animation-utils": "workspace:*",+ "@remotion/new-video": "workspace:*","@remotion/babel-loader": "workspace:*","@remotion/bundler": "workspace:*","@remotion/cli": "workspace:*",diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 6b7aeaedca..6621da0a80 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -174,6 +174,17 @@ const sidebars: SidebarsConfig = {'video','watchstaticfile',],+ },+ {+ type: 'category',+ label: '@remotion/new-video',+ link: {+ type: 'doc',+ id: 'new-video/index',+ },+ items: [+ 'new-video/index'+ ],},{type: 'category',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex bf1c5bf75d..361865a39c 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -3432,6 +3432,15 @@ export const articles = [noAi: false,slug: 'multiple-fps',},+ {+ id: 'new-video/index',+ title: '<NewVideo>',+ relativePath: 'docs/new-video/index.mdx',+ compId: 'articles-docs-new-video-index',+ crumb: 'API',+ noAi: false,+ slug: 'new-video/index',+ },{id: 'noise-visualization',title: 'Noise visualization',diff --git a/packages/docs/static/generated/articles-docs-new-video-index.png b/packages/docs/static/generated/articles-docs-new-video-index.pngnew file mode 100644index 0000000000..713068db36Binary files /dev/null and b/packages/docs/static/generated/articles-docs-new-video-index.png differdiff --git a/packages/example/package.json b/packages/example/package.jsonindex 9d65820beb..637c256c02 100644--- a/packages/example/package.json+++ b/packages/example/package.json@@ -35,7 +35,7 @@"@remotion/animated-emoji": "workspace:*","@remotion/animation-utils": "workspace:*","@remotion/babel-loader": "workspace:*",- "@remotion/video": "workspace:*",+ "@remotion/new-video": "workspace:*","@remotion/webcodecs": "workspace:*","@remotion/bundler": "workspace:*","@remotion/cli": "workspace:*",diff --git a/packages/example/src/longVideoNoFlicker/longVideo.tsx b/packages/example/src/longVideoNoFlicker/longVideo.tsxindex 1f5549925e..37118b21e3 100644--- a/packages/example/src/longVideoNoFlicker/longVideo.tsx+++ b/packages/example/src/longVideoNoFlicker/longVideo.tsx@@ -1,4 +1,4 @@-import {NewVideo} from '@remotion/video';+import {NewVideo} from '@remotion/new-video';import {AbsoluteFill, staticFile} from 'remotion';export const LongVideo: React.FC = () => {diff --git a/packages/new-video/README.md b/packages/new-video/README.mdindex 32646f7e9f..295670856d 100644--- a/packages/new-video/README.md+++ b/packages/new-video/README.md@@ -1,6 +1,6 @@# @remotion/new-video-Experimental tag for reliable and accurate rendering+Experimental tag for reliable and accurate video embedding## Usagediff --git a/packages/new-video/package.json b/packages/new-video/package.jsonindex fdd3a32829..08f054cc6a 100644--- a/packages/new-video/package.json+++ b/packages/new-video/package.json@@ -1,5 +1,5 @@{- "name": "@remotion/video",+ "name": "@remotion/new-video","version": "4.0.325","main": "dist/index.js","types": "dist/index.d.ts",@@ -46,5 +46,5 @@},"./package.json": "./package.json"},- "description": "Experimental tag for reliable and accurate rendering"+ "description": "Experimental tag for reliable and accurate video embedding"}diff --git a/packages/studio-shared/src/package-info.ts b/packages/studio-shared/src/package-info.tsindex 49ee68ac2d..bbac6a536b 100644--- a/packages/studio-shared/src/package-info.ts+++ b/packages/studio-shared/src/package-info.ts@@ -163,7 +163,7 @@ export const descriptions: {[key in Pkgs]: string | null} = {'promo-pages': null,'svg-3d-engine': '3D SVG extrusion effects','serverless-client': null,- 'new-video': 'Experimental tag for reliable and accurate rendering',+ 'new-video': 'Experimental tag for reliable and accurate video embedding',};export const installableMap: {[key in Pkgs]: boolean} = {'svg-3d-engine': false,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 9ef6d0876c..e9930edf81 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -647,6 +647,9 @@ importers:'@remotion/motion-blur':specifier: workspace:*version: link:../motion-blur+ '@remotion/new-video':+ specifier: workspace:*+ version: link:../new-video'@remotion/noise':specifier: workspace:*version: link:../noise@@ -1034,6 +1037,9 @@ importers:'@remotion/motion-blur':specifier: workspace:*version: link:../motion-blur+ '@remotion/new-video':+ specifier: workspace:*+ version: link:../new-video'@remotion/noise':specifier: workspace:*version: link:../noise@@ -1073,9 +1079,6 @@ importers:'@remotion/transitions':specifier: workspace:*version: link:../transitions- '@remotion/video':- specifier: workspace:*- version: link:../new-video'@remotion/webcodecs':specifier: workspace:*version: link:../webcodecs