🎥 Make videos programmatically with React
`@remotion/studio`: Apply frameRange for web renders
JonnyBurger5664fed1ac20
diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsxindex 44663e6fcc..e1ee446cab 100644--- a/packages/studio/src/components/Modals.tsx+++ b/packages/studio/src/components/Modals.tsx@@ -45,6 +45,8 @@ export const Modals: React.FC<{initialFrame={modalContextType.initialFrame}compositionId={modalContextType.compositionId}defaultProps={modalContextType.defaultProps}+ inFrameMark={modalContextType.inFrameMark}+ outFrameMark={modalContextType.outFrameMark}/>)}{modalContextType &&diff --git a/packages/studio/src/components/RenderModal/WebRenderModal.tsx b/packages/studio/src/components/RenderModal/WebRenderModal.tsxindex 965b67004f..342b5c7e5c 100644--- a/packages/studio/src/components/RenderModal/WebRenderModal.tsx+++ b/packages/studio/src/components/RenderModal/WebRenderModal.tsx@@ -47,6 +47,8 @@ type WebRenderModalProps = {readonly compositionId: string;readonly initialFrame: number;readonly defaultProps: Record<string, unknown>;+ readonly inFrameMark: number | null;+ readonly outFrameMark: number | null;};export type RenderType = 'still' | 'video';@@ -123,12 +125,13 @@ const validateOutnameForStill = ({// TODO: Filter out codecs that are not supported for the container// TODO: Add more containers// TODO: Shortcut: Shift + R-// TODO: Apply initial frame range// TODO: Apply defaultCodec// TODO: Apply defaultOutNameconst WebRenderModal: React.FC<WebRenderModalProps> = ({initialFrame,defaultProps,+ inFrameMark,+ outFrameMark,}) => {const context = useContext(ResolvedCompositionContext);if (!context) {@@ -162,12 +165,43 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({'no-preference' | 'prefer-hardware' | 'prefer-software'>('no-preference');const [keyframeIntervalInSeconds, setKeyframeIntervalInSeconds] = useState(5);- const [startFrame, setStartFrame] = useState<number | null>(null);- const [endFrame, setEndFrame] = useState<number | null>(null);+ const [startFrame, setStartFrame] = useState<number | null>(+ () => inFrameMark ?? null,+ );+ const [endFrame, setEndFrame] = useState<number | null>(+ () => outFrameMark ?? null,+ );const [renderProgress, setRenderProgress] =useState<RenderMediaOnWebProgress | null>(null);const [transparent, setTransparent] = useState(false);+ const finalEndFrame = useMemo(() => {+ if (endFrame === null) {+ return resolvedComposition.durationInFrames - 1;+ }++ return Math.max(+ 0,+ Math.min(resolvedComposition.durationInFrames - 1, endFrame),+ );+ }, [endFrame, resolvedComposition.durationInFrames]);++ const finalStartFrame = useMemo(() => {+ if (startFrame === null) {+ return 0;+ }++ return Math.max(0, Math.min(finalEndFrame, startFrame));+ }, [finalEndFrame, startFrame]);++ const frameRange = useMemo(() => {+ if (startFrame === null && endFrame === null) {+ return null;+ }++ return [finalStartFrame, finalEndFrame] as [number, number];+ }, [endFrame, finalEndFrame, finalStartFrame, startFrame]);+const [initialOutName] = useState(() => {return getDefaultOutLocation({compositionName: resolvedComposition.id,@@ -397,13 +431,7 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({videoBitrate,hardwareAcceleration,keyframeIntervalInSeconds,- frameRange:- startFrame !== null || endFrame !== null- ? ([- startFrame ?? 0,- endFrame ?? resolvedComposition.durationInFrames - 1,- ] as [number, number])- : null,+ frameRange,onProgress: (progress) => {setRenderProgress(progress);},@@ -436,8 +464,7 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({videoBitrate,hardwareAcceleration,keyframeIntervalInSeconds,- startFrame,- endFrame,+ frameRange,resolvedComposition.durationInFrames,resolvedComposition.width,resolvedComposition.height,@@ -470,10 +497,9 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({disabled={!outnameValidation.valid}>{renderProgress- ? `Rendering... ${renderProgress.renderedFrames}/${- endFrame ?? resolvedComposition.durationInFrames - 1- }`+ ? `Rendering... ${renderProgress.renderedFrames}/${finalEndFrame}`: `Render ${renderMode}`}+<ShortcutHint keyToPress="↵" cmdOrCtrl /></Button></div>@@ -536,9 +562,9 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({setContainerFormat={setContainerFormat}codec={codec}setCodec={setCodec}- startFrame={startFrame}+ startFrame={finalStartFrame}setStartFrame={setStartFrame}- endFrame={endFrame}+ endFrame={finalEndFrame}setEndFrame={setEndFrame}outName={outName}onOutNameChange={onOutNameChange}diff --git a/packages/studio/src/components/WebRender/TriggerWebRender.tsx b/packages/studio/src/components/WebRender/TriggerWebRender.tsxindex 3554877fcf..aaa92b1bca 100644--- a/packages/studio/src/components/WebRender/TriggerWebRender.tsx+++ b/packages/studio/src/components/WebRender/TriggerWebRender.tsx@@ -1,6 +1,7 @@import {PlayerInternals} from '@remotion/player';import {useCallback, useContext} from 'react';import {Internals} from 'remotion';+import {useTimelineInOutFramePosition} from '../../state/in-out';import {ModalsContext} from '../../state/modals';import {Button} from '../Button';@@ -18,6 +19,7 @@ const label: React.CSSProperties = {export const TriggerWebRender = () => {const video = Internals.useVideo();const getCurrentFrame = PlayerInternals.useFrameImperative();+ const {inFrame, outFrame} = useTimelineInOutFramePosition();const {setSelectedModal} = useContext(ModalsContext);@@ -33,8 +35,17 @@ export const TriggerWebRender = () => {initialFrame: frame,compositionId: video.id,defaultProps: video.defaultProps,+ inFrameMark: inFrame,+ outFrameMark: outFrame,});- }, [getCurrentFrame, setSelectedModal, video?.id, video?.defaultProps]);+ }, [+ getCurrentFrame,+ inFrame,+ outFrame,+ setSelectedModal,+ video?.defaultProps,+ video?.id,+ ]);if (!video) {return null;diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.tsindex e5b7a4fce1..4cdd026485 100644--- a/packages/studio/src/state/modals.ts+++ b/packages/studio/src/state/modals.ts@@ -25,6 +25,8 @@ export type WebRenderModalState = {initialFrame: number;compositionId: string;defaultProps: Record<string, unknown>;+ inFrameMark: number | null;+ outFrameMark: number | null;};export type RenderModalState = {