🎥 Make videos programmatically with React
@remotion/studio: Reuse SSR modal for read-only CLI copy
Cursor Agentc9e971acf846
diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsxindex 9370b6f604..834f5dc5c4 100644--- a/packages/studio/src/components/Modals.tsx+++ b/packages/studio/src/components/Modals.tsx@@ -8,7 +8,6 @@ import {DuplicateComposition} from './NewComposition/DuplicateComposition';import {RenameComposition} from './NewComposition/RenameComposition';import {OverrideInputPropsModal} from './OverrideInputProps';import QuickSwitcher from './QuickSwitcher/QuickSwitcher';-import {ReadOnlyRenderCommandModal} from './RenderModal/ReadOnlyRenderCommandModal';import {RenderStatusModal} from './RenderModal/RenderStatusModal';import {RenderModalWithLoader} from './RenderModal/ServerRenderModal';import {WebRenderModalWithLoader} from './RenderModal/WebRenderModal';@@ -43,86 +42,78 @@ export const Modals: React.FC<{{modalContextType && modalContextType.type === 'web-render' && (<WebRenderModalWithLoader {...modalContextType} />)}- {modalContextType && modalContextType.type === 'render-command' && (- <ReadOnlyRenderCommandModal command={modalContextType.command} />- )}{modalContextType &&- canRender &&- modalContextType.type === 'server-render' && (- <RenderModalWithLoader- initialFrame={modalContextType.initialFrame}- initialDarkMode={modalContextType.initialDarkMode}- compositionId={modalContextType.compositionId}- initialVideoImageFormat={modalContextType.initialVideoImageFormat}- initialJpegQuality={modalContextType.initialJpegQuality}- initialScale={modalContextType.initialScale}- initialLogLevel={modalContextType.initialLogLevel}- initialOffthreadVideoCacheSizeInBytes={- modalContextType.initialOffthreadVideoCacheSizeInBytes- }- initialOffthreadVideoThreads={- modalContextType.initialOffthreadVideoThreads- }- initialMediaCacheSizeInBytes={- modalContextType.initialMediaCacheSizeInBytes- }- initialConcurrency={modalContextType.initialConcurrency}- maxConcurrency={modalContextType.maxConcurrency}- minConcurrency={modalContextType.minConcurrency}- initialStillImageFormat={modalContextType.initialStillImageFormat}- initialMuted={modalContextType.initialMuted}- initialEnforceAudioTrack={modalContextType.initialEnforceAudioTrack}- initialProResProfile={modalContextType.initialProResProfile}- initialx264Preset={modalContextType.initialx264Preset}- initialPixelFormat={modalContextType.initialPixelFormat}- initialAudioBitrate={modalContextType.initialAudioBitrate}- initialVideoBitrate={modalContextType.initialVideoBitrate}- initialEveryNthFrame={modalContextType.initialEveryNthFrame}- initialNumberOfGifLoops={modalContextType.initialNumberOfGifLoops}- initialDelayRenderTimeout={- modalContextType.initialDelayRenderTimeout- }- initialEnvVariables={modalContextType.initialEnvVariables}- initialDisableWebSecurity={- modalContextType.initialDisableWebSecurity- }- initialGl={modalContextType.initialOpenGlRenderer}- initialHeadless={modalContextType.initialHeadless}- initialIgnoreCertificateErrors={- modalContextType.initialIgnoreCertificateErrors- }- initialEncodingBufferSize={- modalContextType.initialEncodingBufferSize- }- initialEncodingMaxRate={modalContextType.initialEncodingMaxRate}- initialUserAgent={modalContextType.initialUserAgent}- initialColorSpace={modalContextType.initialColorSpace}- initialMultiProcessOnLinux={- modalContextType.initialMultiProcessOnLinux- }- initialRepro={modalContextType.initialRepro}- initialBeep={modalContextType.initialBeep}- initialForSeamlessAacConcatenation={- modalContextType.initialForSeamlessAacConcatenation- }- defaultProps={modalContextType.defaultProps}- inFrameMark={modalContextType.inFrameMark}- outFrameMark={modalContextType.outFrameMark}- defaultConfigurationAudioCodec={- modalContextType.defaultConfigurationAudioCodec- }- defaultConfigurationVideoCodec={- modalContextType.defaultConfigurationVideoCodec- }- renderTypeOfLastRender={modalContextType.renderTypeOfLastRender}- defaultMetadata={modalContextType.defaulMetadata}- initialHardwareAcceleration={- modalContextType.initialHardwareAcceleration- }- initialChromeMode={modalContextType.initialChromeMode}- renderDefaults={modalContextType.renderDefaults}- />- )}+ modalContextType.type === 'server-render' &&+ (canRender || modalContextType.readOnlyStudio) ? (+ <RenderModalWithLoader+ readOnlyStudio={modalContextType.readOnlyStudio ?? false}+ initialFrame={modalContextType.initialFrame}+ initialDarkMode={modalContextType.initialDarkMode}+ compositionId={modalContextType.compositionId}+ initialVideoImageFormat={modalContextType.initialVideoImageFormat}+ initialJpegQuality={modalContextType.initialJpegQuality}+ initialScale={modalContextType.initialScale}+ initialLogLevel={modalContextType.initialLogLevel}+ initialOffthreadVideoCacheSizeInBytes={+ modalContextType.initialOffthreadVideoCacheSizeInBytes+ }+ initialOffthreadVideoThreads={+ modalContextType.initialOffthreadVideoThreads+ }+ initialMediaCacheSizeInBytes={+ modalContextType.initialMediaCacheSizeInBytes+ }+ initialConcurrency={modalContextType.initialConcurrency}+ maxConcurrency={modalContextType.maxConcurrency}+ minConcurrency={modalContextType.minConcurrency}+ initialStillImageFormat={modalContextType.initialStillImageFormat}+ initialMuted={modalContextType.initialMuted}+ initialEnforceAudioTrack={modalContextType.initialEnforceAudioTrack}+ initialProResProfile={modalContextType.initialProResProfile}+ initialx264Preset={modalContextType.initialx264Preset}+ initialPixelFormat={modalContextType.initialPixelFormat}+ initialAudioBitrate={modalContextType.initialAudioBitrate}+ initialVideoBitrate={modalContextType.initialVideoBitrate}+ initialEveryNthFrame={modalContextType.initialEveryNthFrame}+ initialNumberOfGifLoops={modalContextType.initialNumberOfGifLoops}+ initialDelayRenderTimeout={modalContextType.initialDelayRenderTimeout}+ initialEnvVariables={modalContextType.initialEnvVariables}+ initialDisableWebSecurity={modalContextType.initialDisableWebSecurity}+ initialGl={modalContextType.initialOpenGlRenderer}+ initialHeadless={modalContextType.initialHeadless}+ initialIgnoreCertificateErrors={+ modalContextType.initialIgnoreCertificateErrors+ }+ initialEncodingBufferSize={modalContextType.initialEncodingBufferSize}+ initialEncodingMaxRate={modalContextType.initialEncodingMaxRate}+ initialUserAgent={modalContextType.initialUserAgent}+ initialColorSpace={modalContextType.initialColorSpace}+ initialMultiProcessOnLinux={+ modalContextType.initialMultiProcessOnLinux+ }+ initialRepro={modalContextType.initialRepro}+ initialBeep={modalContextType.initialBeep}+ initialForSeamlessAacConcatenation={+ modalContextType.initialForSeamlessAacConcatenation+ }+ defaultProps={modalContextType.defaultProps}+ inFrameMark={modalContextType.inFrameMark}+ outFrameMark={modalContextType.outFrameMark}+ defaultConfigurationAudioCodec={+ modalContextType.defaultConfigurationAudioCodec+ }+ defaultConfigurationVideoCodec={+ modalContextType.defaultConfigurationVideoCodec+ }+ renderTypeOfLastRender={modalContextType.renderTypeOfLastRender}+ defaultMetadata={modalContextType.defaulMetadata}+ initialHardwareAcceleration={+ modalContextType.initialHardwareAcceleration+ }+ initialChromeMode={modalContextType.initialChromeMode}+ renderDefaults={modalContextType.renderDefaults}+ />+ ) : null}{modalContextType && modalContextType.type === 'render-progress' && (<RenderStatusModal jobId={modalContextType.jobId} />diff --git a/packages/studio/src/components/RenderButton.tsx b/packages/studio/src/components/RenderButton.tsxindex c236c75d4d..f4c2d3f384 100644--- a/packages/studio/src/components/RenderButton.tsx+++ b/packages/studio/src/components/RenderButton.tsx@@ -18,8 +18,6 @@ import {INPUT_BACKGROUND,INPUT_BORDER_COLOR_UNHOVERED,} from '../helpers/colors';-import {useIsStill} from '../helpers/is-current-selected-still';-import {makeRenderCommand} from '../helpers/make-render-command';import {SHOW_BROWSER_RENDERING} from '../helpers/show-browser-rendering';import {areKeyboardShortcutsDisabled} from '../helpers/use-keybinding';import {CaretDown} from '../icons/caret';@@ -225,74 +223,79 @@ export const RenderButton: React.FC<{readonly readOnlyStudio: boolean}> = ({const video = Internals.useVideo();const getCurrentFrame = PlayerInternals.useFrameImperative();- const isStill = useIsStill();const {props} = useContext(Internals.EditorPropsContext);- const openServerRenderModal = useCallback(() => {- if (!video) {- return null;- }+ const openServerRenderModal = useCallback(+ (copyCommandOnly: boolean) => {+ if (!video) {+ return null;+ }- const defaults = window.remotion_renderDefaults;+ const defaults = window.remotion_renderDefaults;- if (!defaults) {- throw new TypeError('Expected defaults');- }+ if (!defaults) {+ throw new TypeError('Expected defaults');+ }- setSelectedModal({- type: 'server-render',- compositionId: video.id,- initialFrame: getCurrentFrame(),- initialStillImageFormat: defaults.stillImageFormat,- initialVideoImageFormat: null,- initialJpegQuality: defaults.jpegQuality,- initialScale: window.remotion_renderDefaults?.scale ?? 1,- initialLogLevel: defaults.logLevel as LogLevel,- initialConcurrency: defaults.concurrency,- maxConcurrency: defaults.maxConcurrency,- minConcurrency: defaults.minConcurrency,- initialMuted: defaults.muted,- initialEnforceAudioTrack: defaults.enforceAudioTrack,- initialProResProfile:- defaults.proResProfile as _InternalTypes['ProResProfile'],- initialx264Preset: defaults.x264Preset as X264Preset,- initialPixelFormat: null,- initialAudioBitrate: defaults.audioBitrate,- initialVideoBitrate: defaults.videoBitrate,- initialEveryNthFrame: defaults.everyNthFrame,- initialNumberOfGifLoops: defaults.numberOfGifLoops,- initialDelayRenderTimeout: defaults.delayRenderTimeout,- defaultConfigurationAudioCodec: defaults.audioCodec as AudioCodec | null,- initialEnvVariables: window.process.env as Record<string, string>,- initialDisableWebSecurity: defaults.disableWebSecurity,- initialDarkMode: defaults.darkMode,- initialOpenGlRenderer: defaults.openGlRenderer as OpenGlRenderer | null,- initialHeadless: defaults.headless,- initialIgnoreCertificateErrors: defaults.ignoreCertificateErrors,- initialOffthreadVideoCacheSizeInBytes:- defaults.offthreadVideoCacheSizeInBytes,- initialOffthreadVideoThreads: defaults.offthreadVideoThreads,- defaultProps: props[video.id] ?? video.defaultProps,- inFrameMark: inFrame,- outFrameMark: outFrame,- initialColorSpace: defaults.colorSpace as ColorSpace,- initialMultiProcessOnLinux: defaults.multiProcessOnLinux,- defaultConfigurationVideoCodec: defaults.codec as Codec,- initialEncodingBufferSize: defaults.encodingBufferSize,- initialEncodingMaxRate: defaults.encodingMaxRate,- initialUserAgent: defaults.userAgent,- initialBeep: defaults.beepOnFinish,- initialRepro: defaults.repro,- initialForSeamlessAacConcatenation: defaults.forSeamlessAacConcatenation,- renderTypeOfLastRender: null,- defaulMetadata: defaults.metadata,- initialHardwareAcceleration: defaults.hardwareAcceleration,- initialChromeMode: defaults.chromeMode,- initialMediaCacheSizeInBytes: defaults.mediaCacheSizeInBytes,- renderDefaults: defaults,- });- }, [video, setSelectedModal, getCurrentFrame, props, inFrame, outFrame]);+ setSelectedModal({+ type: 'server-render',+ readOnlyStudio: copyCommandOnly,+ compositionId: video.id,+ initialFrame: getCurrentFrame(),+ initialStillImageFormat: defaults.stillImageFormat,+ initialVideoImageFormat: null,+ initialJpegQuality: defaults.jpegQuality,+ initialScale: window.remotion_renderDefaults?.scale ?? 1,+ initialLogLevel: defaults.logLevel as LogLevel,+ initialConcurrency: defaults.concurrency,+ maxConcurrency: defaults.maxConcurrency,+ minConcurrency: defaults.minConcurrency,+ initialMuted: defaults.muted,+ initialEnforceAudioTrack: defaults.enforceAudioTrack,+ initialProResProfile:+ defaults.proResProfile as _InternalTypes['ProResProfile'],+ initialx264Preset: defaults.x264Preset as X264Preset,+ initialPixelFormat: null,+ initialAudioBitrate: defaults.audioBitrate,+ initialVideoBitrate: defaults.videoBitrate,+ initialEveryNthFrame: defaults.everyNthFrame,+ initialNumberOfGifLoops: defaults.numberOfGifLoops,+ initialDelayRenderTimeout: defaults.delayRenderTimeout,+ defaultConfigurationAudioCodec:+ defaults.audioCodec as AudioCodec | null,+ initialEnvVariables: window.process.env as Record<string, string>,+ initialDisableWebSecurity: defaults.disableWebSecurity,+ initialDarkMode: defaults.darkMode,+ initialOpenGlRenderer: defaults.openGlRenderer as OpenGlRenderer | null,+ initialHeadless: defaults.headless,+ initialIgnoreCertificateErrors: defaults.ignoreCertificateErrors,+ initialOffthreadVideoCacheSizeInBytes:+ defaults.offthreadVideoCacheSizeInBytes,+ initialOffthreadVideoThreads: defaults.offthreadVideoThreads,+ defaultProps: props[video.id] ?? video.defaultProps,+ inFrameMark: inFrame,+ outFrameMark: outFrame,+ initialColorSpace: defaults.colorSpace as ColorSpace,+ initialMultiProcessOnLinux: defaults.multiProcessOnLinux,+ defaultConfigurationVideoCodec: defaults.codec as Codec,+ initialEncodingBufferSize: defaults.encodingBufferSize,+ initialEncodingMaxRate: defaults.encodingMaxRate,+ initialUserAgent: defaults.userAgent,+ initialBeep: defaults.beepOnFinish,+ initialRepro: defaults.repro,+ initialForSeamlessAacConcatenation:+ defaults.forSeamlessAacConcatenation,+ renderTypeOfLastRender: null,+ defaulMetadata: defaults.metadata,+ initialHardwareAcceleration: defaults.hardwareAcceleration,+ initialChromeMode: defaults.chromeMode,+ initialMediaCacheSizeInBytes: defaults.mediaCacheSizeInBytes,+ renderDefaults: defaults,+ });+ },+ [video, setSelectedModal, getCurrentFrame, props, inFrame, outFrame],+ );const openClientRenderModal = useCallback(() => {if (!video) {@@ -332,62 +335,18 @@ export const RenderButton: React.FC<{readonly readOnlyStudio: boolean}> = ({});}, [video, setSelectedModal, getCurrentFrame, props, inFrame, outFrame]);- const openReadOnlyRenderCommandModal = useCallback(() => {- if (!video) {- return;- }-- const defaults = window.remotion_renderDefaults;- if (!defaults) {- throw new TypeError('Expected defaults');- }-- const inputProps = (props[video.id] ?? video.defaultProps ?? {}) as Record<- string,- unknown- >;-- setSelectedModal({- type: 'render-command',- command: makeRenderCommand({- commandType: isStill ? 'still' : 'render',- packageManager: window.remotion_packageManager,- serveUrl: window.location.href,- compositionId: video.id,- inputProps,- renderDefaults: defaults,- inFrameMark: inFrame,- outFrameMark: outFrame,- frame: getCurrentFrame(),- }),- });- }, [- getCurrentFrame,- inFrame,- isStill,- outFrame,- props,- setSelectedModal,- video,- ]);-const onClick = useCallback(() => {if (renderType === 'render-command') {- openReadOnlyRenderCommandModal();+ openServerRenderModal(true);return;}if (!SHOW_BROWSER_RENDERING || renderType === 'server-render') {- openServerRenderModal();+ openServerRenderModal(false);} else {openClientRenderModal();}- }, [- renderType,- openReadOnlyRenderCommandModal,- openServerRenderModal,- openClientRenderModal,- ]);+ }, [renderType, openServerRenderModal, openClientRenderModal]);const onHideDropdown = useCallback(() => {setDropdownOpened(false);@@ -405,18 +364,14 @@ export const RenderButton: React.FC<{readonly readOnlyStudio: boolean}> = ({setDropdownOpened(false);if (newType === 'server-render') {- openServerRenderModal();+ openServerRenderModal(false);} else if (newType === 'render-command') {- openReadOnlyRenderCommandModal();+ openServerRenderModal(true);} else {openClientRenderModal();}},- [- openClientRenderModal,- openReadOnlyRenderCommandModal,- openServerRenderModal,- ],+ [openClientRenderModal, openServerRenderModal],);const dropdownValues: ComboboxValue[] = useMemo(() => {if (readOnlyStudio) {@@ -552,7 +507,7 @@ export const RenderButton: React.FC<{readonly readOnlyStudio: boolean}> = ({style={{display: 'none'}}id="render-modal-button-server"disabled={!canServerRender}- onClick={openServerRenderModal}+ onClick={() => openServerRenderModal(false)}type="button"/>{' '}<buttondiff --git a/packages/studio/src/components/RenderModal/ReadOnlyRenderCommandModal.tsx b/packages/studio/src/components/RenderModal/ReadOnlyRenderCommandModal.tsxdeleted file mode 100644index af90e363c2..0000000000--- a/packages/studio/src/components/RenderModal/ReadOnlyRenderCommandModal.tsx+++ /dev/null@@ -1,60 +0,0 @@-import React from 'react';-import {SELECTED_BACKGROUND} from '../../helpers/colors';-import {CopyButton} from '../CopyButton';-import {Flex, Row, Spacing} from '../layout';-import {ModalHeader} from '../ModalHeader';-import {DismissableModal} from '../NewComposition/DismissableModal';--const container: React.CSSProperties = {- padding: 20,- paddingTop: 0,- maxWidth: 760,-};--const text: React.CSSProperties = {- fontSize: 14,- lineHeight: 1.5,-};--const title: React.CSSProperties = {- ...text,- paddingTop: 14,- paddingBottom: 10,-};--const code: React.CSSProperties = {- background: SELECTED_BACKGROUND,- padding: '12px 10px',- fontSize: 14,- marginTop: 10,- marginBottom: 10,- whiteSpace: 'pre-wrap',- wordBreak: 'break-word',-};--export const ReadOnlyRenderCommandModal: React.FC<{- readonly command: string;-}> = ({command}) => {- return (- <DismissableModal>- <ModalHeader title="Render from CLI" />- <div style={container}>- <div style={title}>- The deployed Studio is read-only. Copy this command and run it on your- machine to render with the current props and settings.- </div>- <Row align="center">- <Flex>- <pre style={code}>{command}</pre>- </Flex>- <Spacing x={1} />- <CopyButton- textToCopy={command}- label="Copy"- labelWhenCopied="Copied!"- />- </Row>- </div>- </DismissableModal>- );-};diff --git a/packages/studio/src/components/RenderModal/ServerRenderModal.tsx b/packages/studio/src/components/RenderModal/ServerRenderModal.tsxindex 3853f1e1b7..0c2c862d01 100644--- a/packages/studio/src/components/RenderModal/ServerRenderModal.tsx+++ b/packages/studio/src/components/RenderModal/ServerRenderModal.tsx@@ -34,6 +34,8 @@ import {envVariablesArrayToObject,envVariablesObjectToArray,} from '../../helpers/convert-env-variables';+import {copyText} from '../../helpers/copy-text';+import {makeReadOnlyStudioRenderCommand} from '../../helpers/make-render-command';import {useRenderModalSections} from '../../helpers/render-modal-sections';import {useKeybinding} from '../../helpers/use-keybinding';import {AudioIcon} from '../../icons/audio';@@ -50,6 +52,7 @@ import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';import {ModalHeader} from '../ModalHeader';import type {ComboboxValue} from '../NewComposition/ComboBox';import {DismissableModal} from '../NewComposition/DismissableModal';+import {showNotification} from '../Notifications/NotificationCenter';import {optionsSidebarTabs,persistSelectedOptionsSidebarPanel,@@ -107,6 +110,14 @@ type State =const initialState: State = {type: 'idle'};+const readOnlyHint: React.CSSProperties = {+ fontSize: 12,+ color: 'rgba(255, 255, 255, 0.7)',+ paddingLeft: 16,+ paddingRight: 16,+ paddingTop: 10,+};+type Action =| {type: 'start';@@ -141,6 +152,7 @@ const reducer = (state: State, action: Action): State => {};type RenderModalProps = {+ readonly readOnlyStudio: boolean;readonly compositionId: string;readonly initialFrame: number;readonly initialVideoImageFormat: VideoImageFormat | null;@@ -195,6 +207,7 @@ const RenderModal: React.FC<readonly defaultConfigurationVideoCodec: Codec | null;}> = ({+ readOnlyStudio,initialFrame,initialVideoImageFormat,initialStillImageFormat,@@ -1159,9 +1172,84 @@ const RenderModal: React.FC<const {registerKeybinding} = useKeybinding();- const renderDisabled = state.type === 'load' || !outnameValidation.valid;+ const readOnlyRenderCommand = useMemo(() => {+ if (!readOnlyStudio) {+ return null;+ }++ return makeReadOnlyStudioRenderCommand({+ remotionVersion: window.remotion_version,+ locationHref: window.location.href,+ compositionId: resolvedComposition.id,+ renderMode,+ renderDefaults,+ durationInFrames: resolvedComposition.durationInFrames,+ frame,+ startFrame,+ endFrame,+ stillImageFormat,+ sequenceImageFormat,+ videoImageFormat,+ codec,+ muted,+ enforceAudioTrack,+ proResProfile,+ x264Preset,+ pixelFormat,+ colorSpace,+ scale,+ logLevel,+ delayRenderTimeout,+ hardwareAcceleration,+ chromeMode,+ inputProps,+ });+ }, [+ chromeMode,+ codec,+ colorSpace,+ delayRenderTimeout,+ endFrame,+ enforceAudioTrack,+ frame,+ hardwareAcceleration,+ inputProps,+ logLevel,+ muted,+ pixelFormat,+ proResProfile,+ readOnlyStudio,+ renderDefaults,+ renderMode,+ resolvedComposition.durationInFrames,+ resolvedComposition.id,+ scale,+ sequenceImageFormat,+ startFrame,+ stillImageFormat,+ videoImageFormat,+ x264Preset,+ ]);+ const [commandCopiedAt, setCommandCopiedAt] = useState<number | null>(null);+ const renderDisabled =+ !outnameValidation.valid || (!readOnlyStudio && state.type === 'load');const trigger = useCallback(() => {+ if (readOnlyStudio) {+ if (!readOnlyRenderCommand) {+ return;+ }++ copyText(readOnlyRenderCommand)+ .then(() => {+ setCommandCopiedAt(Date.now());+ })+ .catch((err) => {+ showNotification(`Could not copy: ${err.message}`, 2000);+ });+ return;+ }+if (renderMode === 'still') {onClickStill();} else if (renderMode === 'sequence') {@@ -1169,7 +1257,25 @@ const RenderModal: React.FC<} else {onClickVideo();}- }, [renderMode, onClickStill, onClickSequence, onClickVideo]);+ }, [+ onClickSequence,+ onClickStill,+ onClickVideo,+ readOnlyRenderCommand,+ readOnlyStudio,+ renderMode,+ ]);++ useEffect(() => {+ if (commandCopiedAt === null) {+ return;+ }++ const timeout = setTimeout(() => {+ setCommandCopiedAt(null);+ }, 2000);+ return () => clearTimeout(timeout);+ }, [commandCopiedAt]);useEffect(() => {if (renderDisabled) {@@ -1224,10 +1330,24 @@ const RenderModal: React.FC<backgroundColor: outnameValidation.valid ? BLUE : BLUE_DISABLED,}}>- {state.type === 'idle' ? `Render ${renderMode}` : 'Rendering...'}+ {readOnlyStudio+ ? commandCopiedAt+ ? 'Copied command!'+ : 'Copy command'+ : state.type === 'idle'+ ? `Render ${renderMode}`+ : 'Rendering...'}<ShortcutHint keyToPress="↵" cmdOrCtrl /></Button></div>+ {readOnlyStudio ? (+ <div style={readOnlyHint}>+ Copies a command pinned to your Studio version using{' '}+ <code>{`npx remotion@${window.remotion_version}`}</code>. If{' '}+ <code>@remotion/cli</code> is not installed locally, <code>npx</code>{' '}+ will download the matching version.+ </div>+ ) : null}<div style={horizontalLayout}><div style={leftSidebar}>{shownTabs.includes('general') ? (@@ -1403,7 +1523,7 @@ const RenderModal: React.FC<propsEditType="input-props"saving={saving}setSaving={setSaving}- readOnlyStudio={false}+ readOnlyStudio={readOnlyStudio}/>) : (<RenderModalAdvanceddiff --git a/packages/studio/src/helpers/make-render-command.ts b/packages/studio/src/helpers/make-render-command.tsindex 2643261545..1ffcb6ba3a 100644--- a/packages/studio/src/helpers/make-render-command.ts+++ b/packages/studio/src/helpers/make-render-command.ts@@ -1,25 +1,8 @@import {BrowserSafeApis} from '@remotion/renderer/client';-import type {PackageManager, RenderDefaults} from '@remotion/studio-shared';+import type {RenderDefaults} from '@remotion/studio-shared';+import type {_InternalTypes} from 'remotion';-type CommandType = 'render' | 'still';--export const getRemotionCommandPrefix = (- packageManager: PackageManager | 'unknown',-) => {- switch (packageManager) {- case 'bun':- return 'bunx remotion';- case 'pnpm':- return 'pnpm exec remotion';- case 'yarn':- return 'yarn remotion';- case 'npm':- case 'unknown':- return 'npx remotion';- default:- return 'npx remotion';- }-};+type RenderMode = 'still' | 'video' | 'audio' | 'sequence';const shellQuote = (value: string) => {return `'${value.replace(/'/g, "'\\''")}'`;@@ -43,262 +26,211 @@ const addBooleanFlag = (flags: string[], flag: string, value: boolean) => {}};-const getRenderFlags = ({- renderDefaults,- inFrameMark,- outFrameMark,+export const makeVersionedRemotionCommandPrefix = (version: string) => {+ return version.trim() === '' ? 'npx remotion' : `npx remotion@${version}`;+};++export const normalizeServeUrlForRenderCommand = ({+ locationHref,+ compositionId,}: {- renderDefaults: RenderDefaults;- inFrameMark: number | null;- outFrameMark: number | null;+ locationHref: string;+ compositionId: string;}) => {- const {options} = BrowserSafeApis;- const flags: string[] = [];-- if (- inFrameMark !== null &&- outFrameMark !== null &&- inFrameMark <= outFrameMark- ) {- addFlagWithValue(- flags,- options.framesOption.cliFlag,- `${inFrameMark}-${outFrameMark}`,- );+ const parsed = new URL(locationHref);+ parsed.hash = '';+ parsed.search = '';++ const suffix = `/${compositionId}`;+ if (parsed.pathname === suffix) {+ parsed.pathname = '/';+ } else if (parsed.pathname.endsWith(suffix)) {+ const basePath = parsed.pathname.slice(0, -suffix.length);+ parsed.pathname = basePath === '' ? '/' : basePath;}- addFlagWithValue(- flags,- options.videoCodecOption.cliFlag,- renderDefaults.codec,- );- addFlagWithValue(- flags,- options.audioCodecOption.cliFlag,- renderDefaults.audioCodec,- );- addFlagWithValue(- flags,- options.videoImageFormatOption.cliFlag,- renderDefaults.videoImageFormat,- );- addFlagWithValue(- flags,- options.concurrencyOption.cliFlag,- renderDefaults.concurrency,- );- addFlagWithValue(- flags,- options.pixelFormatOption.cliFlag,- renderDefaults.pixelFormat,- );- addFlagWithValue(- flags,- options.videoBitrateOption.cliFlag,- renderDefaults.videoBitrate,- );- addFlagWithValue(- flags,- options.audioBitrateOption.cliFlag,- renderDefaults.audioBitrate,- );- addFlagWithValue(- flags,- options.encodingBufferSizeOption.cliFlag,- renderDefaults.encodingBufferSize,- );- addFlagWithValue(- flags,- options.encodingMaxRateOption.cliFlag,- renderDefaults.encodingMaxRate,- );- addFlagWithValue(- flags,- options.everyNthFrameOption.cliFlag,- renderDefaults.everyNthFrame,- );- addFlagWithValue(- flags,- options.numberOfGifLoopsOption.cliFlag,- renderDefaults.numberOfGifLoops,- );- addFlagWithValue(- flags,- options.proResProfileOption.cliFlag,- renderDefaults.proResProfile,- );- addFlagWithValue(- flags,- options.x264Option.cliFlag,- renderDefaults.x264Preset,- );- addFlagWithValue(- flags,- options.colorSpaceOption.cliFlag,- renderDefaults.colorSpace,- );- addBooleanFlag(flags, options.mutedOption.cliFlag, renderDefaults.muted);- addBooleanFlag(- flags,- options.enforceAudioOption.cliFlag,- renderDefaults.enforceAudioTrack,- );- addBooleanFlag(flags, options.reproOption.cliFlag, renderDefaults.repro);- addBooleanFlag(- flags,- options.forSeamlessAacConcatenationOption.cliFlag,- renderDefaults.forSeamlessAacConcatenation,- );- addBooleanFlag(- flags,- options.enableMultiprocessOnLinuxOption.cliFlag,- renderDefaults.multiProcessOnLinux,- );+ if (parsed.pathname !== '/' && parsed.pathname.endsWith('/')) {+ parsed.pathname = parsed.pathname.slice(0, -1);+ }- return flags;+ return `${parsed.origin}${parsed.pathname === '/' ? '' : parsed.pathname}`;};-const getStillFlags = ({+export const makeReadOnlyStudioRenderCommand = ({+ remotionVersion,+ locationHref,+ compositionId,+ renderMode,renderDefaults,+ durationInFrames,frame,+ startFrame,+ endFrame,+ stillImageFormat,+ sequenceImageFormat,+ videoImageFormat,+ codec,+ muted,+ enforceAudioTrack,+ proResProfile,+ x264Preset,+ pixelFormat,+ colorSpace,+ scale,+ logLevel,+ delayRenderTimeout,+ hardwareAcceleration,+ chromeMode,+ inputProps,}: {+ remotionVersion: string;+ locationHref: string;+ compositionId: string;+ renderMode: RenderMode;renderDefaults: RenderDefaults;+ durationInFrames: number;frame: number;+ startFrame: number;+ endFrame: number;+ stillImageFormat: string;+ sequenceImageFormat: string;+ videoImageFormat: string;+ codec: string;+ muted: boolean;+ enforceAudioTrack: boolean;+ proResProfile: _InternalTypes['ProResProfile'] | null;+ x264Preset: string | null;+ pixelFormat: string;+ colorSpace: string;+ scale: number;+ logLevel: string;+ delayRenderTimeout: number;+ hardwareAcceleration: string;+ chromeMode: string;+ inputProps: Record<string, unknown>;}) => {+ const serveUrl = normalizeServeUrlForRenderCommand({+ locationHref,+ compositionId,+ });+ const commandType = renderMode === 'still' ? 'still' : 'render';+ const command = makeVersionedRemotionCommandPrefix(remotionVersion);const {options} = BrowserSafeApis;const flags: string[] = [];- addFlagWithValue(flags, options.stillFrameOption.cliFlag, frame);- addFlagWithValue(- flags,- options.stillImageFormatOption.cliFlag,- renderDefaults.stillImageFormat,- );+ if (scale !== renderDefaults.scale) {+ addFlagWithValue(flags, options.scaleOption.cliFlag, scale);+ }- return flags;-};+ if (logLevel !== renderDefaults.logLevel) {+ addFlagWithValue(flags, options.logLevelOption.cliFlag, logLevel);+ }-const getSharedFlags = ({renderDefaults}: {renderDefaults: RenderDefaults}) => {- const {options} = BrowserSafeApis;- const flags: string[] = [];+ if (delayRenderTimeout !== renderDefaults.delayRenderTimeout) {+ addFlagWithValue(+ flags,+ options.delayRenderTimeoutInMillisecondsOption.cliFlag,+ delayRenderTimeout,+ );+ }- addFlagWithValue(- flags,- options.jpegQualityOption.cliFlag,- renderDefaults.jpegQuality,- );- addFlagWithValue(flags, options.scaleOption.cliFlag, renderDefaults.scale);- addFlagWithValue(- flags,- options.logLevelOption.cliFlag,- renderDefaults.logLevel,- );- addFlagWithValue(- flags,- options.delayRenderTimeoutInMillisecondsOption.cliFlag,- renderDefaults.delayRenderTimeout,- );- addFlagWithValue(- flags,- options.glOption.cliFlag,- renderDefaults.openGlRenderer,- );- addFlagWithValue(- flags,- options.userAgentOption.cliFlag,- renderDefaults.userAgent,- );- addFlagWithValue(- flags,- options.chromeModeOption.cliFlag,- renderDefaults.chromeMode,- );- addFlagWithValue(- flags,- options.hardwareAccelerationOption.cliFlag,- renderDefaults.hardwareAcceleration,- );- addFlagWithValue(- flags,- options.mediaCacheSizeInBytesOption.cliFlag,- renderDefaults.mediaCacheSizeInBytes,- );- addFlagWithValue(- flags,- options.offthreadVideoCacheSizeInBytesOption.cliFlag,- renderDefaults.offthreadVideoCacheSizeInBytes,- );- addFlagWithValue(- flags,- options.offthreadVideoThreadsOption.cliFlag,- renderDefaults.offthreadVideoThreads,- );- addFlagWithValue(- flags,- options.licenseKeyOption.cliFlag,- renderDefaults.publicLicenseKey,- );- addBooleanFlag(- flags,- options.disableWebSecurityOption.cliFlag,- renderDefaults.disableWebSecurity,- );- addBooleanFlag(- flags,- options.ignoreCertificateErrorsOption.cliFlag,- renderDefaults.ignoreCertificateErrors,- );- addBooleanFlag(- flags,- options.darkModeOption.cliFlag,- renderDefaults.darkMode,- );- if (!renderDefaults.headless) {- addBooleanFlag(flags, options.headlessOption.cliFlag, true);+ if (hardwareAcceleration !== renderDefaults.hardwareAcceleration) {+ addFlagWithValue(+ flags,+ options.hardwareAccelerationOption.cliFlag,+ hardwareAcceleration,+ );}- return flags;-};+ if (chromeMode !== renderDefaults.chromeMode) {+ addFlagWithValue(flags, options.chromeModeOption.cliFlag, chromeMode);+ }-export const makeRenderCommand = ({- commandType,- packageManager,- serveUrl,- compositionId,- inputProps,- renderDefaults,- inFrameMark,- outFrameMark,- frame,-}: {- commandType: CommandType;- packageManager: PackageManager | 'unknown';- serveUrl: string;- compositionId: string;- inputProps: Record<string, unknown>;- renderDefaults: RenderDefaults;- inFrameMark: number | null;- outFrameMark: number | null;- frame: number;-}) => {- const command = getRemotionCommandPrefix(packageManager);- const sharedFlags = getSharedFlags({renderDefaults});- const renderSpecificFlags =- commandType === 'render'- ? getRenderFlags({renderDefaults, inFrameMark, outFrameMark})- : getStillFlags({renderDefaults, frame});- const inputPropsString = JSON.stringify(inputProps);- const propsFlag = `--${BrowserSafeApis.options.propsOption.cliFlag}=${shellQuote(- inputPropsString,- )}`;+ if (renderMode === 'still') {+ if (frame !== 0) {+ addFlagWithValue(flags, options.stillFrameOption.cliFlag, frame);+ }++ if (stillImageFormat !== renderDefaults.stillImageFormat) {+ addFlagWithValue(+ flags,+ options.stillImageFormatOption.cliFlag,+ stillImageFormat,+ );+ }+ } else {+ if (renderMode === 'sequence') {+ addBooleanFlag(flags, options.imageSequenceOption.cliFlag, true);+ if (sequenceImageFormat !== 'jpeg') {+ addFlagWithValue(+ flags,+ options.videoImageFormatOption.cliFlag,+ sequenceImageFormat,+ );+ }+ } else if (videoImageFormat !== renderDefaults.videoImageFormat) {+ addFlagWithValue(+ flags,+ options.videoImageFormatOption.cliFlag,+ videoImageFormat,+ );+ }++ if (codec !== renderDefaults.codec) {+ addFlagWithValue(flags, options.videoCodecOption.cliFlag, codec);+ }++ if (startFrame !== 0 || endFrame !== durationInFrames - 1) {+ addFlagWithValue(+ flags,+ options.framesOption.cliFlag,+ `${startFrame}-${endFrame}`,+ );+ }++ if (muted && muted !== renderDefaults.muted) {+ addBooleanFlag(flags, options.mutedOption.cliFlag, true);+ }++ if (+ enforceAudioTrack &&+ enforceAudioTrack !== renderDefaults.enforceAudioTrack+ ) {+ addBooleanFlag(flags, options.enforceAudioOption.cliFlag, true);+ }++ if (pixelFormat !== renderDefaults.pixelFormat) {+ addFlagWithValue(flags, options.pixelFormatOption.cliFlag, pixelFormat);+ }++ if (colorSpace !== renderDefaults.colorSpace) {+ addFlagWithValue(flags, options.colorSpaceOption.cliFlag, colorSpace);+ }++ if (proResProfile && proResProfile !== renderDefaults.proResProfile) {+ addFlagWithValue(+ flags,+ options.proResProfileOption.cliFlag,+ proResProfile,+ );+ }++ if (x264Preset && x264Preset !== renderDefaults.x264Preset) {+ addFlagWithValue(flags, options.x264Option.cliFlag, x264Preset);+ }+ }++ addFlagWithValue(+ flags,+ options.propsOption.cliFlag,+ JSON.stringify(inputProps),+ );return [command,commandType,shellQuote(serveUrl),shellQuote(compositionId),- ...sharedFlags,- ...renderSpecificFlags,- propsFlag,+ ...flags,].join(' ');};diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.tsindex f5f894b945..2348a71a02 100644--- a/packages/studio/src/state/modals.ts+++ b/packages/studio/src/state/modals.ts@@ -55,6 +55,7 @@ export type WebRenderModalState = {export type RenderModalState = {type: 'server-render';+ readOnlyStudio?: boolean;compositionId: string;initialFrame: number;initialStillImageFormat: StillImageFormat;@@ -140,10 +141,6 @@ export type ModalState =type: 'quick-switcher';mode: QuickSwitcherMode;invocationTimestamp: number;- }- | {- type: 'render-command';- command: string;};export type ModalContextType = {diff --git a/packages/studio/src/test/make-render-command.test.ts b/packages/studio/src/test/make-render-command.test.tsindex 7aa1d02327..90b6062ae8 100644--- a/packages/studio/src/test/make-render-command.test.ts+++ b/packages/studio/src/test/make-render-command.test.ts@@ -1,8 +1,9 @@import {expect, test} from 'bun:test';import type {RenderDefaults} from '@remotion/studio-shared';import {- getRemotionCommandPrefix,- makeRenderCommand,+ makeReadOnlyStudioRenderCommand,+ makeVersionedRemotionCommandPrefix,+ normalizeServeUrlForRenderCommand,} from '../helpers/make-render-command';const getDefaults = (): RenderDefaults => {@@ -51,68 +52,104 @@ const getDefaults = (): RenderDefaults => {};};-test('Should map package manager to command prefix', () => {- expect(getRemotionCommandPrefix('bun')).toBe('bunx remotion');- expect(getRemotionCommandPrefix('pnpm')).toBe('pnpm exec remotion');- expect(getRemotionCommandPrefix('yarn')).toBe('yarn remotion');- expect(getRemotionCommandPrefix('npm')).toBe('npx remotion');- expect(getRemotionCommandPrefix('unknown')).toBe('npx remotion');+test('Should pin remotion version in command prefix', () => {+ expect(makeVersionedRemotionCommandPrefix('4.0.431')).toBe(+ 'npx [email protected]',+ );+ expect(makeVersionedRemotionCommandPrefix('')).toBe('npx remotion');+});++test('Should normalize serve URL by stripping selected composition', () => {+ expect(+ normalizeServeUrlForRenderCommand({+ locationHref: 'http://localhost:63389/?/still-helloworld',+ compositionId: 'still-helloworld',+ }),+ ).toBe('http://localhost:63389');+ expect(+ normalizeServeUrlForRenderCommand({+ locationHref: 'https://example.com/base-path/still-helloworld',+ compositionId: 'still-helloworld',+ }),+ ).toBe('https://example.com/base-path');});-test('Should generate a render command with escaped props and flags', () => {- const command = makeRenderCommand({- commandType: 'render',- packageManager: 'npm',- serveUrl: 'https://example.com/hello',- compositionId: 'MyComp',+test('Should generate concise read-only render command and omit concurrency', () => {+ const command = makeReadOnlyStudioRenderCommand({+ remotionVersion: '4.0.431',+ locationHref: 'https://example.com/dynamic-length',+ compositionId: 'dynamic-length',+ renderMode: 'video',+ renderDefaults: getDefaults(),+ durationInFrames: 200,+ frame: 0,+ startFrame: 10,+ endFrame: 80,+ stillImageFormat: 'png',+ sequenceImageFormat: 'png',+ videoImageFormat: 'jpeg',+ codec: 'h264',+ muted: true,+ enforceAudioTrack: false,+ proResProfile: null,+ x264Preset: 'medium',+ pixelFormat: 'yuv420p',+ colorSpace: 'default',+ scale: 1,+ logLevel: 'info',+ delayRenderTimeout: 30000,+ hardwareAcceleration: 'if-possible',+ chromeMode: 'headless-shell',inputProps: {title: "It's me",},- renderDefaults: {- ...getDefaults(),- scale: 2,- muted: true,- openGlRenderer: 'angle',- headless: false,- disableWebSecurity: true,- },- inFrameMark: 5,- outFrameMark: 25,- frame: 0,});expect(command).toContain(- "npx remotion render 'https://example.com/hello' 'MyComp'",+ "npx [email protected] render 'https://example.com' 'dynamic-length'",);- expect(command).toContain("--frames='5-25'");+ expect(command).toContain("--frames='10-80'");expect(command).toContain('--muted');- expect(command).toContain('--disable-web-security');- expect(command).toContain('--disable-headless');- expect(command).toContain("--scale='2'");- expect(command).toContain("--gl='angle'");expect(command).toContain("It'\\''s me");+ expect(command).not.toContain('--concurrency=');});-test('Should generate a still command without render-only flags', () => {- const command = makeRenderCommand({- commandType: 'still',- packageManager: 'bun',- serveUrl: 'https://example.com/still',+test('Should generate still command and omit default flags', () => {+ const command = makeReadOnlyStudioRenderCommand({+ remotionVersion: '4.0.431',+ locationHref: 'https://example.com/still',compositionId: 'StillComp',+ renderMode: 'still',+ renderDefaults: getDefaults(),+ durationInFrames: 120,+ frame: 12,+ startFrame: 0,+ endFrame: 119,+ stillImageFormat: 'png',+ sequenceImageFormat: 'png',+ videoImageFormat: 'jpeg',+ codec: 'h264',+ muted: false,+ enforceAudioTrack: false,+ proResProfile: null,+ x264Preset: 'medium',+ pixelFormat: 'yuv420p',+ colorSpace: 'default',+ scale: 1,+ logLevel: 'info',+ delayRenderTimeout: 30000,+ hardwareAcceleration: 'if-possible',+ chromeMode: 'headless-shell',inputProps: {message: 'Hello',},- renderDefaults: getDefaults(),- inFrameMark: 10,- outFrameMark: 20,- frame: 12,});expect(command).toContain(- "bunx remotion still 'https://example.com/still' 'StillComp'",+ "npx [email protected] still 'https://example.com/still' 'StillComp'",);expect(command).toContain("--frame='12'");- expect(command).toContain("--image-format='png'");+ expect(command).not.toContain("--image-format='png'");expect(command).not.toContain('--codec=');expect(command).not.toContain('--frames=');});