🎥 Make videos programmatically with React
cool
Jonny Burger38e477f32c76
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 6a1ebf8a29..2d0084bcb0 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -39,6 +39,7 @@ const {colorSpaceOption,enableMultiprocessOnLinuxOption,glOption,+ numberOfGifLoopsOption,} = BrowserSafeApis.options;const getValidConcurrency = (cliConcurrency: number | string | null) => {@@ -188,7 +189,6 @@ export const benchmarkCommand = async (frameRange: defaultFrameRange,overwrite,pixelFormat,- numberOfGifLoops,everyNthFrame,ffmpegOverride,encodingMaxRate,@@ -337,6 +337,9 @@ export const benchmarkCommand = async (commandLine: parsedCli,}).value;const muted = mutedOption.getValue({commandLine: parsedCli}).value;+ const numberOfGifLoops = numberOfGifLoopsOption.getValue({+ commandLine: parsedCli,+ }).value;for (const composition of compositions) {const {value: videoCodec, source: codecReason} = videoCodecOption.getValue(diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 979c65a737..055fd23a82 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -41,6 +41,7 @@ import type {Crf,DeleteAfter,FrameRange,+ NumberOfGifLoops,StillImageFormat,VideoImageFormat,} from '@remotion/renderer';@@ -81,8 +82,6 @@ import {setKeyboardShortcutsEnabled,} from './keyboard-shortcuts';import {setLogLevel} from './log';-import type {Loop} from './number-of-gif-loops';-import {getNumberOfGifLoops, setNumberOfGifLoops} from './number-of-gif-loops';import {setNumberOfSharedAudioTags} from './number-of-shared-audio-tags';import {getShouldOpenBrowser, setShouldOpenBrowser} from './open-browser';import {setOutputLocation} from './output-location';@@ -121,6 +120,7 @@ const {folderExpiryOption,enableMultiprocessOnLinuxOption,glOption,+ numberOfGifLoopsOption,} = BrowserSafeApis.options;declare global {@@ -312,7 +312,7 @@ declare global {* Specify the number of Loop a GIF should have.* Default: null (means GIF will loop infinite)*/- readonly setNumberOfGifLoops: (newLoop: Loop) => void;+ readonly setNumberOfGifLoops: (newLoop: NumberOfGifLoops) => void;/*** Disable audio output.* Default: false@@ -580,7 +580,7 @@ export const Config: FlatConfig = {setFrameRange,setScale: scaleOption.setConfig,setEveryNthFrame,- setNumberOfGifLoops,+ setNumberOfGifLoops: numberOfGifLoopsOption.setConfig,setMuted: mutedOption.setConfig,setEnforceAudioTrack: enforceAudioOption.setConfig,setOutputLocation,@@ -647,7 +647,6 @@ export const ConfigInternals = {getHeight,getWidth,getEntryPoint,- getNumberOfGifLoops,getWebpackPolling,getShouldOpenBrowser,getChromiumUserAgent,diff --git a/packages/cli/src/config/number-of-gif-loops.ts b/packages/cli/src/config/number-of-gif-loops.tsdeleted file mode 100644index a769cfaef7..0000000000--- a/packages/cli/src/config/number-of-gif-loops.ts+++ /dev/null@@ -1,15 +0,0 @@-export type Loop = number | null;--let currentLoop: Loop = null;--export const setNumberOfGifLoops = (newLoop: Loop | null) => {- if (newLoop !== null && typeof newLoop !== 'number') {- throw new Error('--number-of-gif-loops flag must be a number.');- }-- currentLoop = newLoop;-};--export const getNumberOfGifLoops = () => {- return currentLoop;-};diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 9aa0d1f250..15103b33d3 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -92,7 +92,6 @@ export const getCliOptions = (options: {const userAgent = ConfigInternals.getChromiumUserAgent();const everyNthFrame = ConfigInternals.getEveryNthFrame();- const numberOfGifLoops = ConfigInternals.getNumberOfGifLoops();const concurrency = ConfigInternals.getConcurrency();@@ -115,7 +114,6 @@ export const getCliOptions = (options: {pixelFormat,proResProfile,everyNthFrame,- numberOfGifLoops,stillFrame: ConfigInternals.getStillFrame(),browserExecutable,logLevel: ConfigInternals.Logging.getLogLevel(),diff --git a/packages/cli/src/get-render-defaults.ts b/packages/cli/src/get-render-defaults.tsindex e8da91c6de..3d84a63843 100644--- a/packages/cli/src/get-render-defaults.ts+++ b/packages/cli/src/get-render-defaults.ts@@ -16,6 +16,7 @@ const {colorSpaceOption,enableMultiprocessOnLinuxOption,glOption,+ numberOfGifLoopsOption,} = BrowserSafeApis.options;export const getRenderDefaults = (): RenderDefaults => {@@ -61,11 +62,13 @@ export const getRenderDefaults = (): RenderDefaults => {const gl = glOption.getValue({commandLine: parsedCli,}).value;+ const numberOfGifLoops = numberOfGifLoopsOption.getValue({+ commandLine: parsedCli,+ }).value;const encodingBufferSize = ConfigInternals.getEncodingBufferSize();const encodingMaxRate = ConfigInternals.getEncodingMaxRate();const everyNthFrame = ConfigInternals.getEveryNthFrame();- const numberOfGifLoops = ConfigInternals.getNumberOfGifLoops();const delayRenderTimeout = ConfigInternals.getCurrentPuppeteerTimeout();const audioCodec = ConfigInternals.getAudioCodec();const stillImageFormat = ConfigInternals.getUserPreferredStillImageFormat();@@ -102,7 +105,6 @@ export const getRenderDefaults = (): RenderDefaults => {encodingBufferSize,encodingMaxRate,everyNthFrame,- numberOfGifLoops,delayRenderTimeout,audioCodec,disableWebSecurity,@@ -115,5 +117,6 @@ export const getRenderDefaults = (): RenderDefaults => {userAgent,beepOnFinish,repro,+ numberOfGifLoops,};};diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex cb5589cc0b..b15823304e 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -151,10 +151,6 @@ export const parseCommandLine = () => {Config.setBrowserExecutable(parsedCli['browser-executable']);}- if (parsedCli[numberOfGifLoopsOption.cliFlag]) {- Config.setNumberOfGifLoops(parsedCli[numberOfGifLoopsOption.cliFlag]);- }-if (typeof parsedCli['bundle-cache'] !== 'undefined') {Config.setCachingEnabled(parsedCli['bundle-cache'] !== 'false');}@@ -231,10 +227,6 @@ export const parseCommandLine = () => {Config.setEveryNthFrame(parsedCli['every-nth-frame']);}- if (parsedCli.gl) {- Config.setChromiumOpenGlRenderer(parsedCli.gl);- }-if (parsedCli['prores-profile']) {Config.setProResProfile(String(parsedCli['prores-profile']) as ProResProfile,@@ -271,10 +263,6 @@ export const parseCommandLine = () => {);}- if (typeof parsedCli['enforce-audio-track'] !== 'undefined') {- Config.setEnforceAudioTrack(parsedCli['enforce-audio-track']);- }-if (typeof parsedCli['public-dir'] !== 'undefined') {Config.setPublicDir(parsedCli['public-dir']);}diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex 6ce6993ce1..236e6a2bf8 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -10,6 +10,7 @@ import type {FfmpegOverrideFn,FrameRange,LogLevel,+ NumberOfGifLoops,PixelFormat,ProResProfile,RenderMediaOnDownload,@@ -34,7 +35,6 @@ import path from 'node:path';import {NoReactInternals} from 'remotion/no-react';import {chalk} from '../chalk';import {ConfigInternals} from '../config';-import type {Loop} from '../config/number-of-gif-loops';import {getAndValidateAbsoluteOutputFile} from '../get-cli-options';import {getCompositionWithDimensionOverride} from '../get-composition-with-dimension-override';import {getOutputFilename} from '../get-filename';@@ -143,7 +143,7 @@ export const renderVideoFlow = async ({proResProfile: ProResProfile | undefined;x264Preset: X264Preset | null;pixelFormat: PixelFormat;- numberOfGifLoops: Loop;+ numberOfGifLoops: NumberOfGifLoops;audioCodec: AudioCodec | null;disallowParallelEncoding: boolean;offthreadVideoCacheSizeInBytes: number | null;diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex fbf83ca1a0..565eaf9ca9 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -26,6 +26,7 @@ const {colorSpaceOption,enableMultiprocessOnLinuxOption,glOption,+ numberOfGifLoopsOption,} = BrowserSafeApis.options;export const render = async (@@ -79,7 +80,6 @@ export const render = async (pixelFormat,encodingMaxRate,encodingBufferSize,- numberOfGifLoops,repro,} = getCliOptions({isLambda: false,@@ -118,6 +118,9 @@ export const render = async (commandLine: parsedCli,}).value;const gl = glOption.getValue({commandLine: parsedCli}).value;+ const numberOfGifLoops = numberOfGifLoopsOption.getValue({+ commandLine: parsedCli,+ }).value;const chromiumOptions: ChromiumOptions = {disableWebSecurity,diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.tsindex 5102120ba1..c05b5d290a 100644--- a/packages/cloudrun/src/cli/commands/render/index.ts+++ b/packages/cloudrun/src/cli/commands/render/index.ts@@ -26,6 +26,7 @@ const {enforceAudioOption,mutedOption,colorSpaceOption,+ numberOfGifLoopsOption,enableMultiprocessOnLinuxOption,glOption,} = BrowserSafeApis.options;@@ -71,7 +72,6 @@ export const renderCommand = async (pixelFormat,proResProfile,everyNthFrame,- numberOfGifLoops,encodingMaxRate,encodingBufferSize,height,@@ -241,6 +241,9 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}const colorSpace = colorSpaceOption.getValue({commandLine: CliInternals.parsedCli,}).value;+ const numberOfGifLoops = numberOfGifLoopsOption.getValue({+ commandLine: CliInternals.parsedCli,+ }).value;const res = await internalRenderMediaOnCloudrun({cloudRunUrl,serviceName: undefined,diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex 162169b693..d39f4aceba 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -53,6 +53,7 @@ const {deleteAfterOption,enableMultiprocessOnLinuxOption,glOption,+ numberOfGifLoopsOption,} = BrowserSafeApis.options;export const renderCommand = async (@@ -83,7 +84,6 @@ export const renderCommand = async (proResProfile,puppeteerTimeout,everyNthFrame,- numberOfGifLoops,overwrite,encodingMaxRate,encodingBufferSize,@@ -138,6 +138,9 @@ export const renderCommand = async (const gl = glOption.getValue({commandLine: CliInternals.parsedCli,}).value;+ const numberOfGifLoops = numberOfGifLoopsOption.getValue({+ commandLine: CliInternals.parsedCli,+ }).value;const chromiumOptions: ChromiumOptions = {disableWebSecurity,diff --git a/packages/renderer/src/index.ts b/packages/renderer/src/index.tsindex 4c0112e777..9484650396 100644--- a/packages/renderer/src/index.ts+++ b/packages/renderer/src/index.ts@@ -105,6 +105,7 @@ export type {ChromiumOptions} from './open-browser';export {ColorSpace} from './options/color-space';export {DeleteAfter} from './options/delete-after';export {OpenGlRenderer} from './options/gl';+export {NumberOfGifLoops} from './options/number-of-gif-loops';export {AnyRemotionOption, RemotionOption, ToOptions} from './options/option';export {X264Preset} from './options/x264-preset';export {PixelFormat} from './pixel-format';diff --git a/packages/renderer/src/options/number-of-gif-loops.tsx b/packages/renderer/src/options/number-of-gif-loops.tsxindex 9676c032c8..af64b04ad9 100644--- a/packages/renderer/src/options/number-of-gif-loops.tsx+++ b/packages/renderer/src/options/number-of-gif-loops.tsx@@ -1,8 +1,20 @@import type {AnyRemotionOption} from './option';+export type NumberOfGifLoops = number | null;++let currentLoop: NumberOfGifLoops = null;++const validate = (newLoop: unknown) => {+ if (newLoop !== null && typeof newLoop !== 'number') {+ throw new Error('--number-of-gif-loops flag must be a number.');+ }+};++const cliFlag = 'number-of-gif-loops' as const;+export const numberOfGifLoopsOption = {name: 'Number of GIF loops',- cliFlag: 'number-of-gif-loops' as const,+ cliFlag,description: () => {return (<>@@ -30,4 +42,29 @@ export const numberOfGifLoopsOption = {docLink:'https://www.remotion.dev/docs/render-as-gif#changing-the-number-of-loops',type: 0 as number | null,+ getValue: ({commandLine}) => {+ if (commandLine[cliFlag] !== undefined) {+ validate(commandLine[cliFlag]);+ return {+ value: commandLine[cliFlag] as number,+ source: 'cli',+ };+ }++ if (currentLoop !== null) {+ return {+ value: currentLoop,+ source: 'config',+ };+ }++ return {+ value: null,+ source: 'default',+ };+ },+ setConfig: (newLoop: NumberOfGifLoops) => {+ validate(newLoop);+ currentLoop = newLoop;+ },} satisfies AnyRemotionOption<number | null>;