🎥 Make videos programmatically with React
for video and audio
Jonny Burger38076b3f8e43
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsxindex 5b2f3d3615..bfdd7fd8fe 100644--- a/packages/core/src/audio/Audio.tsx+++ b/packages/core/src/audio/Audio.tsx@@ -3,6 +3,7 @@ import React, {forwardRef, useCallback, useContext} from 'react';import {getAbsoluteSrc} from '../absolute-src.js';import {calculateLoopDuration} from '../calculate-loop.js';import {cancelRender} from '../cancel-render.js';+import {addSequenceStackTraces} from '../enable-sequence-stack-traces.js';import {getRemotionEnvironment} from '../get-remotion-environment.js';import {Loop} from '../loop/index.js';import {usePreload} from '../prefetch.js';@@ -18,16 +19,21 @@ import {SharedAudioContext} from './shared-audio-tags.js';const AudioRefForwardingFunction: React.ForwardRefRenderFunction<HTMLAudioElement,- RemotionAudioProps & RemotionMainAudioProps+ RemotionAudioProps &+ RemotionMainAudioProps & {+ /**+ * @deprecated For internal use only+ */+ stack?: string;+ }> = (props, ref) => {const audioContext = useContext(SharedAudioContext);- const {startFrom, endAt, name, ...otherProps} = props;+ const {startFrom, endAt, name, stack, ...otherProps} = props;const {loop, ...propsOtherThanLoop} = props;const {fps} = useVideoConfig();const environment = getRemotionEnvironment();const {durations, setDurations} = useContext(DurationsContext);-if (typeof props.src !== 'string') {throw new TypeError(`The \`<Audio>\` tag requires a string for \`src\`, but got ${JSON.stringify(@@ -127,6 +133,7 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<_remotionInternalNativeLoopPassed={props._remotionInternalNativeLoopPassed ?? false}+ _remotionInternalStack={stack ?? null}shouldPreMountAudioTags={audioContext !== null && audioContext.numberOfAudioTags > 0}@@ -144,3 +151,5 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<* @see [Documentation](https://www.remotion.dev/docs/audio)*/export const Audio = forwardRef(AudioRefForwardingFunction);++addSequenceStackTraces(Audio);diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsxindex 43d3c93a03..132327b1f0 100644--- a/packages/core/src/audio/AudioForDevelopment.tsx+++ b/packages/core/src/audio/AudioForDevelopment.tsx@@ -31,6 +31,7 @@ type AudioForDevelopmentProps = RemotionAudioProps & {shouldPreMountAudioTags: boolean;onDuration: (src: string, durationInSeconds: number) => void;_remotionInternalNativeLoopPassed: boolean;+ _remotionInternalStack: string | null;};const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<@@ -134,7 +135,7 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<playbackRate: playbackRate ?? 1,displayName: name ?? null,id: timelineId,- stack: null,+ stack: props._remotionInternalStack,});useMediaPlayback({diff --git a/packages/core/src/enable-sequence-stack-traces.ts b/packages/core/src/enable-sequence-stack-traces.tsindex a2dc8e2eaf..2564a402ad 100644--- a/packages/core/src/enable-sequence-stack-traces.ts+++ b/packages/core/src/enable-sequence-stack-traces.ts@@ -5,10 +5,6 @@ const originalCreateElement = React.createElement;const componentsToAddStacksTo: unknown[] = [];const enableSequenceStackTraces = () => {- if (!getRemotionEnvironment().isStudio) {- return;- }-const proxy = new Proxy(originalCreateElement, {apply(target, thisArg, argArray) {if (componentsToAddStacksTo.includes(argArray[0])) {@@ -29,6 +25,10 @@ const enableSequenceStackTraces = () => {};export const addSequenceStackTraces = (component: unknown) => {+ if (!getRemotionEnvironment().isStudio) {+ return;+ }+componentsToAddStacksTo.push(component);enableSequenceStackTraces();};diff --git a/packages/core/src/video/OffthreadVideo.tsx b/packages/core/src/video/OffthreadVideo.tsxindex 1edf5153ec..371159faa8 100644--- a/packages/core/src/video/OffthreadVideo.tsx+++ b/packages/core/src/video/OffthreadVideo.tsx@@ -11,12 +11,10 @@ import {VideoForDevelopment} from './VideoForDevelopment.js';* @description This method imports and displays a video, similar to <Video />. During rendering, it extracts the exact frame from the video and displays it in an <img> tag* @see [Documentation](https://www.remotion.dev/docs/offthreadvideo)*/-export const OffthreadVideo: React.FC<Omit<OffthreadVideoProps, 'loop'>> = (- props,-) => {+export const OffthreadVideo: React.FC<OffthreadVideoProps> = (props) => {// Should only destruct `startFrom` and `endAt` from props,// rest gets drilled down- const {startFrom, endAt, name, ...otherProps} = props;+ const {startFrom, endAt, name, stack, ...otherProps} = props;const environment = getRemotionEnvironment();const onDuration = useCallback(() => undefined, []);@@ -63,6 +61,7 @@ export const OffthreadVideo: React.FC<Omit<OffthreadVideoProps, 'loop'>> = (return (<VideoForDevelopment+ _remotionInternalStack={stack ?? null}_remotionInternalNativeLoopPassed={false}onDuration={onDuration}onlyWarnForMediaSeekingErrordiff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsxindex 8adb4f75cd..93c817d56a 100644--- a/packages/core/src/video/Video.tsx+++ b/packages/core/src/video/Video.tsx@@ -2,6 +2,7 @@import React, {forwardRef, useCallback, useContext} from 'react';import {getAbsoluteSrc} from '../absolute-src.js';import {calculateLoopDuration} from '../calculate-loop.js';+import {addSequenceStackTraces} from '../enable-sequence-stack-traces.js';import {getRemotionEnvironment} from '../get-remotion-environment.js';import {Loop} from '../loop/index.js';import {usePreload} from '../prefetch.js';@@ -16,12 +17,19 @@ import {VideoForRendering} from './VideoForRendering.js';const VideoForwardingFunction: React.ForwardRefRenderFunction<HTMLVideoElement,- RemotionVideoProps & RemotionMainVideoProps+ RemotionVideoProps &+ RemotionMainVideoProps & {+ /**+ * @deprecated For internal use only+ */+ stack?: string;+ }> = (props, ref) => {const {startFrom,endAt,name,+ stack,_remotionInternalNativeLoopPassed,...otherProps} = props;@@ -107,6 +115,7 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<{...otherProps}ref={ref}onDuration={onDuration}+ _remotionInternalStack={stack ?? null}_remotionInternalNativeLoopPassed={_remotionInternalNativeLoopPassed ?? false}@@ -126,3 +135,5 @@ const forward = forwardRef as <T, P = {}>(* @see [Documentation](https://www.remotion.dev/docs/video)*/export const Video = forward(VideoForwardingFunction);++addSequenceStackTraces(Video);diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsxindex 3a55d47cc3..efde0a7289 100644--- a/packages/core/src/video/VideoForDevelopment.tsx+++ b/packages/core/src/video/VideoForDevelopment.tsx@@ -31,6 +31,7 @@ type VideoForDevelopmentProps = RemotionVideoProps & {onlyWarnForMediaSeekingError: boolean;onDuration: (src: string, durationInSeconds: number) => void;_remotionInternalNativeLoopPassed: boolean;+ _remotionInternalStack: string | null;};const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<@@ -83,7 +84,7 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<playbackRate: props.playbackRate ?? 1,displayName: name ?? null,id: timelineId,- stack: null,+ stack: props._remotionInternalStack,});useSyncVolumeWithMediaTag({diff --git a/packages/core/src/video/props.ts b/packages/core/src/video/props.tsindex 8ea4f4ece8..a50b2741f3 100644--- a/packages/core/src/video/props.ts+++ b/packages/core/src/video/props.ts@@ -46,5 +46,9 @@ export type OffthreadVideoProps = {allowAmplificationDuringRender?: boolean;toneFrequency?: number;transparent?: boolean;+ /**+ * @deprecated For internal use only+ */+ stack?: string;} & RemotionMainVideoProps &DeprecatedOffthreadVideoProps;