🎥 Make videos programmatically with React
docs updates
Jonny Burgerca593af009b0
diff --git a/packages/docs/docs/data-fetching.md b/packages/docs/docs/data-fetching.mdindex e899de0a51..bf0598b759 100644--- a/packages/docs/docs/data-fetching.md+++ b/packages/docs/docs/data-fetching.md@@ -53,6 +53,12 @@ It is important to know that in the render process, data fetching works on a perYou need to clear all handles created by `delayRender` within 30 seconds after the page is opened. This limit is imposed by Puppeteer, but makes a lot of sense as going over this limit would make the rendering process massively slow.+## Using `delayRender()` to calculate video metadata++You can also customize duration, frame rate and dimensions based on asynchronous data fetching:++- **See: [Dynamic duration, FPS & dimensions](dynamic-metadata)**+## See also- [delayRender()](/docs/delay-render)diff --git a/packages/docs/docs/dynamic-metadata.md b/packages/docs/docs/dynamic-metadata.mdindex ede97faf20..51e402413b 100644--- a/packages/docs/docs/dynamic-metadata.md+++ b/packages/docs/docs/dynamic-metadata.md@@ -3,12 +3,12 @@ id: dynamic-metadatatitle: Dynamic duration, FPS & dimensions---+## Change metadata based on input props+_Available since v2.0._Using [Input props](parametrized-rendering) you can customize the content of your videos while rendering. But what about if you want to change the duration, frame rate or the dimensions of your video based on input props or asynchronous operations?-## Change metadata based on input props-Use the `getInputProps()` method to retrieve the props that you have passed as an input.For example if you have passed `--props='{"hello": "world"}'` as a command line flag, you can read the value in your Remotion project like this:@@ -16,3 +16,70 @@ For example if you have passed `--props='{"hello": "world"}'` as a command lineconst {hello} = getInputProps()console.log(hello) // "world"```++You can use this technique to dynamically change the frame rate, dimensions or duration of our video as you render. For example, if you pass `--props={"duration": 100}` during rendering, the video will be 100 frames long if you define your composition as followed:++```tsx++import {getInputProps, Composition} from 'remotion';++const inputProps = getInputProps()++export const Index = () => {+ return (+ <>+ <Composition+ id="MyComposition"+ component={MyComponent}+ width={1920}+ height={1080}+ fps={30}+ durationInFrames={inputProps?.duration ?? 20}+ >+ </>+ )+}+```++:::tip+In the example above, we specified fallback duration for use while you are previewing the video, but you can also pass `--props` during preview!+:::++## Change metadata based on asynchronous information++_Available since v1.5._++Sometimes you need to calculate metadata programmatically in a non-synchronous manner. For example, you have a source video and you want your video to be just as long as the source video. You can use the [`delayRender()`/`continueRender()`](/docs/data-fetching) pattern for this as well!++In this example, we fetch the duration of "Big Buck Bunny" and use it to make our video just that long:++```tsx+export const Index: React.FC = () => {+ const [handle] = useState(() => delayRender());+ const [duration, setDuration] = useState(1);++ useEffect(() => {+ const video = document.createElement('video');+ video.src =+ 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';++ video.onloadedmetadata = () => {+ setDuration(Math.round(video.duration * 30));+ continueRender(handle);+ };+ }, [handle]);++ return (+ <>+ <Composition+ id="dynamic-duration"+ component={VideoTesting}+ width={1080}+ height={1080}+ fps={30}+ durationInFrames={duration}+ />+ </>+ )+}+```