Skip to content

🎥 Make videos programmatically with React

fine tuning

Jonny Burger97ed229c4614
diff --git a/packages/cli/src/config/image-sequence-pattern.ts b/packages/cli/src/config/image-sequence-pattern.ts
deleted file mode 100644
index 1370d9185d..0000000000
--- a/packages/cli/src/config/image-sequence-pattern.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-let currentImageSequencePattern: string | undefined;
-
-export const setImageSequencePattern = (pattern: string | undefined) => {
- currentImageSequencePattern = pattern;
-};
-
-export const getImageSequencePattern = () => {
- return currentImageSequencePattern;
-};
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index a0e7608c54..e3908ef420 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -14,10 +14,6 @@ import {
setVideoImageFormat,
} from './image-format';
import {getShouldOutputImageSequence} from './image-sequence';
-import {
- getImageSequencePattern,
- setImageSequencePattern,
-} from './image-sequence-pattern';
import {getOutputLocation} from './output-location';
import {
defaultOverrideFunction,
@@ -129,6 +125,7 @@ const {
hardwareAccelerationOption,
audioLatencyHintOption,
enableCrossSiteIsolationOption,
+ imageSequencePatternOption,
} = BrowserSafeApis.options;
declare global {
@@ -683,7 +680,7 @@ export const Config: FlatConfig = {
setBinariesDirectory: binariesDirectoryOption.setConfig,
setPreferLosslessAudio: preferLosslessOption.setConfig,
setPublicPath: publicPathOption.setConfig,
- setImageSequencePattern,
+ setImageSequencePattern: imageSequencePatternOption.setConfig,
setHardwareAcceleration: hardwareAccelerationOption.setConfig,
setEnableCrossSiteIsolation: enableCrossSiteIsolationOption.setConfig,
};
@@ -725,5 +722,3 @@ export const ConfigInternals = {
getBufferStateDelayInMilliseconds,
getOutputCodecOrUndefined: BrowserSafeApis.getOutputCodecOrUndefined,
};
-
-export {getImageSequencePattern, setImageSequencePattern};
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index 2adbc53163..769d4f3d1f 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -115,10 +115,6 @@ export const parseCommandLine = () => {
Config.setPixelFormat(parsedCli['pixel-format']);
}
- if (parsedCli['image-sequence-pattern']) {
- Config.setImageSequencePattern(parsedCli['image-sequence-pattern']);
- }
-
if (parsedCli['browser-executable']) {
Config.setBrowserExecutable(parsedCli['browser-executable']);
}
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 158017d19e..12171613f8 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -116,6 +116,7 @@ export const renderVideoFlow = async ({
hardwareAcceleration,
chromeMode,
audioLatencyHint,
+ imageSequencePattern,
}: {
remotionRoot: string;
fullEntryPoint: string;
@@ -174,6 +175,7 @@ export const renderVideoFlow = async ({
hardwareAcceleration: HardwareAccelerationOption;
chromeMode: ChromeMode;
audioLatencyHint: AudioContextLatencyCategory | null;
+ imageSequencePattern: string | null;
}) => {
const isVerbose = RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose');
@@ -535,10 +537,10 @@ export const renderVideoFlow = async ({
onBrowserDownload,
onArtifact,
chromeMode,
- imageSequencePattern: parsedCli['image-sequence-pattern'],
+ imageSequencePattern,
});
- Log.info({indent, logLevel}, chalk.blue(`â–¶ ${absoluteOutputFile}`));
+ Log.info({indent, logLevel}, chalk.blue(`\nâ–¶ ${absoluteOutputFile}`));
return;
}
diff --git a/packages/cli/src/render-queue/process-video.ts b/packages/cli/src/render-queue/process-video.ts
index 71ec482ee1..d9fc0da622 100644
--- a/packages/cli/src/render-queue/process-video.ts
+++ b/packages/cli/src/render-queue/process-video.ts
@@ -101,5 +101,6 @@ export const processVideoJob = async ({
chromeMode: job.chromeMode,
offthreadVideoThreads: job.offthreadVideoThreads,
audioLatencyHint: null,
+ imageSequencePattern: null,
});
};
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 0a6e259cda..b0e494688e 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -41,6 +41,7 @@ const {
chromeModeOption,
offthreadVideoThreadsOption,
audioLatencyHintOption,
+ imageSequencePatternOption,
} = BrowserSafeApis.options;
export const render = async (
@@ -189,6 +190,9 @@ export const render = async (
const audioLatencyHint = audioLatencyHintOption.getValue({
commandLine: parsedCli,
}).value;
+ const imageSequencePattern = imageSequencePatternOption.getValue({
+ commandLine: parsedCli,
+ }).value;
await renderVideoFlow({
fullEntryPoint,
@@ -255,5 +259,6 @@ export const render = async (
chromeMode,
offthreadVideoThreads,
audioLatencyHint,
+ imageSequencePattern,
});
};
diff --git a/packages/docs/docs/renderer/render-frames.mdx b/packages/docs/docs/renderer/render-frames.mdx
index bb0160f0a4..b3d651b21d 100644
--- a/packages/docs/docs/renderer/render-frames.mdx
+++ b/packages/docs/docs/renderer/render-frames.mdx
@@ -102,7 +102,7 @@ A string pattern for naming the output image sequence files. You can use the fol
- `[frame]`: Will be replaced with the zero-padded frame number (e.g. 0001, 0002, ...)
- `[ext]`: Will be replaced with the image format extension (e.g. jpeg, png)
-Default: `element-%0[frame]d.[ext]`
+Default: `element-[frame].[ext]`
**Example:**
diff --git a/packages/renderer/src/get-frame-padded-index.ts b/packages/renderer/src/get-frame-padded-index.ts
index 00559c43b3..ef79951e22 100644
--- a/packages/renderer/src/get-frame-padded-index.ts
+++ b/packages/renderer/src/get-frame-padded-index.ts
@@ -26,7 +26,7 @@ export const getFrameOutputFileName = ({
countType,
lastFrame,
totalFrames,
- pattern,
+ imageSequencePattern,
}: {
index: number;
frame: number;
@@ -34,16 +34,16 @@ export const getFrameOutputFileName = ({
countType: CountType;
lastFrame: number;
totalFrames: number;
- pattern?: string;
+ imageSequencePattern: string | null;
}) => {
const filePadLength = getFilePadLength({lastFrame, countType, totalFrames});
const frameStr =
countType === 'actual-frames'
? String(frame).padStart(filePadLength, '0')
: String(index).padStart(filePadLength, '0');
- if (pattern) {
+ if (imageSequencePattern) {
return getFrameOutputFileNameFromPattern({
- pattern,
+ pattern: imageSequencePattern,
frame: frameStr,
ext: imageFormat,
});
diff --git a/packages/renderer/src/options/image-sequence-pattern.tsx b/packages/renderer/src/options/image-sequence-pattern.tsx
index 0fede668ac..a558da37c0 100644
--- a/packages/renderer/src/options/image-sequence-pattern.tsx
+++ b/packages/renderer/src/options/image-sequence-pattern.tsx
@@ -2,6 +2,8 @@ import type {AnyRemotionOption} from './option';
const cliFlag = 'image-sequence-pattern' as const;
+let currentImageSequencePattern: string | null = null;
+
// Option for --image-sequence-pattern
export const imageSequencePatternOption = {
name: 'Image Sequence Pattern',
@@ -16,9 +18,20 @@ export const imageSequencePatternOption = {
),
docLink: null,
type: 'string' as string | null,
- getValue: ({commandLine}) => ({
- value: commandLine[cliFlag] as string,
- source: 'cli',
- }),
- setConfig: () => {},
+ getValue: ({commandLine}) => {
+ if (currentImageSequencePattern !== null) {
+ return {
+ value: currentImageSequencePattern,
+ source: 'config',
+ };
+ }
+
+ return {
+ value: commandLine[cliFlag] as string,
+ source: 'cli',
+ };
+ },
+ setConfig: (pattern: string | null) => {
+ currentImageSequencePattern = pattern;
+ },
} satisfies AnyRemotionOption<string | null>;
diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsx
index 18c472b134..d7ad195b1b 100644
--- a/packages/renderer/src/options/index.tsx
+++ b/packages/renderer/src/options/index.tsx
@@ -19,6 +19,7 @@ import {forSeamlessAacConcatenationOption} from './for-seamless-aac-concatenatio
import {glOption} from './gl';
import {hardwareAccelerationOption} from './hardware-acceleration';
import {headlessOption} from './headless';
+import {imageSequencePatternOption} from './image-sequence-pattern';
import {jpegQualityOption} from './jpeg-quality';
import {audioLatencyHintOption} from './latency-hint';
import {logLevelOption} from './log-level';
@@ -87,6 +88,7 @@ export const allOptions = {
apiKeyOption,
audioLatencyHintOption,
enableCrossSiteIsolationOption,
+ imageSequencePatternOption,
};
export type AvailableOptions = keyof typeof allOptions;
diff --git a/packages/renderer/src/render-frame-and-retry-target-close.ts b/packages/renderer/src/render-frame-and-retry-target-close.ts
index 0570860ec8..bf2ca7f680 100644
--- a/packages/renderer/src/render-frame-and-retry-target-close.ts
+++ b/packages/renderer/src/render-frame-and-retry-target-close.ts
@@ -50,6 +50,7 @@ export const renderFrameAndRetryTargetClose = async ({
onFrameBuffer,
onFrameUpdate,
nextFrameToRender,
+ imageSequenceName,
}: {
retriesLeft: number;
attempt: number;
@@ -88,6 +89,7 @@ export const renderFrameAndRetryTargetClose = async ({
timeToRenderInMilliseconds: number,
) => void);
nextFrameToRender: NextFrameToRender;
+ imageSequenceName: string | null;
}): Promise<void> => {
const currentPool = await poolPromise;
@@ -129,6 +131,7 @@ export const renderFrameAndRetryTargetClose = async ({
nextFrameToRender,
frame,
page: freePage,
+ imageSequenceName,
}),
new Promise((_, reject) => {
cancelSignal?.(() => {
@@ -211,6 +214,7 @@ export const renderFrameAndRetryTargetClose = async ({
onFrameBuffer,
onFrameUpdate,
nextFrameToRender,
+ imageSequenceName,
});
}
@@ -264,6 +268,7 @@ export const renderFrameAndRetryTargetClose = async ({
onFrameBuffer,
onFrameUpdate,
nextFrameToRender,
+ imageSequenceName,
});
}
};
diff --git a/packages/renderer/src/render-frame-with-option-to-reject.ts b/packages/renderer/src/render-frame-with-option-to-reject.ts
index 6bc6d4b946..b892ca507e 100644
--- a/packages/renderer/src/render-frame-with-option-to-reject.ts
+++ b/packages/renderer/src/render-frame-with-option-to-reject.ts
@@ -47,6 +47,7 @@ export const renderFrameWithOptionToReject = async ({
onFrameUpdate,
frame,
page,
+ pattern,
}: {
reject: (err: Error) => void;
width: number;
@@ -83,6 +84,7 @@ export const renderFrameWithOptionToReject = async ({
) => void);
frame: number;
page: Page;
+ pattern: string | null;
}) => {
const startTime = performance.now();
@@ -153,6 +155,7 @@ export const renderFrameWithOptionToReject = async ({
countType,
lastFrame,
totalFrames: framesToRender.length,
+ imageSequencePattern: pattern,
}),
),
jpegQuality,
diff --git a/packages/renderer/src/render-frame.ts b/packages/renderer/src/render-frame.ts
index fd98e07f85..5d309048df 100644
--- a/packages/renderer/src/render-frame.ts
+++ b/packages/renderer/src/render-frame.ts
@@ -37,6 +37,7 @@ export const renderFrame = ({
framesRenderedObj,
frame,
page,
+ imageSequenceName,
}: {
attempt: number;
indent: boolean;
@@ -71,6 +72,7 @@ export const renderFrame = ({
nextFrameToRender: NextFrameToRender;
frame: number;
page: Page;
+ imageSequenceName: string | null;
}) => {
return new Promise<void>((resolve, reject) => {
renderFrameWithOptionToReject({
@@ -103,6 +105,7 @@ export const renderFrame = ({
onFrameUpdate,
frame,
page,
+ pattern: imageSequenceName,
})
.then(() => {
resolve();
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index 8b4ffcb581..548bff5a46 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -360,6 +360,11 @@ const innerRenderFrames = async ({
concurrencyOrFramesToRender,
});
+ const pattern = imageSequencePattern || `element-[frame].[ext]`;
+ const imageSequenceName = pattern
+ .replace(/\[frame\]/g, `%0${filePadLength}d`)
+ .replace(/\[ext\]/g, imageFormat);
+
await Promise.all(
allFramesAndExtraFrames.map(() => {
return renderFrameAndRetryTargetClose({
@@ -394,6 +399,7 @@ const innerRenderFrames = async ({
onFrameBuffer,
onFrameUpdate,
nextFrameToRender,
+ imageSequenceName: pattern,
});
}),
);
@@ -402,11 +408,6 @@ const innerRenderFrames = async ({
await Promise.all(downloadPromises);
- const pattern = imageSequencePattern || `element-%0[frame]d.[ext]`;
- const imageSequenceName = pattern
- .replace(/\[frame\]/g, `%0${filePadLength}d`)
- .replace(/\[ext\]/g, imageFormat);
-
return {
assetsInfo: {
assets: assets.sort((a, b) => {
diff --git a/packages/renderer/src/test/frame-padded-index.test.ts b/packages/renderer/src/test/frame-padded-index.test.ts
index 1d19da6304..6648052776 100644
--- a/packages/renderer/src/test/frame-padded-index.test.ts
+++ b/packages/renderer/src/test/frame-padded-index.test.ts
@@ -10,6 +10,7 @@ test('Get frame padded index', () => {
index: 0,
lastFrame: 100,
totalFrames: 100,
+ imageSequencePattern: null,
}),
).toBe('element-00.jpeg');
@@ -21,6 +22,7 @@ test('Get frame padded index', () => {
index: 50,
lastFrame: 100,
totalFrames: 100,
+ imageSequencePattern: null,
}),
).toBe('element-50.jpeg');
@@ -32,6 +34,7 @@ test('Get frame padded index', () => {
index: 50,
lastFrame: 100,
totalFrames: 101,
+ imageSequencePattern: null,
}),
).toBe('element-050.jpeg');
expect(
@@ -42,6 +45,7 @@ test('Get frame padded index', () => {
index: 50,
lastFrame: 99,
totalFrames: 100,
+ imageSequencePattern: null,
}),
).toBe('element-50.jpeg');
});