Skip to content

🎥 Make videos programmatically with React

`remotion`: Allow Video/Audio/OffthreadVideo to have a `name`

Jonny Burger2fddc30f31eb
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/Audio.tsx
index b87ea16908..537f63ae66 100644
--- a/packages/core/src/audio/Audio.tsx
+++ b/packages/core/src/audio/Audio.tsx
@@ -20,7 +20,7 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
RemotionAudioProps & RemotionMainAudioProps
> = (props, ref) => {
const audioContext = useContext(SharedAudioContext);
- const {startFrom, endAt, ...otherProps} = props;
+ const {startFrom, endAt, name, ...otherProps} = props;
const {loop, ...propsOtherThanLoop} = props;
const {fps} = useVideoConfig();
const environment = getRemotionEnvironment();
@@ -90,6 +90,7 @@ const AudioRefForwardingFunction: React.ForwardRefRenderFunction<
from={0 - startFromFrameNo}
showInTimeline={false}
durationInFrames={endAtFrameNo}
+ name={name}
>
<Audio
_remotionInternalNeedsDurationCalculation={Boolean(loop)}
diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsx
index 4883fcdeb0..e1286670df 100644
--- a/packages/core/src/audio/AudioForDevelopment.tsx
+++ b/packages/core/src/audio/AudioForDevelopment.tsx
@@ -59,6 +59,7 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
acceptableTimeShiftInSeconds,
_remotionInternalNeedsDurationCalculation,
allowAmplificationDuringRender,
+ name,
...nativeProps
} = props;
@@ -116,6 +117,7 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
src,
mediaType: 'audio',
playbackRate: playbackRate ?? 1,
+ displayName: name ?? null,
});
useMediaPlayback({
diff --git a/packages/core/src/audio/AudioForRendering.tsx b/packages/core/src/audio/AudioForRendering.tsx
index bb3afd0b84..482f47a515 100644
--- a/packages/core/src/audio/AudioForRendering.tsx
+++ b/packages/core/src/audio/AudioForRendering.tsx
@@ -59,6 +59,7 @@ const AudioForRenderingRefForwardingFunction: React.ForwardRefRenderFunction<
toneFrequency,
_remotionInternalNeedsDurationCalculation,
acceptableTimeShiftInSeconds,
+ name,
...nativeProps
} = props;
diff --git a/packages/core/src/audio/props.ts b/packages/core/src/audio/props.ts
index a613b88c52..77dbb18945 100644
--- a/packages/core/src/audio/props.ts
+++ b/packages/core/src/audio/props.ts
@@ -5,7 +5,6 @@ export type RemotionMainAudioProps = {
endAt?: number;
};
-// TODO: This breaks occasionally if the types of Audio break
export type RemotionAudioProps = Omit<
React.DetailedHTMLProps<
React.AudioHTMLAttributes<HTMLAudioElement>,
@@ -13,6 +12,7 @@ export type RemotionAudioProps = Omit<
>,
'autoPlay' | 'controls' | 'onEnded' | 'nonce' | 'onResize' | 'onResizeCapture'
> & {
+ name?: string;
volume?: VolumeProp;
playbackRate?: number;
acceptableTimeShiftInSeconds?: number;
diff --git a/packages/core/src/test/use-media-in-timeline.test.tsx b/packages/core/src/test/use-media-in-timeline.test.tsx
index 44382ccbf9..81580771e3 100644
--- a/packages/core/src/test/use-media-in-timeline.test.tsx
+++ b/packages/core/src/test/use-media-in-timeline.test.tsx
@@ -71,6 +71,7 @@ test('useMediaInTimeline registers and unregisters new sequence', () => {
mediaType: 'audio',
mediaRef: audioRef,
playbackRate: 1,
+ displayName: null,
}),
{
wrapper,
diff --git a/packages/core/src/use-media-in-timeline.ts b/packages/core/src/use-media-in-timeline.ts
index fb2463d7a4..d203a30372 100644
--- a/packages/core/src/use-media-in-timeline.ts
+++ b/packages/core/src/use-media-in-timeline.ts
@@ -30,6 +30,7 @@ export const useMediaInTimeline = ({
src,
mediaType,
playbackRate,
+ displayName,
}: {
volume: VolumeProp | undefined;
mediaVolume: number;
@@ -37,6 +38,7 @@ export const useMediaInTimeline = ({
src: string | undefined;
mediaType: 'audio' | 'video';
playbackRate: number;
+ displayName: string | null;
}) => {
const videoConfig = useVideoConfig();
const {rootId, audioAndVideoTags} = useContext(TimelineContext);
@@ -103,7 +105,7 @@ export const useMediaInTimeline = ({
duration,
from: 0,
parent: parentSequence?.id ?? null,
- displayName: getAssetDisplayName(src),
+ displayName: displayName ?? getAssetDisplayName(src),
rootId,
volume: volumes,
showInTimeline: true,
@@ -133,6 +135,7 @@ export const useMediaInTimeline = ({
mediaType,
startsAt,
playbackRate,
+ displayName,
]);
useEffect(() => {
diff --git a/packages/core/src/video/OffthreadVideo.tsx b/packages/core/src/video/OffthreadVideo.tsx
index 32a6a86a74..1da3beec59 100644
--- a/packages/core/src/video/OffthreadVideo.tsx
+++ b/packages/core/src/video/OffthreadVideo.tsx
@@ -16,7 +16,7 @@ export const OffthreadVideo: React.FC<Omit<OffthreadVideoProps, 'loop'>> = (
) => {
// Should only destruct `startFrom` and `endAt` from props,
// rest gets drilled down
- const {startFrom, endAt, ...otherProps} = props;
+ const {startFrom, endAt, name, ...otherProps} = props;
const environment = getRemotionEnvironment();
const onDuration = useCallback(() => undefined, []);
@@ -46,6 +46,7 @@ export const OffthreadVideo: React.FC<Omit<OffthreadVideoProps, 'loop'>> = (
from={0 - startFromFrameNo}
showInTimeline={false}
durationInFrames={endAtFrameNo}
+ name={name}
>
<OffthreadVideo {...otherProps} />
</Sequence>
diff --git a/packages/core/src/video/OffthreadVideoForRendering.tsx b/packages/core/src/video/OffthreadVideoForRendering.tsx
index 871ff16e48..474fbdb52a 100644
--- a/packages/core/src/video/OffthreadVideoForRendering.tsx
+++ b/packages/core/src/video/OffthreadVideoForRendering.tsx
@@ -27,6 +27,7 @@ export const OffthreadVideoForRendering: React.FC<OffthreadVideoProps> = ({
allowAmplificationDuringRender,
transparent = false,
toneFrequency,
+ name,
...props
}) => {
const absoluteFrame = useTimelinePosition();
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/Video.tsx
index c97fd3abf3..82dec0e37f 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/Video.tsx
@@ -18,7 +18,7 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
HTMLVideoElement,
RemotionVideoProps & RemotionMainVideoProps
> = (props, ref) => {
- const {startFrom, endAt, ...otherProps} = props;
+ const {startFrom, endAt, name, ...otherProps} = props;
const {loop, ...propsOtherThanLoop} = props;
const {fps} = useVideoConfig();
const environment = getRemotionEnvironment();
@@ -58,6 +58,7 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
startFrom,
})}
layout="none"
+ name={name}
>
<Video {...propsOtherThanLoop} ref={ref} />
</Loop>
@@ -75,6 +76,7 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
from={0 - startFromFrameNo}
showInTimeline={false}
durationInFrames={endAtFrameNo}
+ name={name}
>
<Video {...otherProps} ref={ref} />
</Sequence>
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index fd742efc95..1353984996 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -50,6 +50,7 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
acceptableTimeShift,
acceptableTimeShiftInSeconds,
toneFrequency,
+ name,
...nativeProps
} = props;
if (typeof acceptableTimeShift !== 'undefined') {
@@ -70,6 +71,7 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
mediaType: 'video',
src,
playbackRate: props.playbackRate ?? 1,
+ displayName: name ?? null,
});
useSyncVolumeWithMediaTag({
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index 5c2d788bd7..6490d9a520 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -42,6 +42,7 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
playbackRate,
onDuration,
toneFrequency,
+ name,
...props
},
ref,
diff --git a/packages/core/src/video/props.ts b/packages/core/src/video/props.ts
index 81aade1438..5a4441e7b5 100644
--- a/packages/core/src/video/props.ts
+++ b/packages/core/src/video/props.ts
@@ -13,6 +13,7 @@ export type RemotionVideoProps = Omit<
>,
'autoPlay' | 'controls' | 'onEnded' | 'nonce'
> & {
+ name?: string;
volume?: VolumeProp;
playbackRate?: number;
acceptableTimeShiftInSeconds?: number;
@@ -30,6 +31,7 @@ type DeprecatedOffthreadVideoProps = {
export type OffthreadVideoProps = {
src: string;
className?: string;
+ name?: string;
id?: string;
style?: React.CSSProperties;
volume?: VolumeProp;