Skip to content

πŸŽ₯ Make videos programmatically with React

make CLI flag work (also fix typos)

Jonny Burger4e19bc3a859e
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index b5d955c418..98697c79bd 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -257,7 +257,7 @@ export const benchmarkCommand = async (
// Not needed for benchmark
gitSource: null,
bufferStateDelayInMilliseconds: null,
- maxTimlineTracks: null,
+ maxTimelineTracks: null,
});
registerCleanupJob(() => cleanupBundle());
diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.ts
index 15fdddda79..e65ac6d82e 100644
--- a/packages/cli/src/bundle.ts
+++ b/packages/cli/src/bundle.ts
@@ -121,7 +121,7 @@ export const bundleCommand = async (
outDir: outputPath,
gitSource,
bufferStateDelayInMilliseconds: null,
- maxTimlineTracks: null,
+ maxTimelineTracks: null,
});
Log.info(
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index 697012f2dc..e9593ab0a1 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -94,7 +94,7 @@ export const listCompositionsCommand = async (
// Not needed for compositions
gitSource: null,
bufferStateDelayInMilliseconds: null,
- maxTimlineTracks: null,
+ maxTimelineTracks: null,
});
registerCleanupJob(() => cleanupBundle());
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 751f1b40e8..19602436b4 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -247,7 +247,7 @@ export const renderVideoFlow = async ({
// Not needed for render
gitSource: null,
bufferStateDelayInMilliseconds: null,
- maxTimlineTracks: null,
+ maxTimelineTracks: null,
},
);
@@ -354,7 +354,12 @@ export const renderVideoFlow = async ({
overwrite,
logLevel,
);
+ const absoluteSeparateAudioTo =
+ separateAudioTo === null ? null : path.resolve(separateAudioTo);
const exists = existsSync(absoluteOutputFile);
+ const audioExists = absoluteSeparateAudioTo
+ ? existsSync(absoluteSeparateAudioTo)
+ : false;
const realFrameRange = RenderInternals.getRealFrameRange(
config.durationInFrames,
@@ -522,7 +527,7 @@ export const renderVideoFlow = async ({
updateRenderProgress({newline: true, printToConsole: true});
},
binariesDirectory,
- separateAudioTo,
+ separateAudioTo: absoluteSeparateAudioTo,
forSeamlessAacConcatenation,
});
@@ -531,6 +536,13 @@ export const renderVideoFlow = async ({
chalk.blue(`${exists ? 'β—‹' : '+'} ${absoluteOutputFile}`),
);
+ if (absoluteSeparateAudioTo) {
+ Log.info(
+ {indent, logLevel},
+ chalk.blue(`${audioExists ? 'β—‹' : '+'} ${absoluteSeparateAudioTo}`),
+ );
+ }
+
Log.verbose({indent, logLevel}, `Slowest frames:`);
slowestFrames.forEach(({frame, time}) => {
Log.verbose({indent, logLevel}, ` Frame ${frame} (${time.toFixed(3)}ms)`);
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index a1eb2320eb..000a29dcd0 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -176,7 +176,7 @@ export const renderStillFlow = async ({
// Not needed for still
gitSource: null,
bufferStateDelayInMilliseconds: null,
- maxTimlineTracks: null,
+ maxTimelineTracks: null,
},
);
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 2f9f68501a..54a410f200 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -157,12 +157,9 @@ export const render = async (
commandLine: parsedCli,
}).value;
- const separateAudioTo = separateAudioOption.getValue(
- {
- commandLine: parsedCli,
- },
- remotionRoot,
- ).value;
+ const separateAudioTo = separateAudioOption.getValue({
+ commandLine: parsedCli,
+ }).value;
const chromiumOptions: ChromiumOptions = {
disableWebSecurity,
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
index bcd1a5b118..ac668e5c24 100644
--- a/packages/cli/src/setup-cache.ts
+++ b/packages/cli/src/setup-cache.ts
@@ -28,7 +28,7 @@ export const bundleOnCliOrTakeServeUrl = async ({
outDir,
gitSource,
bufferStateDelayInMilliseconds,
- maxTimlineTracks,
+ maxTimelineTracks,
}: {
fullPath: string;
remotionRoot: string;
@@ -47,7 +47,7 @@ export const bundleOnCliOrTakeServeUrl = async ({
outDir: string | null;
gitSource: GitSource | null;
bufferStateDelayInMilliseconds: number | null;
- maxTimlineTracks: number | null;
+ maxTimelineTracks: number | null;
}): Promise<{
urlOrBundle: string;
cleanup: () => void;
@@ -84,7 +84,7 @@ export const bundleOnCliOrTakeServeUrl = async ({
outDir,
gitSource,
bufferStateDelayInMilliseconds,
- maxTimlineTracks,
+ maxTimelineTracks,
});
return {
@@ -107,7 +107,7 @@ export const bundleOnCli = async ({
quietFlag,
outDir,
gitSource,
- maxTimlineTracks,
+ maxTimelineTracks,
bufferStateDelayInMilliseconds,
}: {
fullPath: string;
@@ -126,7 +126,7 @@ export const bundleOnCli = async ({
quietFlag: boolean;
outDir: string | null;
gitSource: GitSource | null;
- maxTimlineTracks: number | null;
+ maxTimelineTracks: number | null;
bufferStateDelayInMilliseconds: number | null;
}) => {
const shouldCache = ConfigInternals.getWebpackCaching();
@@ -202,7 +202,7 @@ export const bundleOnCli = async ({
options,
resolvedRemotionRoot: remotionRoot,
bufferStateDelayInMilliseconds,
- maxTimelineTracks: maxTimlineTracks,
+ maxTimelineTracks: maxTimelineTracks,
});
const cacheExistedBefore = BundlerInternals.cacheExists(
remotionRoot,
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index e15ca02e7b..64a5f57b49 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -23,7 +23,7 @@ import {overwriteOption} from './overwrite';
import {preferLosslessAudioOption} from './prefer-lossless';
import {reproOption} from './repro';
import {scaleOption} from './scale';
-import {separateAudioOption} from './separate-audio';
+import {separateAudioOption} from './separate-audio-to';
import {delayRenderTimeoutInMillisecondsOption} from './timeout';
import {videoBitrateOption} from './video-bitrate';
import {videoCodecOption} from './video-codec';
diff --git a/packages/renderer/src/options/options-map.ts b/packages/renderer/src/options/options-map.ts
index 1b9c51696c..5930caf91b 100644
--- a/packages/renderer/src/options/options-map.ts
+++ b/packages/renderer/src/options/options-map.ts
@@ -15,7 +15,7 @@ import {offthreadVideoCacheSizeInBytesOption} from './offthreadvideo-cache-size'
import {preferLosslessAudioOption} from './prefer-lossless';
import {reproOption} from './repro';
import {scaleOption} from './scale';
-import {separateAudioOption} from './separate-audio';
+import {separateAudioOption} from './separate-audio-to';
import {delayRenderTimeoutInMillisecondsOption} from './timeout';
import {videoBitrateOption} from './video-bitrate';
import {videoCodecOption} from './video-codec';
diff --git a/packages/renderer/src/options/separate-audio-to.tsx b/packages/renderer/src/options/separate-audio-to.tsx
new file mode 100644
index 0000000000..5ef9c1ee4b
--- /dev/null
+++ b/packages/renderer/src/options/separate-audio-to.tsx
@@ -0,0 +1,39 @@
+import type {AnyRemotionOption} from './option';
+
+const DEFAULT = null;
+
+const cliFlag = 'separate-audio-to';
+
+export const separateAudioOption = {
+ cliFlag,
+ description: () => {
+ return (
+ <>
+ If set, the audio will not be included in the main output but rendered
+ as a separate file at the location you pass. It is recommended to use an
+ absolute path. If a relative path is passed, it is relative to the
+ Remotion Root.
+ </>
+ );
+ },
+ docLink: 'https://remotion.dev/docs/renderer/render-media',
+ getValue: ({commandLine}) => {
+ if (commandLine[cliFlag]) {
+ return {
+ source: 'cli',
+ value: commandLine[cliFlag] as string,
+ };
+ }
+
+ return {
+ source: 'default',
+ value: DEFAULT,
+ };
+ },
+ name: 'Separate audio to',
+ setConfig: () => {
+ throw new Error('Not implemented');
+ },
+ ssrName: 'separateAudioTo',
+ type: 'string' as string | null,
+} satisfies AnyRemotionOption<string | null>;
diff --git a/packages/renderer/src/options/separate-audio.tsx b/packages/renderer/src/options/separate-audio.tsx
deleted file mode 100644
index e1e8e15e0b..0000000000
--- a/packages/renderer/src/options/separate-audio.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import path from 'node:path/win32';
-import type {AnyRemotionOption} from './option';
-
-const DEFAULT = null;
-
-let separateAudioTo: string | null = null;
-
-const cliFlag = '--separate-audio-to';
-
-export const separateAudioOption = {
- cliFlag,
- description: () => {
- return (
- <>
- If set, the audio will not be included in the main output but rendered
- as a separate file at the location you pass. The path is relative to the
- current working directory of the Remotion Root, or in the case of using
- the server-side rendering APIs, relative to the current working
- directory. It is recommended to use an absolute path.
- </>
- );
- },
- docLink: 'https://remotion.dev/docs/renderer/render-media',
- getValue: ({commandLine}, remotionRoot: string) => {
- if (commandLine[cliFlag]) {
- return {
- source: 'cli',
- value: path.resolve(commandLine[cliFlag] as string, remotionRoot),
- };
- }
-
- if (separateAudioTo !== DEFAULT) {
- return {
- source: 'config',
- value: path.resolve(separateAudioTo, remotionRoot),
- };
- }
-
- return {
- source: 'default',
- value: DEFAULT,
- };
- },
- name: 'Separate audio to',
- setConfig: (value) => {
- separateAudioTo = value;
- },
- ssrName: 'separateAudioTo',
- type: 'string' as string | null,
-} satisfies AnyRemotionOption<string | null>;
diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.ts
index 830556c2f4..02166d7f23 100644
--- a/packages/renderer/src/stitch-frames-to-video.ts
+++ b/packages/renderer/src/stitch-frames-to-video.ts
@@ -411,7 +411,8 @@ const innerStitchFramesToVideo = async (
);
}
- cpSync(audio, separateAudioTo);
+ const finalDestination = path.resolve(remotionRoot, separateAudioTo);
+ cpSync(audio, finalDestination);
rmSync(audio);
}
diff --git a/packages/studio-shared/src/api-requsts.ts b/packages/studio-shared/src/api-requests.ts
similarity index 99%
rename from packages/studio-shared/src/api-requsts.ts
rename to packages/studio-shared/src/api-requests.ts
index 0f7d49da1a..70f087ebca 100644
--- a/packages/studio-shared/src/api-requsts.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -75,6 +75,7 @@ type AddRenderRequestDynamicFields =
colorSpace: ColorSpace;
repro: boolean;
forSeamlessAacConcatenation: boolean;
+ separateAudioTo: string | null;
};
export type CancelRenderRequest = {
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index c6ea52cc68..3f1baca269 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -16,7 +16,7 @@ export {
UpdateAvailableResponse,
UpdateDefaultPropsRequest,
UpdateDefaultPropsResponse,
-} from './api-requsts';
+} from './api-requests';
export {DEFAULT_BUFFER_STATE_DELAY_IN_MILLISECONDS} from './default-buffer-state-delay-in-milliseconds';
export {EventSourceEvent} from './event-source-event';
export {formatBytes} from './format-bytes';
diff --git a/packages/studio/src/components/RenderModal/RenderModal.tsx b/packages/studio/src/components/RenderModal/RenderModal.tsx
index 03cfc47668..42e8bbbc73 100644
--- a/packages/studio/src/components/RenderModal/RenderModal.tsx
+++ b/packages/studio/src/components/RenderModal/RenderModal.tsx
@@ -333,6 +333,7 @@ const RenderModal: React.FC<
);
const [userSelectedAudioCodec, setUserSelectedAudioCodec] =
useState<AudioCodec | null>(() => initialAudioCodec);
+ const [separateAudioTo] = useState<string | null>(null);
const [envVariables, setEnvVariables] = useState<[string, string][]>(() =>
envVariablesObjectToArray(initialEnvVariables).filter(
@@ -822,6 +823,7 @@ const RenderModal: React.FC<
beepOnFinish,
repro,
forSeamlessAacConcatenation,
+ separateAudioTo,
})
.then(() => {
dispatchIfMounted({type: 'succeed'});
diff --git a/packages/studio/src/components/RenderQueue/actions.ts b/packages/studio/src/components/RenderQueue/actions.ts
index 570f43e58d..799bd666d3 100644
--- a/packages/studio/src/components/RenderQueue/actions.ts
+++ b/packages/studio/src/components/RenderQueue/actions.ts
@@ -211,6 +211,7 @@ export const addVideoRenderJob = ({
beepOnFinish,
repro,
forSeamlessAacConcatenation,
+ separateAudioTo,
}: {
compositionId: string;
outName: string;
@@ -246,6 +247,7 @@ export const addVideoRenderJob = ({
beepOnFinish: boolean;
repro: boolean;
forSeamlessAacConcatenation: boolean;
+ separateAudioTo: string | null;
}) => {
return callApi('/api/render', {
compositionId,
@@ -288,6 +290,7 @@ export const addVideoRenderJob = ({
beepOnFinish,
repro,
forSeamlessAacConcatenation,
+ separateAudioTo,
});
};