🎥 Make videos programmatically with React
Update video-uploads.mdx
Jonny Burger94940cd67822
diff --git a/packages/docs/docs/video-uploads.mdx b/packages/docs/docs/video-uploads.mdxindex a63407956f..4cecfe7824 100644--- a/packages/docs/docs/video-uploads.mdx+++ b/packages/docs/docs/video-uploads.mdx@@ -9,14 +9,14 @@ In an app where users can upload videos and edit them, we can create a better us## Allowing user uploads-We have a component which returns a [`<Video>`](/docs/video) tag that includes an URL as source.+We have a component which returns a [`<OffthreadVideo>`](/docs/offthreadvideo) tag that includes an URL as source.```tsx twoslash title="MyComposition.tsx"const upload = async (file: File) => {return 'https://example.com';};// ---cut----import {AbsoluteFill, Video} from 'remotion';+import {AbsoluteFill, OffthreadVideo} from 'remotion';type VideoProps = {videoURL: string;@@ -25,7 +25,7 @@ type VideoProps = {export const MyComponent: React.FC<VideoProps> = ({videoURL}) => {return (<AbsoluteFill>- <Video src={videoURL} />+ <OffthreadVideo src={videoURL} /></AbsoluteFill>);};@@ -51,33 +51,21 @@ import {useState} from 'react';export const RemotionPlayer: React.FC = () => {const [videoUrl, setVideoUrl] = useState<string | null>(null);- const handleChange = useCallback(- async (event: React.ChangeEvent<HTMLInputElement>) => {- if (event.target.files === null) {- return;- }-- const file = event.target.files[0];- //upload is an example function & returns a URL when a file is uploaded on the cloud.- const cloudURL = await upload(file);- // E.g., cloudURL = https://exampleBucketName.s3.ExampleAwsRegion.amazonaws.com- setVideoUrl(cloudURL);- },- [],- );+ const handleChange = useCallback(async (event: React.ChangeEvent<HTMLInputElement>) => {+ if (event.target.files === null) {+ return;+ }++ const file = event.target.files[0];+ //upload is an example function & returns a URL when a file is uploaded on the cloud.+ const cloudURL = await upload(file);+ // E.g., cloudURL = https://exampleBucketName.s3.ExampleAwsRegion.amazonaws.com+ setVideoUrl(cloudURL);+ }, []);return (<div>- {videoUrl === null ? null : (- <Player- component={MyComposition}- durationInFrames={120}- compositionWidth={1920}- compositionHeight={1080}- fps={30}- inputProps={{videoUrl}}- />- )}+ {videoUrl === null ? null : <Player component={MyComposition} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} fps={30} inputProps={{videoUrl}} />}<input type="file" onChange={handleChange} /></div>@@ -118,34 +106,22 @@ export const RemotionPlayer: React.FC = () => {type: 'empty',});- const handleChange = useCallback(- async (event: React.ChangeEvent<HTMLInputElement>) => {- if (event.target.files === null) {- return;- }-- const file = event.target.files[0];- const blobUrl = URL.createObjectURL(file);- setVideoState({type: 'blob', url: blobUrl});- const cloudUrl = await upload(file);- setVideoState({type: 'cloud', url: cloudUrl});- URL.revokeObjectURL(blobUrl);- },- [],- );+ const handleChange = useCallback(async (event: React.ChangeEvent<HTMLInputElement>) => {+ if (event.target.files === null) {+ return;+ }++ const file = event.target.files[0];+ const blobUrl = URL.createObjectURL(file);+ setVideoState({type: 'blob', url: blobUrl});+ const cloudUrl = await upload(file);+ setVideoState({type: 'cloud', url: cloudUrl});+ URL.revokeObjectURL(blobUrl);+ }, []);return (<div>- {videoState.type !== 'empty' ? (- <Player- component={MyComposition}- durationInFrames={120}- compositionWidth={1920}- compositionHeight={1080}- fps={30}- inputProps={{videoUrl: videoState.url}}- />- ) : null}+ {videoState.type !== 'empty' ? <Player component={MyComposition} durationInFrames={120} compositionWidth={1920} compositionHeight={1080} fps={30} inputProps={{videoUrl: videoState.url}} /> : null}<input type="file" onChange={handleChange} /></div>);