Skip to content

🎥 Make videos programmatically with React

`@remotion/media`: Fail hard instead of falling back in client-side rendering

Igor Samokhovets8345a9c0e986
diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdx
index 3ca5601568..ba684070b6 100644
--- a/packages/docs/docs/media/audio.mdx
+++ b/packages/docs/docs/media/audio.mdx
@@ -218,6 +218,10 @@ Does not currently work in preview or in [client-side rendering](/docs/client-si
When a [fallback to `<Html5Audio>` from `remotion`](/docs/media/fallback) happens, this prop allows you to pass props to the fallback `<Html5Audio>` component.
Only props that are not supported by `<Audio>` from `@remotion/media` need to be specified here - props that apply for both tags will automatically be forwarded and do not need to be specified here.
+:::note
+This prop has no effect when using [`@remotion/web-renderer`](/docs/web-renderer) for client-side rendering, as fallback is not possible. See [Fallback is not possible in client-side rendering](/docs/media/fallback#fallback-is-not-possible-in-client-side-rendering).
+:::
+
#### `onError?`
Maps to [`<Html5Audio />` -> `onError`](/docs/html5-audio#onerror)
@@ -240,10 +244,14 @@ Maps to [`<Html5Audio />` -> `crossOrigin`](/docs/html5-audio#crossorigin)
### `disallowFallbackToHtml5Audio?`<AvailableFrom v="3.0.356" />
-By default, if the video cannot be embedded using this tag, [a fallback to `<Html5Audio>` from `remotion`](/docs/media/fallback) will be attempted.
+By default, if the audio cannot be embedded using this tag, [a fallback to `<Html5Audio>` from `remotion`](/docs/media/fallback) will be attempted.
Pass this prop to disable the fallback and fail the render instead.
+:::note
+When using [`@remotion/web-renderer`](/docs/web-renderer) for client-side rendering, fallback is not possible and the render will always fail if the audio cannot be embedded. See [Fallback is not possible in client-side rendering](/docs/media/fallback#fallback-is-not-possible-in-client-side-rendering).
+:::
+
## See also
- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/media/src/audio/audio.tsx)
diff --git a/packages/docs/docs/media/fallback.mdx b/packages/docs/docs/media/fallback.mdx
index 42a353a2ce..0b202870c0 100644
--- a/packages/docs/docs/media/fallback.mdx
+++ b/packages/docs/docs/media/fallback.mdx
@@ -50,3 +50,11 @@ export const MyComp: React.FC = () => {
```
If a fallback is prevented, the render will be cancelled instead.
+
+## Fallback is not possible in client-side rendering
+
+When using [`@remotion/web-renderer`](/docs/web-renderer) for client-side rendering, fallback to [`<OffthreadVideo>`](/docs/offthreadvideo) or [`<Html5Audio>`](/docs/html5-audio) is **not possible**.
+
+This is because these fallback components require server-side capabilities that are not available in the browser.
+
+If a media file cannot be rendered using [`@remotion/media`](/docs/media) during client-side rendering, the render will fail with an error message describing the issue.
diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdx
index a8349fb2dd..5de805ebc0 100644
--- a/packages/docs/docs/media/video.mdx
+++ b/packages/docs/docs/media/video.mdx
@@ -264,6 +264,10 @@ This is useful for [embedding a video as a texture in Three.js](/docs/videos/as-
When a [fallback to `<OffthreadVideo>`](/docs/media/fallback) happens, this prop allows you to pass props to the fallback `<OffthreadVideo>` component.
Only props that are not supported by `<Video>` from `@remotion/media` need to be specified here - props that apply for both tags will automatically be forwarded and do not need to be specified here.
+:::note
+This prop has no effect when using [`@remotion/web-renderer`](/docs/web-renderer) for client-side rendering, as fallback is not possible. See [Fallback is not possible in client-side rendering](/docs/media/fallback#fallback-is-not-possible-in-client-side-rendering).
+:::
+
#### `acceptableTimeShiftInSeconds?`
Maps to [`<OffthreadVideo />` -> `acceptableTimeShiftInSeconds`](/docs/offthreadvideo#acceptabletimeshiftinseconds)
@@ -290,6 +294,10 @@ By default, if the video cannot be embedded using this tag, [a fallback to `<Off
Pass this prop to disable the fallback and fail the render instead.
+:::note
+When using [`@remotion/web-renderer`](/docs/web-renderer) for client-side rendering, fallback is not possible and the render will always fail if the video cannot be embedded. See [Fallback is not possible in client-side rendering](/docs/media/fallback#fallback-is-not-possible-in-client-side-rendering).
+:::
+
### `debugOverlay?`
Shows a debug overlay on the video. This is useful for debugging the video playback.
diff --git a/packages/media/src/audio/audio-for-rendering.tsx b/packages/media/src/audio/audio-for-rendering.tsx
index da6f59570c..e2c9c23055 100644
--- a/packages/media/src/audio/audio-for-rendering.tsx
+++ b/packages/media/src/audio/audio-for-rendering.tsx
@@ -130,6 +130,15 @@ export const AudioForRendering: React.FC<AudioProps> = ({
})
.then((result) => {
if (result.type === 'unknown-container-format') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render audio "${src}": Unknown container format. See supported formats: https://www.remotion.dev/docs/mediabunny/formats`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToHtml5Audio) {
cancelRender(
new Error(
@@ -150,6 +159,15 @@ export const AudioForRendering: React.FC<AudioProps> = ({
}
if (result.type === 'cannot-decode') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render audio "${src}": The audio could not be decoded by the browser.`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToHtml5Audio) {
cancelRender(
new Error(
@@ -176,6 +194,15 @@ export const AudioForRendering: React.FC<AudioProps> = ({
}
if (result.type === 'network-error') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render audio "${src}": Network error while fetching the audio (possibly CORS).`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToHtml5Audio) {
cancelRender(
new Error(
diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsx
index 5abef26ed9..661350e54a 100644
--- a/packages/media/src/video/video-for-rendering.tsx
+++ b/packages/media/src/video/video-for-rendering.tsx
@@ -181,6 +181,15 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
})
.then((result) => {
if (result.type === 'unknown-container-format') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render video "${src}": Unknown container format. See supported formats: https://www.remotion.dev/docs/mediabunny/formats`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToOffthreadVideo) {
cancelRender(
new Error(
@@ -201,6 +210,15 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
}
if (result.type === 'cannot-decode') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render video "${src}": The video could not be decoded by the browser.`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToOffthreadVideo) {
cancelRender(
new Error(
@@ -223,6 +241,15 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
}
if (result.type === 'cannot-decode-alpha') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render video "${src}": The alpha channel could not be decoded by the browser.`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToOffthreadVideo) {
cancelRender(
new Error(
@@ -245,6 +272,15 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
}
if (result.type === 'network-error') {
+ if (environment.isClientSideRendering) {
+ cancelRender(
+ new Error(
+ `Cannot render video "${src}": Network error while fetching the video (possibly CORS).`,
+ ),
+ );
+ return;
+ }
+
if (disallowFallbackToOffthreadVideo) {
cancelRender(
new Error(