🎥 Make videos programmatically with React
alright
Jonny Burger5e5dd2032ee9
diff --git a/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx b/packages/cli/src/editor/components/Timeline/TimelineSequence.tsxindex cbf4dc76f3..c4a36b167d 100644--- a/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx+++ b/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx@@ -1,6 +1,5 @@import React, {useMemo} from 'react';import {Internals, TSequence} from 'remotion';-import styled from 'styled-components';import {TIMELINE_LAYER_HEIGHT,TIMELINE_PADDING,@@ -10,16 +9,6 @@ import {AudioWaveform} from '../AudioWaveform';import {Thumbnail} from '../Thumbnail';import {sliderAreaRef} from './timeline-refs';-const Pre = styled.pre`- color: white;- font-family: Arial, Helvetica, sans-serif;- font-size: 12px;- margin-top: 0;- margin-bottom: 0;- padding: 5px;- position: absolute;-`;-const SEQUENCE_GRADIENT = 'linear-gradient(to bottom, #3697e1, #348AC7 60%)';const AUDIO_GRADIENT = 'linear-gradient(rgb(16 171 58), rgb(43 165 63) 60%)';@@ -43,15 +32,18 @@ export const TimelineSequence: React.FC<{const lastFrame = (video.durationInFrames ?? 1) - 1;const border = 1;- const width =- (s.duration === Infinity || lastFrame === 0- ? windowWidth - TIMELINE_PADDING * 2- : (spatialDuration / lastFrame) * (windowWidth - TIMELINE_PADDING * 2)) -- border;const marginLeft =lastFrame === 0? 0: (s.from / lastFrame) * (windowWidth - TIMELINE_PADDING * 2);+ const negativeLeftMargin = Math.min(0, marginLeft);+ const width =+ (s.duration === Infinity || lastFrame === 0+ ? windowWidth - TIMELINE_PADDING * 2+ : (spatialDuration / lastFrame) * (windowWidth - TIMELINE_PADDING * 2)) -+ border ++ negativeLeftMargin;+const style: React.CSSProperties = useMemo(() => {return {background: s.type === 'audio' ? AUDIO_GRADIENT : SEQUENCE_GRADIENT,@@ -60,7 +52,7 @@ export const TimelineSequence: React.FC<{position: 'absolute',height: TIMELINE_LAYER_HEIGHT,marginTop: 1,- marginLeft,+ marginLeft: Math.max(0, marginLeft),width,color: 'white',overflow: 'hidden',diff --git a/packages/core/src/audio/AudioForRendering.tsx b/packages/core/src/audio/AudioForRendering.tsxindex 9251614f21..b96f2e7399 100644--- a/packages/core/src/audio/AudioForRendering.tsx+++ b/packages/core/src/audio/AudioForRendering.tsx@@ -1,6 +1,7 @@import React, {useContext, useEffect, useMemo} from 'react';import {CompositionManager} from '../CompositionManager';import {random} from '../random';+import {SequenceContext} from '../sequencing';import {useAbsoluteCurrentFrame, useCurrentFrame} from '../use-frame';import {validateMediaProps} from '../validate-media-props';import {RemotionAudioProps} from './props';@@ -8,6 +9,7 @@ import {RemotionAudioProps} from './props';export const AudioForRendering: React.FC<RemotionAudioProps> = (props) => {const absoluteFrame = useAbsoluteCurrentFrame();const sequenceFrame = useCurrentFrame();+ const sequenceContext = useContext(SequenceContext);const {registerAsset, unregisterAsset} = useContext(CompositionManager);validateMediaProps(props, 'Audio');@@ -15,8 +17,11 @@ export const AudioForRendering: React.FC<RemotionAudioProps> = (props) => {// Generate a string that's as unique as possible for this asset// but at the same time the same on all threadsconst id = useMemo(- () => `audio-${random(props.src ?? '')}-muted:${props.muted}`,- [props.muted, props.src]+ () =>+ `audio-${random(props.src ?? '')}-${sequenceContext?.from}-${+ sequenceContext?.durationInFrames+ }-muted:${props.muted}`,+ [props.muted, props.src, sequenceContext]);useEffect(() => {diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsxindex 3ade249b14..cf424162c5 100644--- a/packages/core/src/video/VideoForRendering.tsx+++ b/packages/core/src/video/VideoForRendering.tsx@@ -4,6 +4,7 @@ import {FEATURE_FLAG_V2_BREAKING_CHANGES} from '../feature-flags';import {isApproximatelyTheSame} from '../is-approximately-the-same';import {random} from '../random';import {continueRender, delayRender} from '../ready-manager';+import {SequenceContext} from '../sequencing';import {useCurrentFrame} from '../use-frame';import {useUnsafeVideoConfig} from '../use-unsafe-video-config';import {validateMediaProps} from '../validate-media-props';@@ -16,6 +17,8 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = ({const frame = useCurrentFrame();const videoConfig = useUnsafeVideoConfig();const videoRef = useRef<HTMLVideoElement>(null);+ const sequenceContext = useContext(SequenceContext);+const {registerAsset, unregisterAsset} = useContext(CompositionManager);validateMediaProps(props, 'Video');@@ -23,8 +26,16 @@ export const VideoForRendering: React.FC<RemotionVideoProps> = ({// Generate a string that's as unique as possible for this asset// but at the same time the same on all threadsconst id = useMemo(- () => `audio-${random(props.src ?? '')}-muted:${props.muted}`,- [props.muted, props.src]+ () =>+ `audio-${random(props.src ?? '')}-${sequenceContext?.from}-${+ sequenceContext?.durationInFrames+ }-muted:${props.muted}`,+ [+ props.muted,+ props.src,+ sequenceContext?.durationInFrames,+ sequenceContext?.from,+ ]);if (!videoConfig) {