Skip to content

🎥 Make videos programmatically with React

Docs: Add disclaimer about video seeking performance being degraded when using blob: URLs

Jonny Burger605380c5c3d0
diff --git a/packages/docs/docs/video-uploads.mdx b/packages/docs/docs/video-uploads.mdx
index 99ef5cff48..a63407956f 100644
--- a/packages/docs/docs/video-uploads.mdx
+++ b/packages/docs/docs/video-uploads.mdx
@@ -2,7 +2,7 @@
image: /generated/articles-docs-video-uploads.png
id: video-uploads
title: Handling user video uploads
-crumb: "Building video apps"
+crumb: 'Building video apps'
---
In an app where users can upload videos and edit them, we can create a better user experience by loading the video into a player even before the upload is finished. Good news: This can be done pretty easily!
@@ -13,16 +13,16 @@ We have a component which returns a [`<Video>`](/docs/video) tag that includes a
```tsx twoslash title="MyComposition.tsx"
const upload = async (file: File) => {
- return "https://example.com";
+ return 'https://example.com';
};
// ---cut---
-import { AbsoluteFill, Video } from "remotion";
+import {AbsoluteFill, Video} from 'remotion';
type VideoProps = {
videoURL: string;
};
-export const MyComponent: React.FC<VideoProps> = ({ videoURL }) => {
+export const MyComponent: React.FC<VideoProps> = ({videoURL}) => {
return (
<AbsoluteFill>
<Video src={videoURL} />
@@ -36,17 +36,17 @@ Using a `<input type="file">` element, we allow a user upload.
As soon as a file is fully uploaded to the cloud, the URL will be set and can be used by the component to display the video.
```tsx twoslash title="App.tsx"
-import { useCallback } from "react";
-const MyComposition: React.FC<{ videoUrl: string | null }> = (URL) => {
+import {useCallback} from 'react';
+const MyComposition: React.FC<{videoUrl: string | null}> = (URL) => {
return null;
};
const upload = async (file: File) => {
- return "https://exampleName.s3.examplesRegion.amazonaws.com";
+ return 'https://exampleName.s3.examplesRegion.amazonaws.com';
};
// ---cut---
-import { Player } from "@remotion/player";
-import { useState } from "react";
+import {Player} from '@remotion/player';
+import {useState} from 'react';
export const RemotionPlayer: React.FC = () => {
const [videoUrl, setVideoUrl] = useState<string | null>(null);
@@ -63,7 +63,7 @@ export const RemotionPlayer: React.FC = () => {
// E.g., cloudURL = https://exampleBucketName.s3.ExampleAwsRegion.amazonaws.com
setVideoUrl(cloudURL);
},
- []
+ [],
);
return (
@@ -75,7 +75,7 @@ export const RemotionPlayer: React.FC = () => {
compositionWidth={1920}
compositionHeight={1080}
fps={30}
- inputProps={{ videoUrl }}
+ inputProps={{videoUrl}}
/>
)}
@@ -92,30 +92,30 @@ The implementation of the `upload()` function is provider-specific and we do not
When we start the upload of the file, we can create a blob URL using `URL.createObjectURL()` which can be used to display the local file in a [`<Video>`](/docs/video) tag. When the file is done uploading and we get the remote URL, the component shall use remote URL as source.
```tsx twoslash title="App.tsx"
-const MyComposition: React.FC<{ videoUrl: string }> = ({ videoUrl }) => {
+const MyComposition: React.FC<{videoUrl: string}> = ({videoUrl}) => {
return null;
};
const upload = async (file: File) => {
- return "https://example.com";
+ return 'https://example.com';
};
// ---cut---
-import { Player } from "@remotion/player";
-import { useCallback, useState } from "react";
+import {Player} from '@remotion/player';
+import {useCallback, useState} from 'react';
type VideoState =
| {
- type: "empty";
+ type: 'empty';
}
| {
- type: "blob" | "cloud";
+ type: 'blob' | 'cloud';
url: string;
};
export const RemotionPlayer: React.FC = () => {
const [videoState, setVideoState] = useState<VideoState>({
- type: "empty",
+ type: 'empty',
});
const handleChange = useCallback(
@@ -126,24 +126,24 @@ export const RemotionPlayer: React.FC = () => {
const file = event.target.files[0];
const blobUrl = URL.createObjectURL(file);
- setVideoState({ type: "blob", url: blobUrl });
+ setVideoState({type: 'blob', url: blobUrl});
const cloudUrl = await upload(file);
- setVideoState({ type: "cloud", url: cloudUrl });
+ setVideoState({type: 'cloud', url: cloudUrl});
URL.revokeObjectURL(blobUrl);
},
- []
+ [],
);
return (
<div>
- {videoState.type !== "empty" ? (
+ {videoState.type !== 'empty' ? (
<Player
component={MyComposition}
durationInFrames={120}
compositionWidth={1920}
compositionHeight={1080}
fps={30}
- inputProps={{ videoUrl: videoState.url }}
+ inputProps={{videoUrl: videoState.url}}
/>
) : null}
<input type="file" onChange={handleChange} />
@@ -154,6 +154,11 @@ export const RemotionPlayer: React.FC = () => {
This will result in the user immediately seeing the video as they drag it into the input field. It is a good practice to call `URL.revokeObjectURL()` after the local video is not used anymore to free up the used memory.
+:::note
+As soon as possible, replace the `blob:` URL with the real URL.
+Since `blob:` URLs don't support the HTTP `Range` header, video seeking performance is degraded when using `blob:` URLs.
+:::
+
## See also
- [Uploading with presigned URLs](/docs/presigned-urls)