Skip to content

🎥 Make videos programmatically with React

docs: migrate a few more API docs

Frenco6336b93298ba
diff --git a/packages/docs/docs/bundle.md b/packages/docs/docs/bundle.md
index f8e19e8223..a0189a09f0 100644
--- a/packages/docs/docs/bundle.md
+++ b/packages/docs/docs/bundle.md
@@ -29,7 +29,7 @@ A `string` containing an absolute path of the entry point of a Remotion project.
A callback function that notifies about the progress of the Webpack bundling. Example function:
-```ts
+```ts twoslash
const onProgressUpdate = (progress: number) => {
console.log(`Webpack bundling progress: ${progress * 100}%`)
}
@@ -45,7 +45,9 @@ _optional_
A function to override the webpack config reducer-style. Takes a function which gives you the current webpack config which you can transform and return a modified version of it. For example:
-```ts
+```ts twoslash
+import {WebpackOverrideFn} from "remotion";
+// ---cut---
const webpackOverride: WebpackOverrideFn = (webpackConfig) => {
return {
...webpackConfig
diff --git a/packages/docs/docs/dynamic-metadata.md b/packages/docs/docs/dynamic-metadata.md
index 16d5c528e9..3df6c20b50 100644
--- a/packages/docs/docs/dynamic-metadata.md
+++ b/packages/docs/docs/dynamic-metadata.md
@@ -122,8 +122,7 @@ getCompositions(bundled, {
```tsx twoslash
import {renderFrames as rf} from "@remotion/renderer"
-type RenderFramesOptions = Parameters<typeof rf>[0]
-const renderFrames = (options: Partial<RenderFramesOptions>): void => {}
+const renderFrames = (options: Partial<Parameters<typeof rf>[0]>) => {}
// ---cut---
renderFrames({
// ...
diff --git a/packages/docs/docs/get-audio-data.md b/packages/docs/docs/get-audio-data.md
index 07a0beb59f..dfa986c63d 100644
--- a/packages/docs/docs/get-audio-data.md
+++ b/packages/docs/docs/get-audio-data.md
@@ -26,7 +26,7 @@ A string pointing to an audio asset.
## Example
-```tsx
+```ts
import {getAudioData} from '@remotion/media-utils';
import music from './music.mp3';
diff --git a/packages/docs/docs/gif.md b/packages/docs/docs/gif.md
index 74351a25b2..87b2fdea0e 100644
--- a/packages/docs/docs/gif.md
+++ b/packages/docs/docs/gif.md
@@ -50,7 +50,9 @@ Allows to pass in custom CSS styles.
## Example
-```tsx
+```tsx twoslash
+import {useVideoConfig} from "remotion";
+// ---cut---
import {Gif} from '@remotion/gif';
export const MyComponent: React.FC = () => {
diff --git a/packages/docs/docs/render-frames.md b/packages/docs/docs/render-frames.md
index 67ee349f9f..a26a092cc8 100644
--- a/packages/docs/docs/render-frames.md
+++ b/packages/docs/docs/render-frames.md
@@ -49,7 +49,7 @@ A `string` specifying the ID of the composition. See: [Defining compositions](/d
A callback that fires after the setup process (validation, browser launch) has finished. Example value
-```ts
+```ts twoslash
const onStart = () => {
console.log('Starting rendering...');
}
@@ -59,7 +59,7 @@ const onStart = () => {
A callback function that gets called whenever a frame finished rendering. An argument is passed containing how many frames have been rendered (not the frame number of the rendered frame). Example value
-```ts
+```ts twoslash
const onFrameUpdate = (frame: number) => {
console.log(`${frame} frames rendered.`)
}
@@ -130,7 +130,10 @@ _optional - Available since v2.1.0_
Allows you to react to an exception thrown in your React code. The callback has an argument which is an object containing `error` and `frame` properties.
The `frame` property tells you at which frame the error was thrown. If the error was thrown at startup, `frame` is null.
-```tsx
+```tsx twoslash
+import {renderFrames as rf} from '@remotion/renderer'
+const renderFrames = (options: Partial<Parameters<typeof rf>[0]>) => {}
+// ---cut---
renderFrames({
onError: (info) => {
if (info.frame === null) {
diff --git a/packages/docs/docs/stitch-frames-to-video.md b/packages/docs/docs/stitch-frames-to-video.md
index 87e1e2c6c9..5f8798b13c 100644
--- a/packages/docs/docs/stitch-frames-to-video.md
+++ b/packages/docs/docs/stitch-frames-to-video.md
@@ -92,7 +92,7 @@ _optional_
Callback function which informs about the encoding progress. The `progress` value is a `number` between 0 and 1.
-```ts
+```ts twoslash
const onProgress = (progress: number) => {
console.log(`Encoding progress: ${progress * 100}%`)
}
@@ -104,7 +104,7 @@ _optional_
Notifies when a remote asset needs to be downloaded in order to extract the audio track.
-```ts
+```ts twoslash
const onDownload = (src: string) => {
console.log(`Downloading ${src}...`)
}
diff --git a/packages/docs/docs/three-canvas.md b/packages/docs/docs/three-canvas.md
index 7968985256..f3338367ab 100644
--- a/packages/docs/docs/three-canvas.md
+++ b/packages/docs/docs/three-canvas.md
@@ -15,41 +15,40 @@ A browser bug [would normally cause the layout to be broken](https://github.com/
A spinning, color changing, scaling cube. This example can also be found in the `examples` folder of the Remotion repo.
-```tsx
-import React from 'react';
-import {interpolate, useCurrentFrame} from 'remotion';
-import {ThreeCanvas} from '@remotion/three';
+```tsx twoslash
+import { interpolate, useCurrentFrame, useVideoConfig } from 'remotion';
+import { ThreeCanvas } from '@remotion/three';
const ThreeBasic: React.FC = () => {
- const frame = useCurrentFrame();
- const {width, height} = useVideoConfig();
-
- return (
- <ThreeCanvas
- orthographic={false}
- width={width}
- height={height}
- style={{backgroundColor: 'white'}}
- camera={{fov: 75, position: [0, 0, 470]}}
- >
- <ambientLight intensity={0.15} />
- <pointLight args={[undefined, 0.4]} position={[200, 200, 0]} />
- <mesh
- position={[0, 0, 0]}
- rotation={[frame * 0.06 * 0.5, frame * 0.07 * 0.5, frame * 0.08 * 0.5]}
- scale={interpolate(Math.sin(frame / 10), [-1, 1], [0.8, 1.2])}
- >
- <boxGeometry args={[100, 100, 100]} />
- <meshStandardMaterial
- color={[
- Math.sin(frame * 0.12) * 0.5 + 0.5,
- Math.cos(frame * 0.11) * 0.5 + 0.5,
- Math.sin(frame * 0.08) * 0.5 + 0.5,
- ]}
- />
- </mesh>
- </ThreeCanvas>
- );
+ const frame = useCurrentFrame();
+ const { width, height } = useVideoConfig();
+
+ return (
+ <ThreeCanvas
+ orthographic={false}
+ width={width}
+ height={height}
+ style={{ backgroundColor: 'white' }}
+ camera={{ fov: 75, position: [0, 0, 470] }}
+ >
+ <ambientLight intensity={0.15} />
+ <pointLight args={[undefined, 0.4]} position={[200, 200, 0]} />
+ <mesh
+ position={[0, 0, 0]}
+ rotation={[frame * 0.06 * 0.5, frame * 0.07 * 0.5, frame * 0.08 * 0.5]}
+ scale={interpolate(Math.sin(frame / 10), [-1, 1], [0.8, 1.2])}
+ >
+ <boxGeometry args={[100, 100, 100]} />
+ <meshStandardMaterial
+ color={[
+ Math.sin(frame * 0.12) * 0.5 + 0.5,
+ Math.cos(frame * 0.11) * 0.5 + 0.5,
+ Math.sin(frame * 0.08) * 0.5 + 0.5,
+ ]}
+ />
+ </mesh>
+ </ThreeCanvas>
+ );
};
export default ThreeBasic;
diff --git a/packages/docs/docs/use-audio-data.md b/packages/docs/docs/use-audio-data.md
index d47c247307..f055b93e3f 100644
--- a/packages/docs/docs/use-audio-data.md
+++ b/packages/docs/docs/use-audio-data.md
@@ -25,10 +25,11 @@ A string pointing to an audio asset.
## Example
-```tsx
+```tsx twoslash
+import {Audio} from 'remotion'
+// ---cut---
import {useAudioData} from '@remotion/media-utils';
-import music from './music.mp3'
-
+import music from './music.mp3';
export const MyComponent: React.FC = () => {
const audioData = useAudioData(music);
diff --git a/packages/docs/docs/use-video-texture.md b/packages/docs/docs/use-video-texture.md
index 3b136f6cb0..6c8e33f419 100644
--- a/packages/docs/docs/use-video-texture.md
+++ b/packages/docs/docs/use-video-texture.md
@@ -7,13 +7,14 @@ Allows you to use a video in React Three Fiber that is synchronized with Remotio
To use a video in a Three.JS context, you first have to render it and assign it a ref. If you only want to use it in a React Three Fiber Scene, you can make it invisible by adding a `{position: "absolute", opacity: 0}` style.
-```tsx
+```tsx twoslash
+// @errors: 2322
import {useRef} from 'react';
import {Video} from 'remotion';
import src from './vid.mp4';
const MyVideo = () => {
- const videoRef = useRef<HTMLVideoElement>();
+ const videoRef = useRef<HTMLVideoElement | null>(null);
return (
<Video
ref={videoRef}
@@ -26,7 +27,9 @@ const MyVideo = () => {
To convert the video to a video texture, place the `useVideoTexture()` hook in the same component.
-```tsx
+```tsx twoslash
+const videoRef: React.MutableRefObject<HTMLVideoElement | null> = React.useRef(null)
+// ---cut---
import {useVideoTexture} from '@remotion/three';
// ...
@@ -36,10 +39,14 @@ const texture = useVideoTexture(videoRef)
The return type of it is a `THREE.VideoTexture | null` which you can assign as a `map` to for example `meshBasicMaterial`. We recommend to only render the material when the texture is not `null` to prevent bugs.
-```tsx
- {videoTexture ? (
- <meshBasicMaterial map={videoTexture} />
- ) : null}
+```tsx twoslash
+import {useVideoTexture} from '@remotion/three';
+const videoRef: React.MutableRefObject<HTMLVideoElement | null> = React.useRef(null)
+const videoTexture = useVideoTexture(videoRef)
+// ---cut---
+{videoTexture ? (
+ <meshBasicMaterial map={videoTexture} />
+) : null}
```
## See also
diff --git a/packages/docs/docs/visualize-audio.md b/packages/docs/docs/visualize-audio.md
index a04dcbf469..784beb4791 100644
--- a/packages/docs/docs/visualize-audio.md
+++ b/packages/docs/docs/visualize-audio.md
@@ -33,7 +33,7 @@ Usually the values on left side of the array can become much larger than the val
In this example, we render a bar chart visualizing the audio spectrum of an audio file we imported using [`useAudioData()`](use-audio-data) and `visualizeAudio()`.
-```tsx
+```tsx twoslash
import {Audio, useCurrentFrame, useVideoConfig} from 'remotion';
import {useAudioData, visualizeAudio} from '@remotion/media-utils';
import music from './music.mp3';
diff --git a/packages/docs/package.json b/packages/docs/package.json
index d062292897..613963d764 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -17,6 +17,7 @@
"@docusaurus/preset-classic": "2.0.0-beta.0",
"@mdx-js/react": "^1.6.21",
"@remotion/babel-loader": "^2.1.12",
+ "@remotion/gif": "^2.1.12",
"@remotion/media-utils": "^2.1.12",
"@remotion/player": "^2.1.12",
"@remotion/renderer": "^2.1.12",