🎥 Make videos programmatically with React
show premounted in timelin
Jonny Burger9663d44520eb
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsxindex 9e35cf2761..98edf75ccb 100644--- a/packages/core/src/Sequence.tsx+++ b/packages/core/src/Sequence.tsx@@ -275,7 +275,7 @@ const PremountedSequenceRefForwardingFunction: React.ForwardRefRenderFunction<const active =frame < from &&- frame > from - premountFor &&+ frame >= from - premountFor &&!getRemotionEnvironment().isRendering;const style = useMemo(() => {@@ -299,7 +299,7 @@ const PremountedSequenceRefForwardingFunction: React.ForwardRefRenderFunction<name={finalName}from={from + (active ? -premountFor : 0)}style={style}- premountDisplay={premountFor}+ premountDisplay={active ? premountFor : undefined}{...otherProps}/></Freeze>diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsxindex 1562c2a72c..2b29e51fad 100644--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx@@ -50,7 +50,7 @@ const Inner: React.FC<{const isInRange = relativeFrame >= 0 && relativeFrame < s.duration;- const {marginLeft, width} = useMemo(() => {+ const {marginLeft, width, premountWidth} = useMemo(() => {return getTimelineSequenceLayout({durationInFrames: s.loopDisplay? s.loopDisplay.durationInFrames * s.loopDisplay.numberOfTimes@@ -60,6 +60,7 @@ const Inner: React.FC<{maxMediaDuration,video,windowWidth,+ premountDisplay: s.premountDisplay,});}, [maxMediaDuration, s, video, windowWidth]);@@ -85,6 +86,23 @@ const Inner: React.FC<{return (<div key={s.id} style={style} title={s.displayName}>+ {premountWidth ? (+ <div+ style={{+ width: premountWidth,+ height: '100%',+ background: `repeating-linear-gradient(+ -45deg,+ transparent,+ transparent 2px,+ rgba(255, 255, 255, 0.2) 2px,+ rgba(255, 255, 255, 0.2) 4px+ )`,+ position: 'absolute',+ }}+ />+ ) : null}+{s.type === 'audio' ? (<AudioWaveformsrc={s.src}@@ -101,6 +119,7 @@ const Inner: React.FC<{{s.loopDisplay === undefined ? null : (<LoopedTimelineIndicator loops={s.loopDisplay.numberOfTimes} />)}+{s.type !== 'audio' &&s.type !== 'video' &&s.loopDisplay === undefined &&@@ -113,7 +132,10 @@ const Inner: React.FC<{alignItems: 'center',}}>- <TimelineSequenceFrame roundedFrame={roundedFrame} />+ <TimelineSequenceFrame+ premountDisplay={premountWidth}+ roundedFrame={roundedFrame}+ /></div>) : null}</div>diff --git a/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsx b/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsxindex c4ae4f7469..9152f7b041 100644--- a/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsx@@ -9,6 +9,11 @@ const relativeFrameStyle: React.CSSProperties = {export const TimelineSequenceFrame: React.FC<{roundedFrame: number;-}> = ({roundedFrame}) => {- return <div style={relativeFrameStyle}>{roundedFrame}</div>;+ premountDisplay: number | null;+}> = ({roundedFrame, premountDisplay}) => {+ return (+ <div style={relativeFrameStyle}>+ {premountDisplay ? '0 (Premounted)' : roundedFrame}+ </div>+ );};diff --git a/packages/studio/src/helpers/get-timeline-sequence-layout.ts b/packages/studio/src/helpers/get-timeline-sequence-layout.tsindex a9fbddca49..365c343cf6 100644--- a/packages/studio/src/helpers/get-timeline-sequence-layout.ts+++ b/packages/studio/src/helpers/get-timeline-sequence-layout.ts@@ -32,6 +32,7 @@ export const getTimelineSequenceLayout = ({startFromMedia,video,windowWidth,+ premountDisplay,}: {durationInFrames: number;startFrom: number;@@ -39,10 +40,12 @@ export const getTimelineSequenceLayout = ({maxMediaDuration: number | null;video: VideoConfig;windowWidth: number;+ premountDisplay: number | null;}) => {const maxMediaSequenceDuration =(maxMediaDuration ?? Infinity) - startFromMedia;const lastFrame = (video.durationInFrames ?? 1) - 1;+let spatialDuration = Math.min(maxMediaSequenceDuration,durationInFrames - 1,@@ -71,16 +74,31 @@ export const getTimelineSequenceLayout = ({const nonNegativeMarginLeft = Math.min(marginLeft, 0);+ const width = Math.floor(+ getWidthOfTrack({+ durationInFrames,+ lastFrame,+ nonNegativeMarginLeft,+ spatialDuration,+ windowWidth,+ }),+ );++ const premountWidth = premountDisplay+ ? Math.floor(+ getWidthOfTrack({+ durationInFrames: premountDisplay,+ lastFrame,+ nonNegativeMarginLeft,+ spatialDuration: premountDisplay,+ windowWidth,+ }),+ )+ : null;+return {marginLeft: Math.round(Math.max(marginLeft, 0)),- width: Math.floor(- getWidthOfTrack({- durationInFrames,- lastFrame,- nonNegativeMarginLeft,- spatialDuration,- windowWidth,- }),- ),+ width,+ premountWidth,};};