Skip to content

🎥 Make videos programmatically with React

`@remotion/media`: Make `<Video>` and `<Audio>` a true `<Sequence>` and inherit timeline rendering behavior (#7228)

Jonny Burgerd7b406467ed0
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsx
index 733e1ad863..2be08018f0 100644
--- a/packages/core/src/HtmlInCanvas.tsx
+++ b/packages/core/src/HtmlInCanvas.tsx
@@ -295,7 +295,7 @@ const htmlInCanvasSchema = {
const HtmlInCanvasInner = forwardRef<
HTMLCanvasElement,
HtmlInCanvasProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
}
>(
(
@@ -306,7 +306,7 @@ const HtmlInCanvasInner = forwardRef<
children,
onPaint,
onInit,
- controls,
+ _experimentalControls: controls,
style,
durationInFrames,
...sequenceProps
@@ -517,7 +517,7 @@ const HtmlInCanvasInner = forwardRef<
<Sequence
durationInFrames={resolvedDuration}
name="<HtmlInCanvas>"
- controls={controls}
+ _experimentalControls={controls}
layout="none"
{...sequenceProps}
>
diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsx
index cb60b574ca..b1a688ca7f 100644
--- a/packages/core/src/Img.tsx
+++ b/packages/core/src/Img.tsx
@@ -91,7 +91,7 @@ const imgSchema = {
const ImgInner: React.FC<
ImgProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
}
> = ({
onError,
@@ -106,7 +106,7 @@ const ImgInner: React.FC<
name,
stack,
ref,
- controls,
+ _experimentalControls: controls,
...props
}) => {
const imageRef = useRef<HTMLImageElement>(null);
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index cb9b6b3a67..4faf00e1a1 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -25,6 +25,7 @@ import {
useTimelinePosition,
} from './timeline-position-state.js';
import {useCurrentFrame} from './use-current-frame';
+import type {BasicMediaInTimelineReturnType} from './use-media-in-timeline.js';
import {useRemotionEnvironment} from './use-remotion-environment.js';
import {useVideoConfig} from './use-video-config.js';
import {ENABLE_V5_BREAKING_CHANGES} from './v5-flag.js';
@@ -52,7 +53,7 @@ export type SequencePropsWithoutDuration = {
readonly from?: number;
readonly name?: string;
readonly showInTimeline?: boolean;
- readonly controls?: SequenceControls;
+ readonly _experimentalControls?: SequenceControls;
readonly _experimentalEffects?: EffectsProp;
/**
* @deprecated For internal use only.
@@ -78,6 +79,13 @@ export type SequencePropsWithoutDuration = {
* @deprecated For internal use only.
*/
readonly _remotionInternalIsPostmounting?: boolean;
+ /**
+ * @deprecated For internal use only.
+ */
+ readonly _remotionInternalIsMedia?: {
+ type: 'video' | 'audio';
+ data: BasicMediaInTimelineReturnType;
+ };
} & LayoutAndStyle;
export type SequenceProps = {
@@ -96,12 +104,13 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
height,
width,
showInTimeline = true,
- controls,
+ _experimentalControls: controls,
_experimentalEffects,
_remotionInternalLoopDisplay: loopDisplay,
_remotionInternalStack: stack,
_remotionInternalPremountDisplay: premountDisplay,
_remotionInternalPostmountDisplay: postmountDisplay,
+ _remotionInternalIsMedia: isMedia,
...other
},
ref,
@@ -225,6 +234,34 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
return;
}
+ if (isMedia) {
+ registerSequence({
+ type: isMedia.type,
+ controls: controls ?? null,
+ effects: memoizedEffects,
+ displayName: timelineClipName,
+ doesVolumeChange: isMedia.data.doesVolumeChange,
+ duration: actualDurationInFrames,
+ from,
+ id,
+ loopDisplay,
+ nonce: nonce.get(),
+ parent: parentSequence?.id ?? null,
+ playbackRate: isMedia.data.playbackRate,
+ postmountDisplay: postmountDisplay ?? null,
+ premountDisplay: premountDisplay ?? null,
+ rootId,
+ showInTimeline,
+ src: isMedia.data.src,
+ stack: stack ?? inheritedStack,
+ startMediaFrom: isMedia.data.startMediaFrom,
+ volume: isMedia.data.volumes,
+ });
+ return () => {
+ unregisterSequence(id);
+ };
+ }
+
registerSequence({
from,
duration: actualDurationInFrames,
@@ -266,6 +303,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
inheritedStack,
controls,
memoizedEffects,
+ isMedia,
]);
// Ceil to support floats
diff --git a/packages/core/src/audio/Audio.tsx b/packages/core/src/audio/html5-audio.tsx
similarity index 100%
rename from packages/core/src/audio/Audio.tsx
rename to packages/core/src/audio/html5-audio.tsx
diff --git a/packages/core/src/audio/index.tsx b/packages/core/src/audio/index.tsx
index f9f11e5533..e81d0ea3c6 100644
--- a/packages/core/src/audio/index.tsx
+++ b/packages/core/src/audio/index.tsx
@@ -1,2 +1,2 @@
-export {Audio, Html5Audio} from './Audio.js';
+export {Audio, Html5Audio} from './html5-audio.js';
export * from './props.js';
diff --git a/packages/core/src/get-timeline-duration.ts b/packages/core/src/get-timeline-duration.ts
index 20864dd1ca..e8975e2e4d 100644
--- a/packages/core/src/get-timeline-duration.ts
+++ b/packages/core/src/get-timeline-duration.ts
@@ -6,13 +6,19 @@ export const getTimelineDuration = ({
trimBefore,
trimAfter,
parentSequenceDurationInFrames,
+ loop,
}: {
compositionDurationInFrames: number;
playbackRate: number;
trimBefore: number | undefined;
trimAfter: number | undefined;
parentSequenceDurationInFrames: number | null;
+ loop: boolean;
}) => {
+ if (loop) {
+ return compositionDurationInFrames;
+ }
+
const mediaDuration = calculateMediaDuration({
mediaDurationInFrames:
compositionDurationInFrames * playbackRate + (trimBefore ?? 0),
diff --git a/packages/core/src/loop/index.tsx b/packages/core/src/loop/index.tsx
index 57449cdcbc..69ce76579b 100644
--- a/packages/core/src/loop/index.tsx
+++ b/packages/core/src/loop/index.tsx
@@ -1,6 +1,6 @@
import React, {createContext, useMemo} from 'react';
import type {LoopDisplay} from '../CompositionManager.js';
-import type {LayoutAndStyle} from '../Sequence.js';
+import type {LayoutAndStyle, SequenceProps} from '../Sequence.js';
import {Sequence} from '../Sequence.js';
import {useCurrentFrame} from '../use-current-frame.js';
import {useVideoConfig} from '../use-video-config.js';
@@ -13,7 +13,8 @@ export type LoopProps = {
readonly times?: number;
readonly name?: string;
readonly children: React.ReactNode;
-} & LayoutAndStyle;
+} & LayoutAndStyle &
+ Pick<SequenceProps, 'showInTimeline'>;
type LoopContextType = {
iteration: number;
@@ -32,7 +33,14 @@ const useLoop = () => {
*/
export const Loop: React.FC<LoopProps> & {
useLoop: typeof useLoop;
-} = ({durationInFrames, times = Infinity, children, name, ...props}) => {
+} = ({
+ durationInFrames,
+ times = Infinity,
+ children,
+ name,
+ showInTimeline,
+ ...props
+}) => {
const currentFrame = useCurrentFrame();
const {durationInFrames: compDuration} = useVideoConfig();
@@ -91,6 +99,7 @@ export const Loop: React.FC<LoopProps> & {
_remotionInternalLoopDisplay={loopDisplay}
layout={props.layout}
style={style}
+ showInTimeline={showInTimeline}
>
{children}
</Sequence>
diff --git a/packages/core/src/test/get-media-duration.test.ts b/packages/core/src/test/get-media-duration.test.ts
index 60945dbd43..73e43eb1eb 100644
--- a/packages/core/src/test/get-media-duration.test.ts
+++ b/packages/core/src/test/get-media-duration.test.ts
@@ -8,6 +8,7 @@ test('playbackRate 2.45 with 300 composition frames returns 300', () => {
trimBefore: undefined,
trimAfter: undefined,
parentSequenceDurationInFrames: null,
+ loop: false,
});
expect(duration).toBe(300);
@@ -20,6 +21,7 @@ test('playbackRate 1 returns composition duration unchanged', () => {
trimBefore: undefined,
trimAfter: undefined,
parentSequenceDurationInFrames: null,
+ loop: false,
});
expect(duration).toBe(300);
@@ -32,6 +34,7 @@ test('playbackRate 0.5 with 300 composition frames returns 300', () => {
trimBefore: undefined,
trimAfter: undefined,
parentSequenceDurationInFrames: null,
+ loop: false,
});
expect(duration).toBe(300);
@@ -44,6 +47,7 @@ test('parentSequence caps the duration', () => {
trimBefore: undefined,
trimAfter: undefined,
parentSequenceDurationInFrames: 100,
+ loop: false,
});
expect(duration).toBe(100);
@@ -56,6 +60,7 @@ test('parentSequence with playbackRate 2.45 caps correctly', () => {
trimBefore: undefined,
trimAfter: undefined,
parentSequenceDurationInFrames: 100,
+ loop: false,
});
expect(duration).toBe(245);
@@ -68,6 +73,7 @@ test('trimBefore is accounted for', () => {
trimBefore: 30,
trimAfter: undefined,
parentSequenceDurationInFrames: null,
+ loop: false,
});
expect(duration).toBe(300);
diff --git a/packages/core/src/use-media-in-timeline.ts b/packages/core/src/use-media-in-timeline.ts
index 50031de687..90ee68efc9 100644
--- a/packages/core/src/use-media-in-timeline.ts
+++ b/packages/core/src/use-media-in-timeline.ts
@@ -32,6 +32,9 @@ export const useBasicMediaInTimeline = ({
trimBefore,
trimAfter,
playbackRate,
+ sequenceDurationInFrames,
+ mediaStartsAt,
+ loop,
}: {
volume: VolumeProp | undefined;
mediaVolume: number;
@@ -41,23 +44,25 @@ export const useBasicMediaInTimeline = ({
trimBefore: number | undefined;
trimAfter: number | undefined;
playbackRate: number;
+ sequenceDurationInFrames: number;
+ mediaStartsAt: number;
+ loop: boolean;
}) => {
if (!src) {
throw new Error('No src passed');
}
- const startsAt = useMediaStartsAt();
const parentSequence = useContext(SequenceContext);
- const videoConfig = useVideoConfig();
const [initialVolume] = useState<VolumeProp | undefined>(() => volume);
const duration = getTimelineDuration({
- compositionDurationInFrames: videoConfig.durationInFrames,
+ compositionDurationInFrames: sequenceDurationInFrames,
playbackRate,
trimBefore,
trimAfter,
parentSequenceDurationInFrames: parentSequence?.durationInFrames ?? null,
+ loop,
});
const volumes: string | number = useMemo(() => {
@@ -65,17 +70,17 @@ export const useBasicMediaInTimeline = ({
return volume;
}
- return new Array(Math.floor(Math.max(0, duration + startsAt)))
+ return new Array(Math.floor(Math.max(0, duration + mediaStartsAt)))
.fill(true)
.map((_, i) => {
return evaluateVolume({
- frame: i + startsAt,
+ frame: i + mediaStartsAt,
volume,
mediaVolume,
});
})
.join(',');
- }, [duration, startsAt, volume, mediaVolume]);
+ }, [duration, mediaStartsAt, volume, mediaVolume]);
useEffect(() => {
if (typeof volume === 'number' && volume !== initialVolume) {
@@ -90,16 +95,39 @@ export const useBasicMediaInTimeline = ({
const nonce = useNonce();
const {rootId} = useTimelineContext();
- return {
+ const startMediaFrom = 0 - mediaStartsAt + (trimBefore ?? 0);
+
+ const memoizedResult = useMemo(() => {
+ return {
+ volumes,
+ duration,
+ doesVolumeChange,
+ nonce,
+ rootId,
+ finalDisplayName: displayName ?? getAssetDisplayName(src),
+ startMediaFrom,
+ src,
+ playbackRate,
+ };
+ }, [
volumes,
duration,
doesVolumeChange,
nonce,
rootId,
- finalDisplayName: displayName ?? getAssetDisplayName(src),
- };
+ displayName,
+ src,
+ startMediaFrom,
+ playbackRate,
+ ]);
+
+ return memoizedResult;
};
+export type BasicMediaInTimelineReturnType = ReturnType<
+ typeof useBasicMediaInTimeline
+>;
+
export const useImageInTimeline = ({
src,
displayName,
@@ -124,6 +152,8 @@ export const useImageInTimeline = ({
const parentSequence = useContext(SequenceContext);
const {registerSequence, unregisterSequence} = useContext(SequenceManager);
+ const {durationInFrames} = useVideoConfig();
+ const mediaStartsAt = useMediaStartsAt();
const {duration, nonce, rootId, finalDisplayName} = useBasicMediaInTimeline({
volume: undefined,
mediaVolume: 0,
@@ -133,6 +163,9 @@ export const useImageInTimeline = ({
trimAfter: undefined,
trimBefore: undefined,
playbackRate: 1,
+ sequenceDurationInFrames: durationInFrames,
+ mediaStartsAt,
+ loop: false,
});
const {isStudio} = useRemotionEnvironment();
@@ -222,6 +255,8 @@ export const useMediaInTimeline = ({
const parentSequence = useContext(SequenceContext);
const startsAt = useMediaStartsAt();
const {registerSequence, unregisterSequence} = useContext(SequenceManager);
+ const {durationInFrames} = useVideoConfig();
+ const mediaStartsAt = useMediaStartsAt();
const {volumes, duration, doesVolumeChange, nonce, rootId, finalDisplayName} =
useBasicMediaInTimeline({
@@ -233,6 +268,9 @@ export const useMediaInTimeline = ({
trimAfter: undefined,
trimBefore: undefined,
playbackRate,
+ sequenceDurationInFrames: durationInFrames,
+ mediaStartsAt,
+ loop: false,
});
const {isStudio} = useRemotionEnvironment();
diff --git a/packages/core/src/video/Video.tsx b/packages/core/src/video/html5-video.tsx
similarity index 99%
rename from packages/core/src/video/Video.tsx
rename to packages/core/src/video/html5-video.tsx
index bc5610c5ae..0ae8375ad3 100644
--- a/packages/core/src/video/Video.tsx
+++ b/packages/core/src/video/html5-video.tsx
@@ -112,6 +112,7 @@ const VideoForwardingFunction: React.ForwardRefRenderFunction<
})}
layout="none"
name={name}
+ showInTimeline={false}
>
<Html5Video
{...propsOtherThanLoop}
diff --git a/packages/core/src/video/index.ts b/packages/core/src/video/index.ts
index 15f39b6dbe..11f88a04ea 100644
--- a/packages/core/src/video/index.ts
+++ b/packages/core/src/video/index.ts
@@ -5,4 +5,4 @@ export type {
RemotionOffthreadVideoProps,
RemotionVideoProps,
} from './props';
-export {Html5Video, Video} from './Video.js';
+export {Html5Video, Video} from './html5-video.js';
diff --git a/packages/core/src/wrap-in-schema.ts b/packages/core/src/wrap-in-schema.ts
index 329ea3d2c1..2745c7370b 100644
--- a/packages/core/src/wrap-in-schema.ts
+++ b/packages/core/src/wrap-in-schema.ts
@@ -61,7 +61,7 @@ const mergeValues = (
export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
Component: React.ComponentType<
- Props & {readonly controls: SequenceControls | undefined}
+ Props & {readonly _experimentalControls: SequenceControls | undefined}
>,
schema: S,
): React.ComponentType<Props> => {
@@ -77,9 +77,12 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
) {
return React.createElement(Component, {
...props,
- controls: null,
+ _experimentalControls: null,
ref,
- } as Props & {controls: SequenceControls | undefined; ref: typeof ref});
+ } as Props & {
+ _experimentalControls: SequenceControls | undefined;
+ ref: typeof ref;
+ });
}
// eslint-disable-next-line react-hooks/rules-of-hooks
@@ -113,9 +116,12 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>(
return React.createElement(Component, {
...mergedProps,
- controls,
+ _experimentalControls: controls,
ref,
- } as Props & {controls: SequenceControls | undefined; ref: typeof ref});
+ } as Props & {
+ _experimentalControls: SequenceControls | undefined;
+ ref: typeof ref;
+ });
});
Wrapped.displayName = `wrapInSchema(${Component.displayName || Component.name || 'Component'})`;
diff --git a/packages/docs/docs/html5-audio.mdx b/packages/docs/docs/html5-audio.mdx
index b5eedb7d78..722d068ac6 100644
--- a/packages/docs/docs/html5-audio.mdx
+++ b/packages/docs/docs/html5-audio.mdx
@@ -241,7 +241,7 @@ To prevent synthetic amplification, set a volume not higher than 1.
## See also
-- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/audio/Audio.tsx)
+- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/audio/html5-audio.tsx)
- [Using audio](/docs/using-audio)
- [Audio visualization](/docs/audio/visualization)
- [`<Html5Video />`](/docs/html5-video)
diff --git a/packages/docs/docs/html5-video.mdx b/packages/docs/docs/html5-video.mdx
index 68c495f285..349f6b1c0c 100644
--- a/packages/docs/docs/html5-video.mdx
+++ b/packages/docs/docs/html5-video.mdx
@@ -323,7 +323,7 @@ To decide which tag to use, see: [Comparison of video tags](/docs/video-tags)
## See also
-- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/video/Video.tsx)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/video/html5-video.tsx)
- [`<Html5Audio />`](/docs/html5-audio)
- [`<OffthreadVideo />`](/docs/offthreadvideo)
- [`<Video />` (from `@remotion/media`)](/docs/media/video)
diff --git a/packages/example/e2e/undo-redo-sync.test.mts b/packages/example/e2e/undo-redo-sync.test.mts
index 2b8458ada4..865610b7d1 100644
--- a/packages/example/e2e/undo-redo-sync.test.mts
+++ b/packages/example/e2e/undo-redo-sync.test.mts
@@ -43,14 +43,14 @@ test.describe('undo redo sync across tabs', () => {
// 2. Click the expand arrow on the Video track
const expandTrackButton = page1.locator(
- 'button[aria-label="Expand track properties"]',
+ 'button[aria-label="Expand track properties"]:not([disabled])',
);
await expect(expandTrackButton).toBeVisible({timeout: 15_000});
await expandTrackButton.click();
// 3. Expand the Controls section to reveal the schema fields
const expandControlsButton = page1.locator(
- 'button[aria-label="Expand Controls section"]',
+ 'button[aria-label="Expand Controls section"]:not([disabled])',
);
await expect(expandControlsButton).toBeVisible({timeout: 10_000});
await expandControlsButton.click();
diff --git a/packages/example/e2e/undo-redo.test.mts b/packages/example/e2e/undo-redo.test.mts
index e353db3660..944084ebab 100644
--- a/packages/example/e2e/undo-redo.test.mts
+++ b/packages/example/e2e/undo-redo.test.mts
@@ -37,14 +37,14 @@ test.describe('undo redo', () => {
// 2. Click the expand arrow on the Video track
const expandTrackButton = page.locator(
- 'button[aria-label="Expand track properties"]',
+ 'button[aria-label="Expand track properties"]:not([disabled])',
);
await expect(expandTrackButton).toBeVisible({timeout: 15_000});
await expandTrackButton.click();
// 3. Expand the Controls section to reveal the schema fields
const expandControlsButton = page.locator(
- 'button[aria-label="Expand Controls section"]',
+ 'button[aria-label="Expand Controls section"]:not([disabled])',
);
await expect(expandControlsButton).toBeVisible({timeout: 10_000});
await expandControlsButton.click();
diff --git a/packages/example/src/ExperimentalControls/index.tsx b/packages/example/src/ExperimentalControls/index.tsx
new file mode 100644
index 0000000000..fdee9a7c5d
--- /dev/null
+++ b/packages/example/src/ExperimentalControls/index.tsx
@@ -0,0 +1,172 @@
+import {Gif} from '@remotion/gif';
+import {LightLeak} from '@remotion/light-leaks';
+import {Audio, Video} from '@remotion/media';
+import {Starburst} from '@remotion/starburst';
+import React from 'react';
+import {AbsoluteFill, HtmlInCanvas, Img, Sequence, staticFile} from 'remotion';
+
+const Tile: React.FC<{
+ readonly title: string;
+ readonly children: React.ReactNode;
+}> = ({title, children}) => {
+ return (
+ <div
+ style={{
+ flex: 1,
+ display: 'flex',
+ flexDirection: 'column',
+ border: '2px solid #333',
+ borderRadius: 8,
+ overflow: 'hidden',
+ backgroundColor: '#111',
+ minWidth: 0,
+ minHeight: 0,
+ }}
+ >
+ <div
+ style={{
+ padding: '8px 12px',
+ fontFamily: 'monospace',
+ fontSize: 16,
+ color: '#fff',
+ backgroundColor: '#222',
+ }}
+ >
+ {title}
+ </div>
+ <div
+ style={{
+ flex: 1,
+ position: 'relative',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ overflow: 'hidden',
+ }}
+ >
+ {children}
+ </div>
+ </div>
+ );
+};
+
+export const ExperimentalControlsShowcase: React.FC = () => {
+ return (
+ <AbsoluteFill style={{backgroundColor: 'black', padding: 16, gap: 16}}>
+ <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
+ <Tile title="Img">
+ <Img
+ src={staticFile('1.jpg')}
+ style={{
+ maxWidth: '100%',
+ maxHeight: '100%',
+ translate: '0px 93px',
+ scale: 1.65,
+ }}
+ />
+ </Tile>
+ <Tile title="Sequence">
+ <Sequence durationInFrames={120} name="inner-sequence">
+ <AbsoluteFill
+ style={{
+ backgroundColor: '#3344ff',
+ color: 'white',
+ fontFamily: 'sans-serif',
+ fontSize: 40,
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}
+ >
+ Sequence
+ </AbsoluteFill>
+ </Sequence>
+ </Tile>
+ <Tile title="HtmlInCanvas">
+ <HtmlInCanvas
+ width={400}
+ height={300}
+ style={{
+ translate: '0px -110px',
+ scale: 0.78,
+ rotate: '48deg',
+ }}
+ >
+ <div
+ style={{
+ width: 400,
+ height: 300,
+ backgroundColor: '#101728',
+ color: 'white',
+ fontFamily: 'sans-serif',
+ fontSize: 32,
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}
+ >
+ HtmlInCanvas
+ </div>
+ </HtmlInCanvas>
+ </Tile>
+ <Tile title="LightLeak">
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <LightLeak
+ durationInFrames={120}
+ seed={3}
+ hueShift={30}
+ style={{
+ translate: '0px 81px',
+ scale: 1.1,
+ }}
+ />
+ </AbsoluteFill>
+ </Tile>
+ </div>
+ <div style={{flex: 1, display: 'flex', flexDirection: 'row', gap: 16}}>
+ <Tile title="Starburst">
+ <AbsoluteFill style={{backgroundColor: 'black'}}>
+ <Starburst
+ rays={16}
+ colors={['#ffdd00', '#ff8800']}
+ vignette={0.5}
+ />
+ </AbsoluteFill>
+ </Tile>
+ <Tile title="Gif">
+ <Gif
+ src={staticFile('giphy.gif')}
+ fit="contain"
+ width={400}
+ height={300}
+ style={{
+ translate: '0px 59px',
+ }}
+ />
+ </Tile>
+ <Tile title="Video">
+ <Video
+ src={staticFile('bigbuckbunny.mp4')}
+ style={{
+ width: '100%',
+ height: '100%',
+ translate: '0px -27px',
+ }}
+ objectFit="contain"
+ />
+ </Tile>
+ <Tile title="Audio">
+ <div
+ style={{
+ color: 'white',
+ fontFamily: 'sans-serif',
+ fontSize: 24,
+ textAlign: 'center',
+ }}
+ >
+ Audio (no visual)
+ <Audio src={staticFile('music.mp3')} volume={1.29} />
+ </div>
+ </Tile>
+ </div>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index a2b896b2fb..8f9c7f53d2 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -31,6 +31,7 @@ import {
import {DynamicDuration, dynamicDurationSchema} from './DynamicDuration';
import {EmojiTestbed} from './Emoji';
import {ErrorOnFrame10} from './ErrorOnFrame10';
+import {ExperimentalControlsShowcase} from './ExperimentalControls';
import {Expert} from './Expert';
import {FontDemo} from './Fonts';
import {Framer} from './Framer';
@@ -2047,6 +2048,14 @@ export const Index: React.FC = () => {
durationInFrames={90}
/>
</Folder>
+ <Composition
+ id="experimental-controls-showcase"
+ component={ExperimentalControlsShowcase}
+ width={1920}
+ height={1080}
+ fps={30}
+ durationInFrames={120}
+ />
<Composition
id="sfx"
component={SfxExample}
diff --git a/packages/gif/src/Gif.tsx b/packages/gif/src/Gif.tsx
index d1e37a807e..e7952ae292 100644
--- a/packages/gif/src/Gif.tsx
+++ b/packages/gif/src/Gif.tsx
@@ -76,11 +76,11 @@ const GifInner = ({
delayRenderTimeoutInMilliseconds,
durationInFrames,
style,
- controls,
+ _experimentalControls: controls,
ref,
...sequenceProps
}: GifProps & {
- readonly controls?: SequenceControls | undefined;
+ readonly _experimentalControls?: SequenceControls | undefined;
readonly ref?: React.Ref<HTMLCanvasElement>;
}) => {
const env = useRemotionEnvironment();
@@ -112,7 +112,7 @@ const GifInner = ({
layout="none"
durationInFrames={resolvedDuration}
name="<Gif>"
- controls={controls}
+ _experimentalControls={controls}
{...sequenceProps}
>
{inner}
diff --git a/packages/light-leaks/src/LightLeak.tsx b/packages/light-leaks/src/LightLeak.tsx
index 6943ee2287..3d4b9d6ba1 100644
--- a/packages/light-leaks/src/LightLeak.tsx
+++ b/packages/light-leaks/src/LightLeak.tsx
@@ -275,14 +275,14 @@ const lightLeakSchema = {
const LightLeakInner: React.FC<
LightLeakProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
}
> = ({
seed = 0,
hueShift = 0,
durationInFrames,
style,
- controls,
+ _experimentalControls: controls,
...sequenceProps
}) => {
const {durationInFrames: videoDuration} = useVideoConfig();
@@ -309,7 +309,7 @@ const LightLeakInner: React.FC<
<Sequence
durationInFrames={resolvedDuration}
name="<LightLeak>"
- controls={controls}
+ _experimentalControls={controls}
{...sequenceProps}
style={style}
>
diff --git a/packages/media/src/audio/audio-for-preview.tsx b/packages/media/src/audio/audio-for-preview.tsx
index b852169c25..0cdea5b956 100644
--- a/packages/media/src/audio/audio-for-preview.tsx
+++ b/packages/media/src/audio/audio-for-preview.tsx
@@ -1,10 +1,5 @@
import React, {useContext, useEffect, useMemo, useRef, useState} from 'react';
-import type {
- LogLevel,
- LoopVolumeCurveBehavior,
- SequenceControls,
- VolumeProp,
-} from 'remotion';
+import type {LogLevel, LoopVolumeCurveBehavior, VolumeProp} from 'remotion';
import {
Internals,
Audio as RemotionAudio,
@@ -15,9 +10,7 @@ import {
import {getTimeInSeconds} from '../get-time-in-seconds';
import {MediaPlayer} from '../media-player';
import {type MediaOnError, callOnErrorAndResolve} from '../on-error';
-import {useLoopDisplay} from '../show-in-timeline';
import {useCommonEffects} from '../use-common-effects';
-import {useMediaInTimeline} from '../use-media-in-timeline';
import type {FallbackHtml5AudioProps} from './props';
const {
@@ -52,15 +45,10 @@ type NewAudioForPreviewProps = {
readonly fallbackHtml5AudioProps: FallbackHtml5AudioProps | undefined;
readonly onError: MediaOnError | undefined;
readonly credentials: RequestCredentials | undefined;
+ readonly setMediaDurationInSeconds: (durationInSeconds: number) => void;
};
-type AudioForPreviewAssertedShowingProps = NewAudioForPreviewProps & {
- readonly controls: SequenceControls | undefined;
-};
-
-const AudioForPreviewAssertedShowing: React.FC<
- AudioForPreviewAssertedShowingProps
-> = ({
+const AudioForPreviewAssertedShowing: React.FC<NewAudioForPreviewProps> = ({
src,
playbackRate,
logLevel,
@@ -79,7 +67,7 @@ const AudioForPreviewAssertedShowing: React.FC<
fallbackHtml5AudioProps,
onError,
credentials,
- controls,
+ setMediaDurationInSeconds,
}) => {
const videoConfig = useUnsafeVideoConfig();
const frame = useCurrentFrame();
@@ -99,9 +87,6 @@ const AudioForPreviewAssertedShowing: React.FC<
const [mediaMuted] = useMediaMutedState();
const [mediaVolume] = useMediaVolumeState();
- const [mediaDurationInSeconds, setMediaDurationInSeconds] = useState<
- number | null
- >(null);
const volumePropFrame = useFrameForVolumeProp(
loopVolumeCurveBehavior ?? 'repeat',
@@ -138,36 +123,6 @@ const AudioForPreviewAssertedShowing: React.FC<
(parentSequence?.relativeFrom ?? 0)) /
videoConfig.fps;
- const loopDisplay = useLoopDisplay({
- loop,
- mediaDurationInSeconds,
- playbackRate,
- trimAfter,
- trimBefore,
- });
-
- const effects = useMemo(() => {
- return [];
- }, []);
-
- useMediaInTimeline({
- volume,
- mediaVolume,
- mediaType: 'audio',
- src,
- playbackRate,
- displayName: name ?? null,
- stack,
- showInTimeline,
- premountDisplay: parentSequence?.premountDisplay ?? null,
- postmountDisplay: parentSequence?.postmountDisplay ?? null,
- loopDisplay,
- trimAfter,
- trimBefore,
- controls,
- _experimentalEffects: effects,
- });
-
const bufferingContext = useContext(Internals.BufferingContextReact);
if (!bufferingContext) {
@@ -395,6 +350,7 @@ const AudioForPreviewAssertedShowing: React.FC<
buffer,
onError,
credentials,
+ setMediaDurationInSeconds,
]);
if (shouldFallbackToNativeAudio && !disallowFallbackToHtml5Audio) {
@@ -449,13 +405,10 @@ type InnerAudioProps = {
readonly fallbackHtml5AudioProps?: FallbackHtml5AudioProps;
readonly onError?: MediaOnError;
readonly credentials?: RequestCredentials;
+ readonly setMediaDurationInSeconds?: (durationInSeconds: number) => void;
};
-export const AudioForPreview: React.FC<
- InnerAudioProps & {
- readonly controls: SequenceControls | undefined;
- }
-> = ({
+export const AudioForPreview: React.FC<InnerAudioProps> = ({
loop = false,
src,
logLevel,
@@ -474,7 +427,7 @@ export const AudioForPreview: React.FC<
fallbackHtml5AudioProps,
onError,
credentials,
- controls,
+ setMediaDurationInSeconds,
}) => {
const preloadedSrc = usePreload(src);
@@ -511,6 +464,10 @@ export const AudioForPreview: React.FC<
return null;
}
+ if (!setMediaDurationInSeconds) {
+ throw new Error('setMediaDurationInSeconds is required');
+ }
+
return (
<AudioForPreviewAssertedShowing
audioStreamIndex={audioStreamIndex}
@@ -531,7 +488,7 @@ export const AudioForPreview: React.FC<
onError={onError}
credentials={credentials}
fallbackHtml5AudioProps={fallbackHtml5AudioProps}
- controls={controls}
+ setMediaDurationInSeconds={setMediaDurationInSeconds}
/>
);
};
diff --git a/packages/media/src/audio/audio.tsx b/packages/media/src/audio/audio.tsx
index c55a93b815..e0aa283653 100644
--- a/packages/media/src/audio/audio.tsx
+++ b/packages/media/src/audio/audio.tsx
@@ -1,6 +1,13 @@
+import {useState} from 'react';
import React from 'react';
-import type {SequenceControls, SequenceSchema} from 'remotion';
+import {useMemo} from 'react';
+import {
+ useVideoConfig,
+ type SequenceControls,
+ type SequenceSchema,
+} from 'remotion';
import {Internals, Sequence, useRemotionEnvironment} from 'remotion';
+import {getLoopDisplay} from '../show-in-timeline';
import {AudioForPreview} from './audio-for-preview';
import {AudioForRendering} from './audio-for-rendering';
import type {AudioProps} from './props';
@@ -28,7 +35,7 @@ const audioSchema = {
const AudioInner: React.FC<
AudioProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
}
> = (props) => {
// Should only destruct `trimBefore` and `trimAfter` from props,
@@ -37,13 +44,70 @@ const AudioInner: React.FC<
name,
stack,
showInTimeline,
- controls,
+ _experimentalControls: controls,
from,
durationInFrames,
...otherProps
} = props;
const environment = useRemotionEnvironment();
+ const [mediaVolume] = Internals.useMediaVolumeState();
+ const mediaStartsAt = Internals.useMediaStartsAt();
+ const videoConfig = useVideoConfig();
+ const sequenceDurationInFrames = Math.min(
+ durationInFrames ?? Infinity,
+ Math.max(0, videoConfig.durationInFrames - (from ?? 0)),
+ );
+
+ const basicInfo = Internals.useBasicMediaInTimeline({
+ src: props.src,
+ volume: props.volume,
+ playbackRate: props.playbackRate ?? 1,
+ trimBefore: props.trimBefore,
+ trimAfter: props.trimAfter,
+ sequenceDurationInFrames,
+ mediaType: 'audio',
+ displayName: name ?? '<Audio>',
+ mediaVolume,
+ mediaStartsAt,
+ loop: props.loop ?? false,
+ });
+
+ // TODO: Redundant with what we do in the Studio
+ const [mediaDurationInSeconds, setMediaDurationInSeconds] = useState<
+ number | null
+ >(null);
+
+ const loopDisplay = useMemo(
+ () =>
+ getLoopDisplay({
+ loop: props.loop ?? false,
+ mediaDurationInSeconds,
+ playbackRate: props.playbackRate ?? 1,
+ trimAfter: props.trimAfter,
+ trimBefore: props.trimBefore,
+ sequenceDurationInFrames,
+ compFps: videoConfig.fps,
+ }),
+ [
+ props.loop,
+ mediaDurationInSeconds,
+ props.playbackRate,
+ props.trimAfter,
+ props.trimBefore,
+ sequenceDurationInFrames,
+ videoConfig.fps,
+ ],
+ );
+
+ const isMedia = useMemo(
+ () => ({
+ type: 'audio' as const,
+ data: basicInfo,
+ }),
+ [basicInfo],
+ );
+
if (typeof props.src !== 'string') {
throw new TypeError(
`The \`<Audio>\` tag requires a string for \`src\`, but got ${JSON.stringify(
@@ -57,12 +121,21 @@ const AudioInner: React.FC<
'Audio',
);
+ if (sequenceDurationInFrames === 0) {
+ return null;
+ }
+
return (
<Sequence
layout="none"
from={from ?? 0}
- durationInFrames={durationInFrames ?? Infinity}
- showInTimeline={false}
+ durationInFrames={basicInfo.duration}
+ _remotionInternalStack={stack}
+ _remotionInternalIsMedia={isMedia}
+ name={name ?? '<Audio>'}
+ _experimentalControls={controls}
+ _remotionInternalLoopDisplay={loopDisplay}
+ showInTimeline={showInTimeline ?? true}
>
{environment.isRendering ? (
<AudioForRendering {...otherProps} />
@@ -71,7 +144,7 @@ const AudioInner: React.FC<
name={name}
{...otherProps}
stack={stack ?? null}
- controls={controls}
+ setMediaDurationInSeconds={setMediaDurationInSeconds}
/>
)}
</Sequence>
diff --git a/packages/media/src/audio/props.ts b/packages/media/src/audio/props.ts
index 5c571280e7..636a599397 100644
--- a/packages/media/src/audio/props.ts
+++ b/packages/media/src/audio/props.ts
@@ -1,4 +1,9 @@
-import type {LogLevel, LoopVolumeCurveBehavior, VolumeProp} from 'remotion';
+import type {
+ LogLevel,
+ LoopVolumeCurveBehavior,
+ SequenceProps,
+ VolumeProp,
+} from 'remotion';
import type {MediaOnError} from '../on-error';
export type FallbackHtml5AudioProps = {
@@ -11,20 +16,10 @@ export type FallbackHtml5AudioProps = {
export type AudioProps = {
src: string;
- /**
- * When set, `<Audio>` applies timing via an inner `<Sequence layout="none">` that is hidden from the timeline (`showInTimeline={false}`) so the clip still appears once as media.
- */
- from?: number;
- /**
- * When set with `from`, bounds the clip in frames. Defaults to `Infinity` like `<Sequence>`.
- */
- durationInFrames?: number;
trimBefore?: number;
trimAfter?: number;
volume?: VolumeProp;
loopVolumeCurveBehavior?: LoopVolumeCurveBehavior;
- name?: string;
- showInTimeline?: boolean;
playbackRate?: number;
muted?: boolean;
style?: React.CSSProperties;
@@ -43,4 +38,7 @@ export type AudioProps = {
delayRenderTimeoutInMilliseconds?: number;
onError?: MediaOnError;
credentials?: RequestCredentials;
-};
+} & Pick<
+ SequenceProps,
+ 'from' | 'durationInFrames' | 'name' | 'showInTimeline'
+>;
diff --git a/packages/media/src/show-in-timeline.ts b/packages/media/src/show-in-timeline.ts
index bec53ceae1..a5a6cdd246 100644
--- a/packages/media/src/show-in-timeline.ts
+++ b/packages/media/src/show-in-timeline.ts
@@ -1,50 +1,39 @@
-import {useMemo} from 'react';
import type {LoopDisplay} from 'remotion';
-import {Internals, useVideoConfig} from 'remotion';
+import {Internals} from 'remotion';
-export const useLoopDisplay = ({
+export const getLoopDisplay = ({
loop,
mediaDurationInSeconds,
playbackRate,
trimAfter,
trimBefore,
+ sequenceDurationInFrames,
+ compFps,
}: {
loop: boolean;
mediaDurationInSeconds: number | null;
trimAfter: number | undefined;
trimBefore: number | undefined;
+ sequenceDurationInFrames: number;
playbackRate: number;
+ compFps: number;
}): LoopDisplay | undefined => {
- const {durationInFrames: compDuration, fps} = useVideoConfig();
+ if (!loop || !mediaDurationInSeconds) {
+ return undefined;
+ }
- const loopDisplay: LoopDisplay | undefined = useMemo(() => {
- if (!loop || !mediaDurationInSeconds) {
- return undefined;
- }
-
- const durationInFrames = Internals.calculateMediaDuration({
- mediaDurationInFrames: mediaDurationInSeconds * fps,
- playbackRate,
- trimAfter,
- trimBefore,
- });
-
- const maxTimes = compDuration / durationInFrames;
-
- return {
- numberOfTimes: maxTimes,
- startOffset: 0,
- durationInFrames,
- };
- }, [
- compDuration,
- fps,
- loop,
- mediaDurationInSeconds,
+ const durationInFrames = Internals.calculateMediaDuration({
+ mediaDurationInFrames: mediaDurationInSeconds * compFps,
playbackRate,
trimAfter,
trimBefore,
- ]);
+ });
+
+ const maxTimes = sequenceDurationInFrames / durationInFrames;
- return loopDisplay;
+ return {
+ numberOfTimes: maxTimes,
+ startOffset: 0,
+ durationInFrames,
+ };
};
diff --git a/packages/media/src/use-media-in-timeline.ts b/packages/media/src/use-media-in-timeline.ts
deleted file mode 100644
index 61ea1059c7..0000000000
--- a/packages/media/src/use-media-in-timeline.ts
+++ /dev/null
@@ -1,133 +0,0 @@
-import {useContext, useEffect, useState} from 'react';
-import {
- useRemotionEnvironment,
- type EffectDefinitionAndStack,
- type LoopDisplay,
- type SequenceControls,
-} from 'remotion';
-import {Internals, type VolumeProp} from 'remotion';
-
-export const useMediaInTimeline = ({
- volume,
- mediaVolume,
- src,
- mediaType,
- playbackRate,
- displayName,
- stack,
- showInTimeline,
- premountDisplay,
- postmountDisplay,
- loopDisplay,
- trimBefore,
- trimAfter,
- controls,
- _experimentalEffects,
-}: {
- volume: VolumeProp | undefined;
- mediaVolume: number;
- src: string | undefined;
- mediaType: 'audio' | 'video';
- playbackRate: number;
- displayName: string | null;
- stack: string | null;
- showInTimeline: boolean;
- premountDisplay: number | null;
- postmountDisplay: number | null;
- loopDisplay: LoopDisplay | undefined;
- trimBefore: number | undefined;
- trimAfter: number | undefined;
- controls: SequenceControls | undefined;
- _experimentalEffects: EffectDefinitionAndStack<unknown>[];
-}) => {
- const parentSequence = useContext(Internals.SequenceContext);
- const startsAt = Internals.useMediaStartsAt();
- const {registerSequence, unregisterSequence} = useContext(
- Internals.SequenceManager,
- );
-
- const [mediaId] = useState(() => String(Math.random()));
-
- const {volumes, duration, doesVolumeChange, nonce, rootId, finalDisplayName} =
- Internals.useBasicMediaInTimeline({
- volume,
- mediaVolume,
- mediaType,
- src,
- displayName,
- trimBefore,
- trimAfter,
- playbackRate,
- });
-
- const {isStudio} = useRemotionEnvironment();
-
- useEffect(() => {
- if (!src) {
- throw new Error('No src passed');
- }
-
- if (!isStudio && window.process?.env?.NODE_ENV !== 'test') {
- return;
- }
-
- if (!showInTimeline) {
- return;
- }
-
- registerSequence({
- type: mediaType,
- src,
- id: mediaId,
- duration,
- from: 0,
- parent: parentSequence?.id ?? null,
- displayName: finalDisplayName,
- rootId,
- volume: volumes,
- showInTimeline: true,
- nonce: nonce.get(),
- startMediaFrom: 0 - startsAt + (trimBefore ?? 0),
- doesVolumeChange,
- loopDisplay,
- playbackRate,
- stack,
- premountDisplay,
- postmountDisplay,
- controls: controls ?? null,
- effects: _experimentalEffects,
- });
-
- return () => {
- unregisterSequence(mediaId);
- };
- }, [
- controls,
- doesVolumeChange,
- duration,
- finalDisplayName,
- isStudio,
- loopDisplay,
- mediaId,
- mediaType,
- nonce,
- parentSequence?.id,
- playbackRate,
- postmountDisplay,
- premountDisplay,
- registerSequence,
- rootId,
- showInTimeline,
- src,
- stack,
- startsAt,
- unregisterSequence,
- volumes,
- trimBefore,
- _experimentalEffects,
- ]);
-
- return {
- id: mediaId,
- };
-};
diff --git a/packages/media/src/video/props.ts b/packages/media/src/video/props.ts
index 1da54cb950..732be26091 100644
--- a/packages/media/src/video/props.ts
+++ b/packages/media/src/video/props.ts
@@ -2,6 +2,7 @@ import type {
LogLevel,
LoopVolumeCurveBehavior,
OnVideoFrame,
+ SequenceProps,
VolumeProp,
} from 'remotion';
import type {EffectsProp} from 'remotion';
@@ -42,7 +43,6 @@ type OptionalVideoProps = {
className: string | undefined;
volume: VolumeProp;
loopVolumeCurveBehavior: LoopVolumeCurveBehavior;
- name: string | undefined;
onVideoFrame: OnVideoFrame | undefined;
playbackRate: number;
muted: boolean;
@@ -77,13 +77,5 @@ export type InnerVideoProps = MandatoryVideoProps &
export type VideoProps = MandatoryVideoProps &
Partial<OuterVideoProps> &
- Partial<OptionalVideoProps> & {
- /**
- * When set, `<Video>` applies timing via an inner `<Sequence layout="none">` that is hidden from the timeline (`showInTimeline={false}`) so the clip still appears once as media.
- */
- from?: number;
- /**
- * Bounds the clip in frames together with `from`. Defaults to `Infinity` like `<Sequence>`.
- */
- durationInFrames?: number;
- };
+ Partial<OptionalVideoProps> &
+ Pick<SequenceProps, 'durationInFrames' | 'from' | 'name'>;
diff --git a/packages/media/src/video/video-for-preview.tsx b/packages/media/src/video/video-for-preview.tsx
index 5e0b7a6772..1352a5412d 100644
--- a/packages/media/src/video/video-for-preview.tsx
+++ b/packages/media/src/video/video-for-preview.tsx
@@ -23,9 +23,7 @@ import {
import {getTimeInSeconds} from '../get-time-in-seconds';
import {MediaPlayer} from '../media-player';
import {type MediaOnError, callOnErrorAndResolve} from '../on-error';
-import {useLoopDisplay} from '../show-in-timeline';
import {useCommonEffects} from '../use-common-effects';
-import {useMediaInTimeline} from '../use-media-in-timeline';
import type {FallbackOffthreadVideoProps, VideoObjectFit} from './props';
import {cacheVideoFrame, getCachedVideoFrame} from './video-frame-cache';
import {warnAboutObjectFitInStyleOrClassName} from './warn-object-fit-css';
@@ -41,9 +39,7 @@ const {
warnAboutTooHighVolume,
usePreload,
SequenceContext,
- SequenceVisibilityToggleContext,
useEffectChainState,
- useMemoizedEffects,
} = Internals;
type VideoForPreviewProps = {
@@ -58,7 +54,6 @@ type VideoForPreviewProps = {
readonly onVideoFrame: undefined | ((frame: CanvasImageSource) => void);
readonly showInTimeline: boolean;
readonly loop: boolean;
- readonly name: string | undefined;
readonly trimAfter: number | undefined;
readonly trimBefore: number | undefined;
readonly stack: string | null;
@@ -70,13 +65,12 @@ type VideoForPreviewProps = {
readonly onError: MediaOnError | undefined;
readonly credentials: RequestCredentials | undefined;
readonly objectFit: VideoObjectFit;
+ readonly setMediaDurationInSeconds: (durationInSeconds: number) => void;
readonly _experimentalInitiallyDrawCachedFrame: boolean;
readonly _experimentalEffects: EffectsProp;
};
-type VideoForPreviewAssertedShowingProps = VideoForPreviewProps & {
- readonly controls: SequenceControls | undefined;
-};
+type VideoForPreviewAssertedShowingProps = VideoForPreviewProps;
const VideoForPreviewAssertedShowing: React.FC<
VideoForPreviewAssertedShowingProps
@@ -92,7 +86,6 @@ const VideoForPreviewAssertedShowing: React.FC<
onVideoFrame,
showInTimeline,
loop,
- name,
trimAfter,
trimBefore,
stack,
@@ -103,10 +96,10 @@ const VideoForPreviewAssertedShowing: React.FC<
headless,
onError,
credentials,
- controls,
objectFit: objectFitProp,
_experimentalInitiallyDrawCachedFrame,
_experimentalEffects,
+ setMediaDurationInSeconds,
}) => {
const src = usePreload(unpreloadedSrc);
@@ -130,11 +123,6 @@ const VideoForPreviewAssertedShowing: React.FC<
const [mediaMuted] = useMediaMutedState();
const [mediaVolume] = useMediaVolumeState();
- const [mediaDurationInSeconds, setMediaDurationInSeconds] = useState<
- number | null
- >(null);
-
- const {hidden} = useContext(SequenceVisibilityToggleContext);
const volumePropFrame = useFrameForVolumeProp(loopVolumeCurveBehavior);
@@ -153,7 +141,6 @@ const VideoForPreviewAssertedShowing: React.FC<
const effectChainState = useEffectChainState();
const experimentalEffectsRef = useRef(_experimentalEffects);
experimentalEffectsRef.current = _experimentalEffects;
- const memoizedEffects = useMemoizedEffects(_experimentalEffects.flat());
const effectChainStateRef = useRef(effectChainState);
effectChainStateRef.current = effectChainState;
const frameRef = useRef(frame);
@@ -167,34 +154,6 @@ const VideoForPreviewAssertedShowing: React.FC<
(parentSequence?.relativeFrom ?? 0)) /
videoConfig.fps;
- const loopDisplay = useLoopDisplay({
- loop,
- mediaDurationInSeconds,
- playbackRate,
- trimAfter,
- trimBefore,
- });
-
- const {id: timelineId} = useMediaInTimeline({
- volume,
- mediaType: 'video',
- src,
- playbackRate,
- displayName: name ?? null,
- stack,
- showInTimeline,
- premountDisplay: parentSequence?.premountDisplay ?? null,
- postmountDisplay: parentSequence?.postmountDisplay ?? null,
- loopDisplay,
- mediaVolume,
- trimAfter,
- trimBefore,
- controls,
- _experimentalEffects: memoizedEffects,
- });
-
- const isSequenceHidden = hidden[timelineId] ?? false;
-
const currentTime = frame / videoConfig.fps;
const currentTimeRef = useRef(currentTime);
@@ -209,8 +168,8 @@ const VideoForPreviewAssertedShowing: React.FC<
);
}
- const effectiveMuted =
- isSequenceHidden || muted || mediaMuted || userPreferredVolume <= 0;
+ // TODO: Consider Sequence hidden
+ const effectiveMuted = muted || mediaMuted || userPreferredVolume <= 0;
const isPlayerBuffering = Internals.useIsPlayerBuffering(buffering);
const initialPlaying = useRef(playing && !isPlayerBuffering);
@@ -387,6 +346,7 @@ const VideoForPreviewAssertedShowing: React.FC<
if (result.type === 'success') {
setMediaPlayerReady(true);
setMediaDurationInSeconds(result.durationInSeconds);
+
hasDrawnRealFrameRef.current = true;
}
})
@@ -455,6 +415,7 @@ const VideoForPreviewAssertedShowing: React.FC<
videoConfig.fps,
onError,
credentials,
+ setMediaDurationInSeconds,
]);
warnAboutObjectFitInStyleOrClassName({style, className, logLevel});
@@ -510,10 +471,10 @@ const VideoForPreviewAssertedShowing: React.FC<
const actualStyle: React.CSSProperties = useMemo(() => {
return {
...style,
- opacity: isSequenceHidden ? 0 : (style?.opacity ?? 1),
+ // TODO: Previousy we did hide on isSequenceHidden
objectFit: objectFitProp,
};
- }, [isSequenceHidden, objectFitProp, style]);
+ }, [objectFitProp, style]);
if (shouldFallbackToNativeVideo && !disallowFallbackToOffthreadVideo) {
// <Video> will fallback to <VideoForPreview> anyway
@@ -529,7 +490,7 @@ const VideoForPreviewAssertedShowing: React.FC<
trimBefore={trimBefore}
playbackRate={playbackRate}
loopVolumeCurveBehavior={loopVolumeCurveBehavior}
- name={name}
+ name={'<Html5Video> (fallback)'}
loop={loop}
showInTimeline={showInTimeline}
stack={stack ?? undefined}
@@ -591,7 +552,5 @@ export const VideoForPreview: React.FC<
return null;
}
- return (
- <VideoForPreviewAssertedShowing {...props} controls={props.controls} />
- );
+ return <VideoForPreviewAssertedShowing {...props} />;
};
diff --git a/packages/media/src/video/video-for-rendering.tsx b/packages/media/src/video/video-for-rendering.tsx
index bd789f3619..8ab3bf33cf 100644
--- a/packages/media/src/video/video-for-rendering.tsx
+++ b/packages/media/src/video/video-for-rendering.tsx
@@ -35,7 +35,6 @@ type InnerVideoProps = {
readonly src: string;
readonly logLevel: LogLevel;
readonly muted: boolean;
- readonly name: string | undefined;
readonly volume: VolumeProp;
readonly loopVolumeCurveBehavior: LoopVolumeCurveBehavior;
readonly onVideoFrame: OnVideoFrame | undefined;
@@ -75,7 +74,6 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
className,
fallbackOffthreadVideoProps,
audioStreamIndex,
- name,
disallowFallbackToOffthreadVideo,
stack,
toneFrequency,
@@ -422,12 +420,12 @@ export const VideoForRendering: React.FC<InnerVideoProps> = ({
delayRenderTimeoutInMilliseconds={
delayRenderTimeoutInMilliseconds ?? undefined
}
+ name={'Fallback to <OffthreadVideo>'}
style={styleWithObjectFit}
allowAmplificationDuringRender
transparent={fallbackOffthreadVideoProps?.transparent ?? true}
toneMapped={fallbackOffthreadVideoProps?.toneMapped ?? true}
audioStreamIndex={audioStreamIndex ?? 0}
- name={name}
className={className}
onVideoFrame={onVideoFrame}
volume={volumeProp}
diff --git a/packages/media/src/video/video.tsx b/packages/media/src/video/video.tsx
index 0624e279df..8e960fee30 100644
--- a/packages/media/src/video/video.tsx
+++ b/packages/media/src/video/video.tsx
@@ -1,6 +1,12 @@
+import {useMemo, useState} from 'react';
import React from 'react';
-import type {SequenceControls, SequenceSchema} from 'remotion';
+import {
+ useVideoConfig,
+ type SequenceControls,
+ type SequenceSchema,
+} from 'remotion';
import {Internals, Sequence, useRemotionEnvironment} from 'remotion';
+import {getLoopDisplay} from '../show-in-timeline';
import type {InnerVideoProps, VideoProps} from './props';
import {VideoForPreview} from './video-for-preview';
import {VideoForRendering} from './video-for-rendering';
@@ -57,7 +63,8 @@ const videoSchema = {
const InnerVideo: React.FC<
InnerVideoProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
+ readonly setMediaDurationInSeconds: (durationInSeconds: number) => void;
}
> = ({
src,
@@ -71,7 +78,6 @@ const InnerVideo: React.FC<
loop,
loopVolumeCurveBehavior,
muted,
- name,
onVideoFrame,
playbackRate,
style,
@@ -85,10 +91,11 @@ const InnerVideo: React.FC<
headless,
onError,
credentials,
- controls,
+ _experimentalControls: controls,
objectFit,
_experimentalInitiallyDrawCachedFrame,
_experimentalEffects,
+ setMediaDurationInSeconds,
}) => {
const environment = useRemotionEnvironment();
@@ -128,7 +135,6 @@ const InnerVideo: React.FC<
disallowFallbackToOffthreadVideo={
disallowFallbackToOffthreadVideo ?? false
}
- name={name}
fallbackOffthreadVideoProps={fallbackOffthreadVideoProps}
logLevel={logLevel}
loop={loop}
@@ -153,9 +159,9 @@ const InnerVideo: React.FC<
return (
<VideoForPreview
+ setMediaDurationInSeconds={setMediaDurationInSeconds}
audioStreamIndex={audioStreamIndex ?? 0}
className={className}
- name={name}
logLevel={logLevel}
loop={loop}
loopVolumeCurveBehavior={loopVolumeCurveBehavior}
@@ -187,7 +193,7 @@ const InnerVideo: React.FC<
const VideoInner: React.FC<
VideoProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
}
> = ({
src,
@@ -215,20 +221,86 @@ const VideoInner: React.FC<
headless,
onError,
credentials,
- controls,
+ _experimentalControls: controls,
objectFit,
_experimentalInitiallyDrawCachedFrame,
_experimentalEffects,
- from,
durationInFrames,
+ from,
}) => {
const fallbackLogLevel = Internals.useLogLevel();
+ const [mediaVolume] = Internals.useMediaVolumeState();
+ const mediaStartsAt = Internals.useMediaStartsAt();
+ const videoConfig = useVideoConfig();
+ const sequenceDurationInFrames = Math.min(
+ durationInFrames ?? Infinity,
+ Math.max(0, videoConfig.durationInFrames - (from ?? 0)),
+ );
+
+ const basicInfo = Internals.useBasicMediaInTimeline({
+ src,
+ volume,
+ playbackRate: playbackRate ?? 1,
+ trimBefore,
+ trimAfter,
+ sequenceDurationInFrames,
+ mediaType: 'video',
+ displayName: name ?? '<Video>',
+ mediaVolume,
+ mediaStartsAt,
+ loop: loop ?? false,
+ });
+
+ // TODO: Redundant with what we do in the Studio
+ const [mediaDurationInSeconds, setMediaDurationInSeconds] = useState<
+ number | null
+ >(null);
+
+ const loopDisplay = useMemo(
+ () =>
+ getLoopDisplay({
+ loop: loop ?? false,
+ mediaDurationInSeconds,
+ playbackRate: playbackRate ?? 1,
+ trimAfter,
+ trimBefore,
+ sequenceDurationInFrames,
+ compFps: videoConfig.fps,
+ }),
+ [
+ loop,
+ mediaDurationInSeconds,
+ playbackRate,
+ trimAfter,
+ trimBefore,
+ sequenceDurationInFrames,
+ videoConfig.fps,
+ ],
+ );
+
+ const isMedia = useMemo(
+ () => ({
+ type: 'video' as const,
+ data: basicInfo,
+ }),
+ [basicInfo],
+ );
+
+ if (sequenceDurationInFrames === 0) {
+ return null;
+ }
+
return (
<Sequence
layout="none"
from={from ?? 0}
- durationInFrames={durationInFrames ?? Infinity}
- showInTimeline={false}
+ durationInFrames={basicInfo.duration}
+ _remotionInternalStack={stack}
+ _remotionInternalIsMedia={isMedia}
+ name={name ?? '<Video>'}
+ _experimentalControls={controls}
+ _remotionInternalLoopDisplay={loopDisplay}
+ showInTimeline={showInTimeline ?? true}
>
<InnerVideo
audioStreamIndex={audioStreamIndex ?? 0}
@@ -245,7 +317,6 @@ const VideoInner: React.FC<
loop={loop ?? false}
loopVolumeCurveBehavior={loopVolumeCurveBehavior ?? 'repeat'}
muted={muted ?? false}
- name={name}
onVideoFrame={onVideoFrame}
playbackRate={playbackRate ?? 1}
showInTimeline={showInTimeline ?? true}
@@ -260,12 +331,13 @@ const VideoInner: React.FC<
headless={headless ?? false}
onError={onError}
credentials={credentials}
- controls={controls}
+ _experimentalControls={controls}
objectFit={objectFit ?? 'contain'}
_experimentalInitiallyDrawCachedFrame={
_experimentalInitiallyDrawCachedFrame ?? false
}
_experimentalEffects={_experimentalEffects ?? []}
+ setMediaDurationInSeconds={setMediaDurationInSeconds}
/>
</Sequence>
);
diff --git a/packages/starburst/src/Starburst.tsx b/packages/starburst/src/Starburst.tsx
index 47f587d089..c354615636 100644
--- a/packages/starburst/src/Starburst.tsx
+++ b/packages/starburst/src/Starburst.tsx
@@ -366,7 +366,7 @@ const starburstSchema = {
const StarburstInner: React.FC<
StarburstProps & {
- readonly controls: SequenceControls | undefined;
+ readonly _experimentalControls: SequenceControls | undefined;
}
> = ({
rays,
@@ -378,7 +378,7 @@ const StarburstInner: React.FC<
originOffsetY = 0,
durationInFrames,
style,
- controls,
+ _experimentalControls: controls,
...sequenceProps
}) => {
const {durationInFrames: videoDuration} = useVideoConfig();
@@ -434,7 +434,7 @@ const StarburstInner: React.FC<
<Sequence
durationInFrames={resolvedDuration}
name="<Starburst>"
- controls={controls}
+ _experimentalControls={controls}
{...sequenceProps}
style={style}
>
diff --git a/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx b/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx
index 91c2e2a072..899cbdd5ec 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandArrowButton.tsx
@@ -25,19 +25,22 @@ export const TimelineExpandArrowButton: React.FC<{
readonly isExpanded: boolean;
readonly onClick: () => void;
readonly label: string;
-}> = ({isExpanded, onClick, label}) => {
+ readonly hasExpandableContent: boolean;
+}> = ({isExpanded, onClick, label, hasExpandableContent}) => {
const style: React.CSSProperties = useMemo(() => {
return {
...arrowButton,
transform: isExpanded ? 'rotate(90deg)' : 'rotate(0deg)',
+ opacity: hasExpandableContent ? 1 : 0.2,
};
- }, [isExpanded]);
+ }, [isExpanded, hasExpandableContent]);
return (
<button
type="button"
style={style}
onClick={onClick}
+ disabled={!hasExpandableContent}
aria-expanded={isExpanded}
aria-label={`${isExpanded ? 'Collapse' : 'Expand'} ${label}`}
>
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index 095b68131c..e3af004928 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -127,6 +127,7 @@ export const TimelineExpandedSection: React.FC<{
isExpanded={isExpanded}
onClick={() => toggleTrack(node.id)}
label={`${node.label} section`}
+ hasExpandableContent
/>
<span style={rowLabel}>{node.label}</span>
</div>
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index ed915f3d7c..176033bfa7 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -6,16 +6,14 @@ import {TIMELINE_TRACK_SEPARATOR} from '../../helpers/colors';
import {
getTimelineLayerHeight,
TIMELINE_ITEM_BORDER_BOTTOM,
+ TIMELINE_LAYER_HEIGHT_AUDIO,
} from '../../helpers/timeline-layout';
import {callApi} from '../call-api';
import {ContextMenu} from '../ContextMenu';
import {ExpandedTracksContext} from '../ExpandedTracksProvider';
import type {ComboboxValue} from '../NewComposition/ComboBox';
import {showNotification} from '../Notifications/NotificationCenter';
-import {
- TimelineExpandArrowButton,
- TimelineExpandArrowSpacer,
-} from './TimelineExpandArrowButton';
+import {TimelineExpandArrowButton} from './TimelineExpandArrowButton';
import {TimelineExpandedSection} from './TimelineExpandedSection';
import {TimelineLayerEye} from './TimelineLayerEye';
import {TimelineStack} from './TimelineStack';
@@ -210,6 +208,14 @@ export const TimelineListItem: React.FC<{
return {
height:
getTimelineLayerHeight(sequence.type) + TIMELINE_ITEM_BORDER_BOTTOM,
+ borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,
+ };
+ }, [sequence.type]);
+
+ const inner: React.CSSProperties = useMemo(() => {
+ return {
+ // TODO: Not so small
+ height: TIMELINE_LAYER_HEIGHT_AUDIO,
color: 'white',
fontFamily: 'Arial, Helvetica, sans-serif',
display: 'flex',
@@ -218,38 +224,36 @@ export const TimelineListItem: React.FC<{
wordBreak: 'break-all',
textAlign: 'left',
paddingLeft: SPACING,
- borderBottom: `1px solid ${TIMELINE_TRACK_SEPARATOR}`,
};
- }, [sequence.type]);
+ }, []);
const hasExpandableContent =
Boolean(sequence.controls) || sequence.effects.length > 0;
const trackRow = (
<div style={outer}>
- <TimelineLayerEye
- type={sequence.type === 'audio' ? 'speaker' : 'eye'}
- hidden={isItemHidden}
- onInvoked={onToggleVisibility}
- />
- <div style={padder} />
- {sequence.parent && nestedDepth > 0 ? <div style={space} /> : null}
- {visualModeActive ? (
- hasExpandableContent ? (
+ <div style={inner}>
+ <TimelineLayerEye
+ type={sequence.type === 'audio' ? 'speaker' : 'eye'}
+ hidden={isItemHidden}
+ onInvoked={onToggleVisibility}
+ />
+ <div style={padder} />
+ {sequence.parent && nestedDepth > 0 ? <div style={space} /> : null}
+ {visualModeActive ? (
<TimelineExpandArrowButton
isExpanded={isExpanded}
onClick={onToggleExpand}
label="track properties"
+ hasExpandableContent={hasExpandableContent}
/>
- ) : (
- <TimelineExpandArrowSpacer />
- )
- ) : null}
- <TimelineStack
- sequence={sequence}
- isCompact={isCompact}
- originalLocation={originalLocation}
- />
+ ) : null}
+ <TimelineStack
+ sequence={sequence}
+ isCompact={isCompact}
+ originalLocation={originalLocation}
+ />
+ </div>
</div>
);
diff --git a/packages/studio/src/components/Timeline/TimelineStack/index.tsx b/packages/studio/src/components/Timeline/TimelineStack/index.tsx
index d5e162b7bd..8d5dba3deb 100644
--- a/packages/studio/src/components/Timeline/TimelineStack/index.tsx
+++ b/packages/studio/src/components/Timeline/TimelineStack/index.tsx
@@ -185,6 +185,8 @@ export const TimelineStack: React.FC<{
textOverflow: 'ellipsis',
overflow: 'hidden',
flexShrink: 100000,
+ userSelect: 'none',
+ WebkitUserSelect: 'none',
};
}, [opening, stackHovered, stackHoverable]);