🎥 Make videos programmatically with React
document fallback
JonnyBurgerc2aacaba1daa
diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdxindex ceeec7059e..d057a5c16d 100644--- a/packages/docs/docs/media/audio.mdx+++ b/packages/docs/docs/media/audio.mdx@@ -193,6 +193,12 @@ Customize the [timeout](/docs/delay-render#modifying-the-timeout) of the [`delayCustomize the [number of retries](/docs/delay-render#retrying) of the [`delayRender()`](/docs/delay-render) call that this component makes.+### `disallowFallbackToHtml5Audio?`<AvailableFrom v="3.0.356" />++By default, if the video cannot be embedded using this tag, [a fallback to `<Audio>` from `remotion`](/docs/media/fallback) will be attempted.++Pass this prop to disable the fallback and fail the render instead.+## Setting the cache size`@remotion/media` keeps a cache of video and audio frames.diff --git a/packages/docs/docs/media/fallback.mdx b/packages/docs/docs/media/fallback.mdxindex df43607868..c0bf29943a 100644--- a/packages/docs/docs/media/fallback.mdx+++ b/packages/docs/docs/media/fallback.mdx@@ -24,3 +24,27 @@ Cannot decode /public/video-h265.mp4, falling back to <OffthreadVideo>```If you are rendering on an environment where the logs are not immediately visible (e.g. Lambda), observe whether a fallback has happened by visiting the logs (e.g. CloudWatch).++## Preventing a fallback from happening++To prevent [`<Video>`](/docs/media/video) from falling back to [`<OffthreadVideo>`](/docs/offthreadvideo), set the [`disallowFallbackToOffthreadVideo`](/docs/media/video#disallowfallbacktooffthreadvideo) prop:++```tsx twoslash title="No fallback to OffthreadVideo"+import {experimental_Video as Video} from '@remotion/media';++export const MyComp: React.FC = () => {+ return <Video src="https://remotion.media/video.mp4" disallowFallbackToOffthreadVideo />;+};+```++To prevent [`<Audio>`](/docs/media/audio) from falling back to [`<Audio>`](/docs/audio) from [`remotion`](/docs/remotion), set the [`disallowFallbackToHtml5Audio`](/docs/media/disallowfallbacktohtml5audio) prop:++```tsx twoslash title="No fallback to HTML5 audio tag"+import {experimental_Audio as Audio} from '@remotion/media';++export const MyComp: React.FC = () => {+ return <Audio src="https://remotion.media/audio.mp3" disallowFallbackToHtml5Audio />;+};+```++If a fallback is prevented, the render will be cancelled instead.diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdxindex a611a249b8..bfc4574b68 100644--- a/packages/docs/docs/media/video.mdx+++ b/packages/docs/docs/media/video.mdx@@ -225,6 +225,12 @@ A callback function that gets called when a frame is extracted from the video.Useful for [video manipulation](/docs/video-manipulation).The callback is called with a [`CanvasImageSource`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource) object, more specifically, either an `ImageBitmap` or a `VideoFrame`.+### `disallowFallbackToOffthreadVideo?`<AvailableFrom v="3.0.356" />++By default, if the video cannot be embedded using this tag, [a fallback to `<OffthreadVideo>`](/docs/media/fallback) will be attempted.++Pass this prop to disable the fallback and fail the render instead.+## Setting the cache size`@remotion/media` keeps a cache of video and audio frames.diff --git a/packages/media/src/audio/audio-for-rendering.tsx b/packages/media/src/audio/audio-for-rendering.tsxindex 5e24e00f06..37890fba28 100644--- a/packages/media/src/audio/audio-for-rendering.tsx+++ b/packages/media/src/audio/audio-for-rendering.tsx@@ -27,6 +27,7 @@ export const AudioForRendering: React.FC<AudioProps> = ({showInTimeline,style,name,+ disallowFallbackToHtml5Audio,}) => {const frame = useCurrentFrame();const absoluteFrame = Internals.useTimelinePosition();@@ -89,6 +90,14 @@ export const AudioForRendering: React.FC<AudioProps> = ({}).then((result) => {if (result === 'cannot-decode') {+ if (!disallowFallbackToHtml5Audio) {+ cancelRender(+ new Error(+ `Cannot decode ${src}, and 'disallowFallbackToHtml5Audio' was set. Failing the render.`,+ ),+ );+ }+Internals.Log.warn({logLevel, tag: '@remotion/media'},`Cannot decode ${src}, falling back to <Audio>`,@@ -98,6 +107,14 @@ export const AudioForRendering: React.FC<AudioProps> = ({}if (result === 'network-error') {+ if (!disallowFallbackToHtml5Audio) {+ cancelRender(+ new Error(+ `Cannot decode ${src}, and 'disallowFallbackToHtml5Audio' was set. Failing the render.`,+ ),+ );+ }+Internals.Log.warn({logLevel, tag: '@remotion/media'},`Network error fetching ${src}, falling back to <Audio>`,@@ -154,6 +171,7 @@ export const AudioForRendering: React.FC<AudioProps> = ({delayRender,delayRenderRetries,delayRenderTimeoutInMilliseconds,+ disallowFallbackToHtml5Audio,environment.isClientSideRendering,fps,frame,diff --git a/packages/media/src/audio/props.ts b/packages/media/src/audio/props.tsindex dc62bb4319..c97b8a69be 100644--- a/packages/media/src/audio/props.ts+++ b/packages/media/src/audio/props.ts@@ -36,4 +36,5 @@ export type AudioProps = {toneFrequency?: number;acceptableTimeShiftInSeconds?: number;};+ disallowFallbackToHtml5Audio?: boolean;};diff --git a/packages/media/src/video/props.ts b/packages/media/src/video/props.tsindex 9569ee8963..abbfb670ad 100644--- a/packages/media/src/video/props.ts+++ b/packages/media/src/video/props.ts@@ -35,5 +35,6 @@ export type VideoProps = {stack?: string;logLevel?: LogLevel;loop?: boolean;+ disallowFallbackToOffthreadVideo?: boolean;fallbackOffthreadVideoProps?: FallbackOffthreadVideoProps;};diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsxindex 0c1e576006..f0214e1944 100644--- a/packages/media/src/video/video-for-rendering.tsx+++ b/packages/media/src/video/video-for-rendering.tsx@@ -35,6 +35,7 @@ export const VideoForRendering: React.FC<VideoProps> = ({fallbackOffthreadVideoProps,name,showInTimeline,+ disallowFallbackToOffthreadVideo,}) => {if (!src) {throw new TypeError('No `src` was passed to <Video>.');@@ -101,6 +102,14 @@ export const VideoForRendering: React.FC<VideoProps> = ({}).then((result) => {if (result === 'cannot-decode') {+ if (!disallowFallbackToOffthreadVideo) {+ cancelRender(+ new Error(+ `Cannot decode ${src}, and 'disallowFallbackToOffthreadVideo' was set. Failing the render.`,+ ),+ );+ }+if (window.remotion_isMainTab) {Internals.Log.info({logLevel, tag: '@remotion/media'},@@ -113,6 +122,14 @@ export const VideoForRendering: React.FC<VideoProps> = ({}if (result === 'network-error') {+ if (!disallowFallbackToOffthreadVideo) {+ cancelRender(+ new Error(+ `Cannot decode ${src}, and 'disallowFallbackToOffthreadVideo' was set. Failing the render.`,+ ),+ );+ }+if (window.remotion_isMainTab) {Internals.Log.info({logLevel, tag: '@remotion/media'},@@ -215,6 +232,7 @@ export const VideoForRendering: React.FC<VideoProps> = ({unregisterRenderAsset,volumeProp,replaceWithOffthreadVideo,+ disallowFallbackToOffthreadVideo,]);const classNameValue = useMemo(() => {