🎥 Make videos programmatically with React
WIP: `@remotion/media`: onError prop
Jonny Burgerebe543ba17d2
diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdxindex ba684070b6..f2ec706db2 100644--- a/packages/docs/docs/media/audio.mdx+++ b/packages/docs/docs/media/audio.mdx@@ -113,9 +113,36 @@ export const MyVideo = () => {A name and that will be shown as the label of the sequence in the timeline of the Remotion Studio. This property is purely for helping you keep track of items in the timeline.-### `onError?`+### `onError?`<AvailableFrom v="4.0.404" />-**Currently not supported!**+Handle errors that occur during audio loading. The callback receives an object with an `error` property and should return either `'fallback'` or `'fail'`.++- Return `'fallback'` to fall back to [`<Html5Audio>`](/docs/html5-audio) (default behavior when this prop is not specified)+- Return `'fail'` to fail the render immediately++```tsx twoslash+import {AbsoluteFill, staticFile} from 'remotion';+import {Audio} from '@remotion/media';++export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Audio+ src={staticFile('audio.mp3')}+ onError={({error}) => {+ console.log('Audio error:', error.message);+ // Return 'fail' to fail the render, or 'fallback' to use Html5Audio+ return 'fallback';+ }}+ />+ </AbsoluteFill>+ );+};+```++:::note+This callback is invoked when an error occurs in the `@remotion/media` audio processing. If you return `'fallback'`, the component will fall back to [`<Html5Audio>`](/docs/html5-audio) which may have its own error handling via [`fallbackHtml5AudioProps.onError`](#onerror-1).+:::### `playbackRate?`<AvailableFrom v="4.0.354" />diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdxindex 5de805ebc0..0ee8e6f93c 100644--- a/packages/docs/docs/media/video.mdx+++ b/packages/docs/docs/media/video.mdx@@ -115,9 +115,36 @@ export const MyVideo = () => {A name and that will be shown as the label of the sequence in the timeline of the Remotion Studio. This property is purely for helping you keep track of items in the timeline.-### `onError?`+### `onError?`<AvailableFrom v="4.0.404" />-**Currently not supported!**+Handle errors that occur during video loading. The callback receives an object with an `error` property and should return either `'fallback'` or `'fail'`.++- Return `'fallback'` to fall back to [`<OffthreadVideo>`](/docs/offthreadvideo) (default behavior when this prop is not specified)+- Return `'fail'` to fail the render immediately++```tsx twoslash+import {AbsoluteFill, staticFile} from 'remotion';+import {Video} from '@remotion/media';++export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Video+ src={staticFile('video.webm')}+ onError={({error}) => {+ console.log('Video error:', error.message);+ // Return 'fail' to fail the render, or 'fallback' to use OffthreadVideo+ return 'fallback';+ }}+ />+ </AbsoluteFill>+ );+};+```++:::note+This callback is invoked when an error occurs in the `@remotion/media` video processing. If you return `'fallback'`, the component will fall back to [`<OffthreadVideo>`](/docs/offthreadvideo) which may have its own error handling via [`fallbackOffthreadVideoProps.onError`](#onerror-1).+:::### `playbackRate?`<AvailableFrom v="4.0.354" />diff --git a/packages/media/src/audio/audio-for-preview.tsx b/packages/media/src/audio/audio-for-preview.tsxindex 5551fdaced..17e1ee4f97 100644--- a/packages/media/src/audio/audio-for-preview.tsx+++ b/packages/media/src/audio/audio-for-preview.tsx@@ -18,7 +18,11 @@ import {getTimeInSeconds} from '../get-time-in-seconds';import {MediaPlayer} from '../media-player';import {useLoopDisplay} from '../show-in-timeline';import {useMediaInTimeline} from '../use-media-in-timeline';-import type {FallbackHtml5AudioProps} from './props';+import type {+ FallbackHtml5AudioProps,+ MediaErrorAction,+ MediaErrorEvent,+} from './props';const {useUnsafeVideoConfig,@@ -50,6 +54,9 @@ type NewAudioForPreviewProps = {readonly toneFrequency: number | undefined;readonly audioStreamIndex: number | undefined;readonly fallbackHtml5AudioProps: FallbackHtml5AudioProps | undefined;+ readonly onError:+ | ((event: MediaErrorEvent) => MediaErrorAction)+ | undefined;};const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({@@ -69,6 +76,7 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({toneFrequency,audioStreamIndex,fallbackHtml5AudioProps,+ onError,}) => {const videoConfig = useUnsafeVideoConfig();const frame = useCurrentFrame();@@ -196,63 +204,66 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({return;}- if (result.type === 'unknown-container-format') {- if (disallowFallbackToHtml5Audio) {- throw new Error(- `Unknown container format ${preloadedSrc}, and 'disallowFallbackToHtml5Audio' was set.`,+ const handleError = (error: Error, fallbackMessage: string) => {+ if (onError) {+ const action = onError({error});+ if (action === 'fail') {+ throw error;+ }++ // action === 'fallback'+ Internals.Log.warn(+ {logLevel, tag: '@remotion/media'},+ fallbackMessage,);+ setShouldFallbackToNativeAudio(true);+ return;+ }++ if (disallowFallbackToHtml5Audio) {+ throw error;}Internals.Log.warn({logLevel, tag: '@remotion/media'},- `Unknown container format for ${preloadedSrc} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <Html5Audio>`,+ fallbackMessage,);setShouldFallbackToNativeAudio(true);+ };++ if (result.type === 'unknown-container-format') {+ handleError(+ new Error(+ `Unknown container format ${preloadedSrc}.`,+ ),+ `Unknown container format for ${preloadedSrc} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <Html5Audio>`,+ );return;}if (result.type === 'network-error') {- if (disallowFallbackToHtml5Audio) {- throw new Error(- `Network error fetching ${preloadedSrc}, and 'disallowFallbackToHtml5Audio' was set.`,- );- }-- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},+ handleError(+ new Error(`Network error fetching ${preloadedSrc}.`),`Network error fetching ${preloadedSrc}, falling back to <Html5Audio>`,);- setShouldFallbackToNativeAudio(true);return;}if (result.type === 'cannot-decode') {- if (disallowFallbackToHtml5Audio) {- throw new Error(- `Cannot decode ${preloadedSrc}, and 'disallowFallbackToHtml5Audio' was set.`,- );- }-- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},+ handleError(+ new Error(`Cannot decode ${preloadedSrc}.`),`Cannot decode ${preloadedSrc}, falling back to <Html5Audio>`,);- setShouldFallbackToNativeAudio(true);return;}if (result.type === 'no-tracks') {- if (disallowFallbackToHtml5Audio) {- throw new Error(- `No video or audio tracks found for ${preloadedSrc}, and 'disallowFallbackToHtml5Audio' was set.`,- );- }-- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},+ handleError(+ new Error(+ `No video or audio tracks found for ${preloadedSrc}.`,+ ),`No video or audio tracks found for ${preloadedSrc}, falling back to <Html5Audio>`,);- setShouldFallbackToNativeAudio(true);return;}@@ -267,6 +278,13 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({}}).catch((error) => {+ if (onError) {+ const action = onError({error});+ if (action === 'fail') {+ throw error;+ }+ }+Internals.Log.error({logLevel, tag: '@remotion/media'},'[AudioForPreview] Failed to initialize MediaPlayer',@@ -275,6 +293,13 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({setShouldFallbackToNativeAudio(true);});} catch (error) {+ if (onError) {+ const action = onError({error: error as Error});+ if (action === 'fail') {+ throw error;+ }+ }+Internals.Log.error({logLevel, tag: '@remotion/media'},'[AudioForPreview] MediaPlayer initialization failed',@@ -306,6 +331,7 @@ const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({audioStreamIndex,disallowFallbackToHtml5Audio,buffer,+ onError,]);useLayoutEffect(() => {@@ -473,6 +499,7 @@ type InnerAudioProps = {readonly toneFrequency?: number;readonly audioStreamIndex?: number;readonly fallbackHtml5AudioProps?: FallbackHtml5AudioProps;+ readonly onError?: (event: MediaErrorEvent) => MediaErrorAction;};export const AudioForPreview: React.FC<InnerAudioProps> = ({@@ -492,6 +519,7 @@ export const AudioForPreview: React.FC<InnerAudioProps> = ({toneFrequency,audioStreamIndex,fallbackHtml5AudioProps,+ onError,}) => {const preloadedSrc = usePreload(src);@@ -545,6 +573,7 @@ export const AudioForPreview: React.FC<InnerAudioProps> = ({stack={stack}disallowFallbackToHtml5Audio={disallowFallbackToHtml5Audio ?? false}toneFrequency={toneFrequency}+ onError={onError}fallbackHtml5AudioProps={fallbackHtml5AudioProps}/>);diff --git a/packages/media/src/audio/audio-for-rendering.tsx b/packages/media/src/audio/audio-for-rendering.tsxindex def2498edc..9cacab4637 100644--- a/packages/media/src/audio/audio-for-rendering.tsx+++ b/packages/media/src/audio/audio-for-rendering.tsx@@ -35,6 +35,7 @@ export const AudioForRendering: React.FC<AudioProps> = ({toneFrequency,trimAfter,trimBefore,+ onError,}) => {const defaultLogLevel = Internals.useLogLevel();const logLevel = overriddenLogLevel ?? defaultLogLevel;@@ -129,61 +130,63 @@ export const AudioForRendering: React.FC<AudioProps> = ({maxCacheSize,}).then((result) => {- if (result.type === 'unknown-container-format') {+ const handleError = (+ error: Error,+ clientSideError: Error,+ fallbackMessage: string,+ ) => {if (environment.isClientSideRendering) {- cancelRender(- new Error(- `Cannot render audio "${src}": Unknown container format. See supported formats: https://www.remotion.dev/docs/mediabunny/formats`,- ),+ cancelRender(clientSideError);+ return;+ }++ if (onError) {+ const action = onError({error});+ if (action === 'fail') {+ cancelRender(error);+ return;+ }++ // action === 'fallback'+ Internals.Log.warn(+ {logLevel, tag: '@remotion/media'},+ fallbackMessage,);+ setReplaceWithHtml5Audio(true);return;}if (disallowFallbackToHtml5Audio) {- cancelRender(- new Error(- `Unknown container format ${src}, and 'disallowFallbackToHtml5Audio' was set. Failing the render.`,- ),- );+ cancelRender(error);+ return;}Internals.Log.warn(- {- logLevel,- tag: '@remotion/media',- },- `Unknown container format for ${src} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <Html5Audio>`,+ {logLevel, tag: '@remotion/media'},+ fallbackMessage,);setReplaceWithHtml5Audio(true);+ };++ if (result.type === 'unknown-container-format') {+ handleError(+ new Error(`Unknown container format ${src}.`),+ new Error(+ `Cannot render audio "${src}": Unknown container format. See supported formats: https://www.remotion.dev/docs/mediabunny/formats`,+ ),+ `Unknown container format for ${src} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <Html5Audio>`,+ );return;}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(- `Cannot decode ${src}, and 'disallowFallbackToHtml5Audio' was set. Failing the render.`,- ),- );- }-- Internals.Log.warn(- {- logLevel,- tag: '@remotion/media',- },+ handleError(+ new Error(`Cannot decode ${src}.`),+ new Error(+ `Cannot render audio "${src}": The audio could not be decoded by the browser.`,+ ),`Cannot decode ${src}, falling back to <Html5Audio>`,);- setReplaceWithHtml5Audio(true);return;}@@ -194,31 +197,13 @@ 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(- `Cannot decode ${src}, and 'disallowFallbackToHtml5Audio' was set. Failing the render.`,- ),- );- }-- Internals.Log.warn(- {- logLevel,- tag: '@remotion/media',- },+ handleError(+ new Error(`Network error fetching ${src}.`),+ new Error(+ `Cannot render audio "${src}": Network error while fetching the audio (possibly CORS).`,+ ),`Network error fetching ${src}, falling back to <Html5Audio>`,);- setReplaceWithHtml5Audio(true);return;}@@ -293,6 +278,7 @@ export const AudioForRendering: React.FC<AudioProps> = ({replaceWithHtml5Audio,maxCacheSize,audioEnabled,+ onError,]);if (replaceWithHtml5Audio) {diff --git a/packages/media/src/audio/props.ts b/packages/media/src/audio/props.tsindex 7057485d91..b6bf5631af 100644--- a/packages/media/src/audio/props.ts+++ b/packages/media/src/audio/props.ts@@ -1,5 +1,11 @@import type {LogLevel, LoopVolumeCurveBehavior, VolumeProp} from 'remotion';+export type MediaErrorAction = 'fallback' | 'fail';++export type MediaErrorEvent = {+ error: Error;+};+export type FallbackHtml5AudioProps = {crossOrigin?: '' | 'anonymous' | 'use-credentials' | undefined;onError?: (err: Error) => void;@@ -32,4 +38,5 @@ export type AudioProps = {toneFrequency?: number;delayRenderRetries?: number;delayRenderTimeoutInMilliseconds?: number;+ onError?: (event: MediaErrorEvent) => MediaErrorAction;};diff --git a/packages/media/src/index.ts b/packages/media/src/index.tsindex 6d68274091..d1d9767171 100644--- a/packages/media/src/index.ts+++ b/packages/media/src/index.ts@@ -11,6 +11,11 @@ export const experimental_Audio = Audio;export const experimental_Video = Video;export {AudioForPreview} from './audio/audio-for-preview';-export {AudioProps, FallbackHtml5AudioProps} from './audio/props';-export {VideoProps} from './video/props';+export {+ AudioProps,+ FallbackHtml5AudioProps,+ MediaErrorAction,+ MediaErrorEvent,+} from './audio/props';+export {FallbackOffthreadVideoProps, VideoProps} from './video/props';export {Audio, Video};diff --git a/packages/media/src/video/props.ts b/packages/media/src/video/props.tsindex 938d692337..97b0dd15f7 100644--- a/packages/media/src/video/props.ts+++ b/packages/media/src/video/props.ts@@ -5,6 +5,12 @@ import type {VolumeProp,} from 'remotion';+export type MediaErrorAction = 'fallback' | 'fail';++export type MediaErrorEvent = {+ error: Error;+};+export type FallbackOffthreadVideoProps = {acceptableTimeShiftInSeconds?: number;transparent?: boolean;@@ -48,6 +54,7 @@ type OptionalVideoProps = {showInTimeline: boolean;debugOverlay: boolean;headless: boolean;+ onError: ((event: MediaErrorEvent) => MediaErrorAction) | undefined;};export type InnerVideoProps = MandatoryVideoProps &diff --git a/packages/media/src/video/video-for-preview.tsx b/packages/media/src/video/video-for-preview.tsxindex 08d13776d0..d969d68185 100644--- a/packages/media/src/video/video-for-preview.tsx+++ b/packages/media/src/video/video-for-preview.tsx@@ -18,7 +18,11 @@ import {getTimeInSeconds} from '../get-time-in-seconds';import {MediaPlayer} from '../media-player';import {useLoopDisplay} from '../show-in-timeline';import {useMediaInTimeline} from '../use-media-in-timeline';-import type {FallbackOffthreadVideoProps} from './props';+import type {+ FallbackOffthreadVideoProps,+ MediaErrorAction,+ MediaErrorEvent,+} from './props';const {useUnsafeVideoConfig,@@ -55,6 +59,9 @@ type VideoForPreviewProps = {readonly audioStreamIndex: number;readonly debugOverlay: boolean;readonly headless: boolean;+ readonly onError:+ | ((event: MediaErrorEvent) => MediaErrorAction)+ | undefined;};const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({@@ -78,6 +85,7 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({audioStreamIndex,debugOverlay,headless,+ onError,}) => {const src = usePreload(unpreloadedSrc);@@ -204,63 +212,64 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({return;}- if (result.type === 'unknown-container-format') {- if (disallowFallbackToOffthreadVideo) {- throw new Error(- `Unknown container format ${preloadedSrc}, and 'disallowFallbackToOffthreadVideo' was set.`,+ const handleError = (error: Error, fallbackMessage: string) => {+ if (onError) {+ const action = onError({error});+ if (action === 'fail') {+ throw error;+ }++ // action === 'fallback'+ Internals.Log.warn(+ {logLevel, tag: '@remotion/media'},+ fallbackMessage,);+ setShouldFallbackToNativeVideo(true);+ return;+ }++ if (disallowFallbackToOffthreadVideo) {+ throw error;}Internals.Log.warn({logLevel, tag: '@remotion/media'},- `Unknown container format for ${preloadedSrc} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <OffthreadVideo>`,+ fallbackMessage,);setShouldFallbackToNativeVideo(true);+ };++ if (result.type === 'unknown-container-format') {+ handleError(+ new Error(`Unknown container format ${preloadedSrc}.`),+ `Unknown container format for ${preloadedSrc} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <OffthreadVideo>`,+ );return;}if (result.type === 'network-error') {- if (disallowFallbackToOffthreadVideo) {- throw new Error(- `Network error fetching ${preloadedSrc}, and 'disallowFallbackToOffthreadVideo' was set.`,- );- }-- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},+ handleError(+ new Error(`Network error fetching ${preloadedSrc}.`),`Network error fetching ${preloadedSrc}, falling back to <OffthreadVideo>`,);- setShouldFallbackToNativeVideo(true);return;}if (result.type === 'cannot-decode') {- if (disallowFallbackToOffthreadVideo) {- throw new Error(- `Cannot decode ${preloadedSrc}, and 'disallowFallbackToOffthreadVideo' was set.`,- );- }-- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},+ handleError(+ new Error(`Cannot decode ${preloadedSrc}.`),`Cannot decode ${preloadedSrc}, falling back to <OffthreadVideo>`,);- setShouldFallbackToNativeVideo(true);return;}if (result.type === 'no-tracks') {- if (disallowFallbackToOffthreadVideo) {- throw new Error(- `No video or audio tracks found for ${preloadedSrc}, and 'disallowFallbackToOffthreadVideo' was set.`,- );- }-- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},+ handleError(+ new Error(+ `No video or audio tracks found for ${preloadedSrc}.`,+ ),`No video or audio tracks found for ${preloadedSrc}, falling back to <OffthreadVideo>`,);- setShouldFallbackToNativeVideo(true);return;}@@ -270,6 +279,13 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({}}).catch((error) => {+ if (onError) {+ const action = onError({error});+ if (action === 'fail') {+ throw error;+ }+ }+Internals.Log.error({logLevel, tag: '@remotion/media'},'[VideoForPreview] Failed to initialize MediaPlayer',@@ -278,6 +294,13 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({setShouldFallbackToNativeVideo(true);});} catch (error) {+ if (onError) {+ const action = onError({error: error as Error});+ if (action === 'fail') {+ throw error;+ }+ }+Internals.Log.error({logLevel, tag: '@remotion/media'},'[VideoForPreview] MediaPlayer initialization failed',@@ -309,6 +332,7 @@ const VideoForPreviewAssertedShowing: React.FC<VideoForPreviewProps> = ({preloadedSrc,sharedAudioContext,videoConfig.fps,+ onError,]);const classNameValue = useMemo(() => {diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsxindex 661350e54a..cee38885e3 100644--- a/packages/media/src/video/video-for-rendering.tsx+++ b/packages/media/src/video/video-for-rendering.tsx@@ -25,7 +25,11 @@ import {applyVolume} from '../convert-audiodata/apply-volume';import {TARGET_SAMPLE_RATE} from '../convert-audiodata/resample-audiodata';import {frameForVolumeProp} from '../looped-frame';import {extractFrameViaBroadcastChannel} from '../video-extraction/extract-frame-via-broadcast-channel';-import type {FallbackOffthreadVideoProps} from './props';+import type {+ FallbackOffthreadVideoProps,+ MediaErrorAction,+ MediaErrorEvent,+} from './props';type InnerVideoProps = {readonly className: string | undefined;@@ -49,6 +53,9 @@ type InnerVideoProps = {readonly trimBeforeValue: number | undefined;readonly trimAfterValue: number | undefined;readonly headless: boolean;+ readonly onError:+ | ((event: MediaErrorEvent) => MediaErrorAction)+ | undefined;};type FallbackToOffthreadVideo = {@@ -77,6 +84,7 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({trimAfterValue,trimBeforeValue,headless,+ onError,}) => {if (!src) {throw new TypeError('No `src` was passed to <Video>.');@@ -180,123 +188,96 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({maxCacheSize,}).then((result) => {- if (result.type === 'unknown-container-format') {+ const handleError = (+ error: Error,+ clientSideError: Error,+ fallbackMessage: string,+ durationInSeconds: number | null,+ ) => {if (environment.isClientSideRendering) {- cancelRender(- new Error(- `Cannot render video "${src}": Unknown container format. See supported formats: https://www.remotion.dev/docs/mediabunny/formats`,- ),- );+ cancelRender(clientSideError);return;}- if (disallowFallbackToOffthreadVideo) {- cancelRender(- new Error(- `Unknown container format ${src}, and 'disallowFallbackToOffthreadVideo' was set. Failing the render.`,- ),- );- }-- if (window.remotion_isMainTab) {- Internals.Log.info(- {logLevel, tag: '@remotion/media'},- `Unknown container format for ${src} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <OffthreadVideo>`,- );- }-- setReplaceWithOffthreadVideo({durationInSeconds: null});- return;- }-- if (result.type === 'cannot-decode') {- if (environment.isClientSideRendering) {- cancelRender(- new Error(- `Cannot render video "${src}": The video could not be decoded by the browser.`,- ),- );+ if (onError) {+ const action = onError({error});+ if (action === 'fail') {+ cancelRender(error);+ return;+ }++ // action === 'fallback'+ if (window.remotion_isMainTab) {+ Internals.Log.warn(+ {logLevel, tag: '@remotion/media'},+ fallbackMessage,+ );+ }++ setReplaceWithOffthreadVideo({durationInSeconds});return;}if (disallowFallbackToOffthreadVideo) {- cancelRender(- new Error(- `Cannot decode ${src}, and 'disallowFallbackToOffthreadVideo' was set. Failing the render.`,- ),- );+ cancelRender(error);+ return;}if (window.remotion_isMainTab) {Internals.Log.warn({logLevel, tag: '@remotion/media'},- `Cannot decode ${src}, falling back to <OffthreadVideo>`,+ fallbackMessage,);}- setReplaceWithOffthreadVideo({- durationInSeconds: result.durationInSeconds,- });+ setReplaceWithOffthreadVideo({durationInSeconds});+ };++ if (result.type === 'unknown-container-format') {+ handleError(+ new Error(`Unknown container format ${src}.`),+ new Error(+ `Cannot render video "${src}": Unknown container format. See supported formats: https://www.remotion.dev/docs/mediabunny/formats`,+ ),+ `Unknown container format for ${src} (Supported formats: https://www.remotion.dev/docs/mediabunny/formats), falling back to <OffthreadVideo>`,+ null,+ );return;}- 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(- `Cannot decode alpha component for ${src}, and 'disallowFallbackToOffthreadVideo' was set. Failing the render.`,- ),- );- }-- if (window.remotion_isMainTab) {- Internals.Log.info(- {logLevel, tag: '@remotion/media'},- `Cannot decode alpha component for ${src}, falling back to <OffthreadVideo>`,- );- }+ if (result.type === 'cannot-decode') {+ handleError(+ new Error(`Cannot decode ${src}.`),+ new Error(+ `Cannot render video "${src}": The video could not be decoded by the browser.`,+ ),+ `Cannot decode ${src}, falling back to <OffthreadVideo>`,+ result.durationInSeconds,+ );+ return;+ }- setReplaceWithOffthreadVideo({- durationInSeconds: result.durationInSeconds,- });+ if (result.type === 'cannot-decode-alpha') {+ handleError(+ new Error(`Cannot decode alpha component for ${src}.`),+ new Error(+ `Cannot render video "${src}": The alpha channel could not be decoded by the browser.`,+ ),+ `Cannot decode alpha component for ${src}, falling back to <OffthreadVideo>`,+ result.durationInSeconds,+ );return;}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(- `Cannot decode ${src}, and 'disallowFallbackToOffthreadVideo' was set. Failing the render.`,- ),- );- }-- if (window.remotion_isMainTab) {- Internals.Log.warn(- {logLevel, tag: '@remotion/media'},- `Network error fetching ${src} (no CORS?), falling back to <OffthreadVideo>`,- );- }-- setReplaceWithOffthreadVideo({durationInSeconds: null});+ handleError(+ new Error(`Network error fetching ${src}.`),+ new Error(+ `Cannot render video "${src}": Network error while fetching the video (possibly CORS).`,+ ),+ `Network error fetching ${src} (no CORS?), falling back to <OffthreadVideo>`,+ null,+ );return;}@@ -411,6 +392,7 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({maxCacheSize,cancelRender,headless,+ onError,]);const classNameValue = useMemo(() => {diff --git a/packages/media/src/video/video.tsx b/packages/media/src/video/video.tsxindex 78c1c49f81..b05bb7850a 100644--- a/packages/media/src/video/video.tsx+++ b/packages/media/src/video/video.tsx@@ -31,6 +31,7 @@ const InnerVideo: React.FC<InnerVideoProps> = ({showInTimeline,debugOverlay,headless,+ onError,}) => {const environment = useRemotionEnvironment();@@ -86,6 +87,7 @@ const InnerVideo: React.FC<InnerVideoProps> = ({trimAfterValue={trimAfterValue}trimBeforeValue={trimBeforeValue}headless={headless}+ onError={onError}/>);}@@ -112,6 +114,7 @@ const InnerVideo: React.FC<InnerVideoProps> = ({fallbackOffthreadVideoProps={fallbackOffthreadVideoProps}debugOverlay={debugOverlay ?? false}headless={headless ?? false}+ onError={onError}/>);};@@ -140,6 +143,7 @@ export const Video: React.FC<VideoProps> = ({toneFrequency,debugOverlay,headless,+ onError,}) => {const fallbackLogLevel = Internals.useLogLevel();return (@@ -171,6 +175,7 @@ export const Video: React.FC<VideoProps> = ({stack={stack}debugOverlay={debugOverlay ?? false}headless={headless ?? false}+ onError={onError}/>);};