🎥 Make videos programmatically with React
add public dir to options parameter
Jonny Burgera568eb033821
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 7fa2ee2534..a299834013 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -48,6 +48,7 @@ const {binariesDirectoryOption,forSeamlessAacConcatenationOption,publicPathOption,+ publicDirOption,} = BrowserSafeApis.options;const getValidConcurrency = (cliConcurrency: number | string | null) => {@@ -188,7 +189,6 @@ export const benchmarkCommand = async (inputProps,envVariables,browserExecutable,- publicDir,proResProfile,frameRange: defaultFrameRange,pixelFormat,@@ -220,6 +220,7 @@ export const benchmarkCommand = async (const gl = glOption.getValue({commandLine: parsedCli}).value;const headless = headlessOption.getValue({commandLine: parsedCli}).value;const publicPath = publicPathOption.getValue({commandLine: parsedCli}).value;+ const publicDir = publicDirOption.getValue({commandLine: parsedCli}).value;const chromiumOptions: ChromiumOptions = {disableWebSecurity,diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.tsindex 392e49c2f2..2ea12c30de 100644--- a/packages/cli/src/bundle.ts+++ b/packages/cli/src/bundle.ts@@ -6,7 +6,6 @@ import {existsSync, readdirSync, readFileSync, rmSync, writeFileSync} from 'fs';import path from 'path';import {chalk} from './chalk';import {findEntryPoint} from './entry-point';-import {getCliOptions} from './get-cli-options';import {getGitSource} from './get-github-repository';import {Log} from './log';import {parsedCli, quietFlagProvided} from './parse-command-line';@@ -14,7 +13,7 @@ import {bundleOnCli} from './setup-cache';import {shouldUseNonOverlayingLogger} from './should-use-non-overlaying-logger';import {yesOrNo} from './yes-or-no';-const {publicPathOption} = BrowserSafeApis.options;+const {publicPathOption, publicDirOption} = BrowserSafeApis.options;export const bundleCommand = async (remotionRoot: string,@@ -53,12 +52,8 @@ export const bundleCommand = async (process.exit(1);}- const {publicDir} = getCliOptions({- isStill: false,- logLevel,- });-const publicPath = publicPathOption.getValue({commandLine: parsedCli}).value;+ const publicDir = publicDirOption.getValue({commandLine: parsedCli}).value;const outputPath = parsedCli['out-dir']? path.resolve(process.cwd(), parsedCli['out-dir'])diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 6918a5e529..7ef19cfad3 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -19,6 +19,7 @@ const {delayRenderTimeoutInMillisecondsOption,binariesDirectoryOption,publicPathOption,+ publicDirOption,} = BrowserSafeApis.options;export const listCompositionsCommand = async (@@ -56,7 +57,6 @@ export const listCompositionsCommand = async (browserExecutable,envVariables,inputProps,- publicDir,ignoreCertificateErrors,userAgent,disableWebSecurity,@@ -89,6 +89,7 @@ export const listCompositionsCommand = async (offthreadVideoCacheSizeInBytesOption.getValue({commandLine: parsedCli,}).value;+ const publicDir = publicDirOption.getValue({commandLine: parsedCli}).value;const {urlOrBundle: bundled, cleanup: cleanupBundle} =await bundleOnCliOrTakeServeUrl({diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex a5ce2764e7..27bc72f600 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -76,7 +76,6 @@ import {overrideWebpackConfig} from './override-webpack';import {setPixelFormat} from './pixel-format';import {setPort, setRendererPort, setStudioPort} from './preview-server';import {setProResProfile} from './prores-profile';-import {getPublicDir, setPublicDir} from './public-dir';import {getChromiumUserAgent, setChromiumUserAgent} from './user-agent';import {setWebpackCaching} from './webpack-caching';import {@@ -113,6 +112,7 @@ const {enableLambdaInsights,logLevelOption,delayRenderTimeoutInMillisecondsOption,+ publicDirOption,binariesDirectoryOption,preferLosslessOption,forSeamlessAacConcatenationOption,@@ -570,7 +570,7 @@ export const Config: FlatConfig = {setPort,setStudioPort,setRendererPort,- setPublicDir,+ setPublicDir: publicDirOption.setConfig,setEntryPoint,setLevel: logLevelOption.setConfig,setBrowserExecutable,@@ -661,7 +661,6 @@ export const ConfigInternals = {getMaxTimelineTracks: StudioServerInternals.getMaxTimelineTracks,defaultOverrideFunction,getKeyboardShortcutsEnabled,- getPublicDir,getFfmpegOverrideFunction,getHeight,getWidth,diff --git a/packages/cli/src/config/public-dir.ts b/packages/cli/src/config/public-dir.tsdeleted file mode 100644index a075089575..0000000000--- a/packages/cli/src/config/public-dir.ts+++ /dev/null@@ -1,9 +0,0 @@-let publicDir: string | null = null;--export const getPublicDir = () => {- return publicDir;-};--export const setPublicDir = (dir: string | null) => {- publicDir = dir;-};diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.tsindex 3e837610e3..0ee4a0a99b 100644--- a/packages/cli/src/get-cli-options.ts+++ b/packages/cli/src/get-cli-options.ts@@ -98,7 +98,6 @@ export const getCliOptions = (options: {userAgent,disableWebSecurity,ignoreCertificateErrors,- publicDir: ConfigInternals.getPublicDir(),ffmpegOverride: ConfigInternals.getFfmpegOverrideFunction(),height,width,diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.tsindex bc3e2bd61a..e96ac330fa 100644--- a/packages/cli/src/parse-command-line.ts+++ b/packages/cli/src/parse-command-line.ts@@ -227,10 +227,6 @@ export const parseCommandLine = () => {);}- if (typeof parsedCli['public-dir'] !== 'undefined') {- Config.setPublicDir(parsedCli['public-dir']);- }-if (typeof parsedCli['webpack-poll'] !== 'undefined') {Config.setWebpackPollingInMilliseconds(parsedCli['webpack-poll']);}diff --git a/packages/cli/src/render-queue/process-still.ts b/packages/cli/src/render-queue/process-still.tsindex 3c7ee7df6f..df66c873c7 100644--- a/packages/cli/src/render-queue/process-still.ts+++ b/packages/cli/src/render-queue/process-still.ts@@ -1,9 +1,13 @@+import {BrowserSafeApis} from '@remotion/renderer/client';import type {JobProgressCallback, RenderJob} from '@remotion/studio-server';import {getRendererPortFromConfigFile} from '../config/preview-server';import {convertEntryPointToServeUrl} from '../convert-entry-point-to-serve-url';import {getCliOptions} from '../get-cli-options';+import {parsedCli} from '../parse-command-line';import {renderStillFlow} from '../render-flows/still';+const {publicDirOption} = BrowserSafeApis.options;+export const processStill = async ({job,remotionRoot,@@ -21,11 +25,15 @@ export const processStill = async ({throw new Error('Expected still job');}- const {publicDir, browserExecutable} = getCliOptions({+ const {browserExecutable} = getCliOptions({isStill: true,logLevel: job.logLevel,});+ const publicDir = publicDirOption.getValue({+ commandLine: parsedCli,+ }).value;+const fullEntryPoint = convertEntryPointToServeUrl(entryPoint);await renderStillFlow({diff --git a/packages/cli/src/render-queue/process-video.ts b/packages/cli/src/render-queue/process-video.tsindex 812d960a94..e90a5d9f15 100644--- a/packages/cli/src/render-queue/process-video.ts+++ b/packages/cli/src/render-queue/process-video.ts@@ -1,10 +1,14 @@import type {LogLevel} from '@remotion/renderer';+import {BrowserSafeApis} from '@remotion/renderer/client';import type {JobProgressCallback, RenderJob} from '@remotion/studio-server';import {getRendererPortFromConfigFile} from '../config/preview-server';import {convertEntryPointToServeUrl} from '../convert-entry-point-to-serve-url';import {getCliOptions} from '../get-cli-options';+import {parsedCli} from '../parse-command-line';import {renderVideoFlow} from '../render-flows/render';+const {publicDirOption} = BrowserSafeApis.options;+export const processVideoJob = async ({job,remotionRoot,@@ -24,7 +28,11 @@ export const processVideoJob = async ({throw new Error('Expected video job');}- const {publicDir, browserExecutable, ffmpegOverride} = getCliOptions({+ const publicDir = publicDirOption.getValue({+ commandLine: parsedCli,+ }).value;++ const {browserExecutable, ffmpegOverride} = getCliOptions({isStill: true,logLevel,});diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 791c422f38..85b2223417 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -36,6 +36,7 @@ const {separateAudioOption,audioCodecOption,publicPathOption,+ publicDirOption,} = BrowserSafeApis.options;export const render = async (@@ -86,7 +87,6 @@ export const render = async (userAgent,disableWebSecurity,ignoreCertificateErrors,- publicDir,height,width,ffmpegOverride,@@ -173,6 +173,7 @@ export const render = async (};const audioCodec = audioCodecOption.getValue({commandLine: parsedCli}).value;+ const publicDir = publicDirOption.getValue({commandLine: parsedCli}).value;await renderVideoFlow({fullEntryPoint,diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex a8cb6442aa..ce7b44a345 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -21,6 +21,7 @@ const {overwriteOption,binariesDirectoryOption,publicPathOption,+ publicDirOption,} = BrowserSafeApis.options;export const still = async (@@ -65,7 +66,6 @@ export const still = async (envVariables,height,inputProps,- publicDir,stillFrame,width,disableWebSecurity,@@ -106,6 +106,9 @@ export const still = async (const publicPath = publicPathOption.getValue({commandLine: parsedCli,}).value;+ const publicDir = publicDirOption.getValue({+ commandLine: parsedCli,+ }).value;const chromiumOptions: ChromiumOptions = {disableWebSecurity,diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.tsindex f71b750d4e..0f0086622c 100644--- a/packages/cli/src/studio.ts+++ b/packages/cli/src/studio.ts@@ -31,6 +31,8 @@ const getPort = () => {return null;};+const {binariesDirectoryOption, publicDirOption} = BrowserSafeApis.options;+export const studioCommand = async (remotionRoot: string,args: string[],@@ -91,10 +93,13 @@ export const studioCommand = async (const gitSource = getGitSource(remotionRoot);- const binariesDirectory =- BrowserSafeApis.options.binariesDirectoryOption.getValue({- commandLine: parsedCli,- }).value;+ const binariesDirectory = binariesDirectoryOption.getValue({+ commandLine: parsedCli,+ }).value;++ const relativePublicDir = publicDirOption.getValue({+ commandLine: parsedCli,+ }).value;await StudioServerInternals.startStudio({previewEntry: require.resolve('@remotion/studio/entry'),@@ -109,7 +114,7 @@ export const studioCommand = async (keyboardShortcutsEnabled,maxTimelineTracks: ConfigInternals.getMaxTimelineTracks(),remotionRoot,- userPassedPublicDir: ConfigInternals.getPublicDir(),+ relativePublicDir,webpackOverride: ConfigInternals.getWebpackOverrideFn(),poll: ConfigInternals.getWebpackPolling(),getRenderDefaults,diff --git a/packages/docs/docs/cli/bundle.md b/packages/docs/docs/cli/bundle.mdindex 43a941b9ec..c95c46be21 100644--- a/packages/docs/docs/cli/bundle.md+++ b/packages/docs/docs/cli/bundle.md@@ -28,7 +28,7 @@ Specify a location for the Remotion config file.### `--public-dir`-[Define the location of the `public/` directory.](/docs/config#setpublicdir). If not defined, Remotion will assume the location is the `public` folder in your Remotion root.+<Options id="public-dir" />### `--out-dir`diff --git a/packages/docs/docs/cli/compositions.md b/packages/docs/docs/cli/compositions.mdindex 4ce5a79d6f..821d754386 100644--- a/packages/docs/docs/cli/compositions.md+++ b/packages/docs/docs/cli/compositions.md@@ -51,7 +51,7 @@ If you don't feel like passing command line flags every time, consider creating### `--public-dir`<AvailableFrom v="3.2.13" />-[Define the location of the `public/` directory.](/docs/config#setpublicdir). If not defined, Remotion will assume the location is the `public` folder in your Remotion root.+<Options id="public-path" />### `--timeout`diff --git a/packages/docs/docs/cli/render.md b/packages/docs/docs/cli/render.mdindex 24b06c1bc6..99bb920494 100644--- a/packages/docs/docs/cli/render.md+++ b/packages/docs/docs/cli/render.md@@ -158,7 +158,7 @@ For example only every second frame, every third frame and so on. Only works for### `--public-dir`<AvailableFrom v="3.2.13" />-[Define the location of the `public/` directory.](/docs/config#setpublicdir). If not defined, Remotion will assume the location is the `public` folder in your Remotion root.+<Options id="public-path" />### `--timeout`diff --git a/packages/docs/docs/cli/still.md b/packages/docs/docs/cli/still.mdindex c362f594d7..8fe69114a7 100644--- a/packages/docs/docs/cli/still.md+++ b/packages/docs/docs/cli/still.md@@ -85,7 +85,7 @@ From v3.2.27, negative values are allowed, with `-1` being the last frame.### `--public-dir`<AvailableFrom v="3.2.13" />-[Define the location of the `public/` directory.](/docs/config#setpublicdir). If not defined, Remotion will assume the location is the `public` folder in your Remotion root.+<Options id="public-path" />### `--timeout`diff --git a/packages/docs/docs/cli/studio.md b/packages/docs/docs/cli/studio.mdindex 40f3095863..ba69bafeee 100644--- a/packages/docs/docs/cli/studio.md+++ b/packages/docs/docs/cli/studio.md@@ -43,7 +43,7 @@ Specify a location for a dotenv file - Default `.env`. [Read about how environme### `--public-dir`<AvailableFrom v="3.2.13" />-[Define the location of the `public/` directory.](/docs/config#setpublicdir). If not defined, Remotion will assume the location is the `public` folder in your Remotion root.+<Options id="public-path" />### `--disable-keyboard-shortcuts`<AvailableFrom v="3.2.11" />diff --git a/packages/docs/docs/config.md b/packages/docs/docs/config.mdindex a33f46ea2e..a8771ab98d 100644--- a/packages/docs/docs/config.md+++ b/packages/docs/docs/config.md@@ -79,14 +79,12 @@ The [command line flag](/docs/cli/render#--port) `--port` will take precedence o## setPublicDir()<AvailableFrom v="3.2.13" />-Define the location of the `public/` directory.-By default it is a folder named "public" inside the current working directory.-You can either set an absolute path, or a relative path that will be resolved from the closest package.json location.+<Options id="public-dir" />```ts twoslash title="remotion.config.ts"import { Config } from "@remotion/cli/config";// ---cut----Config.setPublicDir("./publico");+Config.setPublicDir("./custom-public-dir");```The [command line flag](/docs/cli/render#--public-dir) `--public-dir` will take precedence over this option.diff --git a/packages/renderer/src/options/index.tsx b/packages/renderer/src/options/index.tsxindex fff46acb31..f51b1793ee 100644--- a/packages/renderer/src/options/index.tsx+++ b/packages/renderer/src/options/index.tsx@@ -22,6 +22,7 @@ import {offthreadVideoCacheSizeInBytesOption} from './offthreadvideo-cache-size'import type {AnyRemotionOption} from './option';import {overwriteOption} from './overwrite';import {preferLosslessAudioOption} from './prefer-lossless';+import {publicDirOption} from './public-dir';import {publicPathOption} from './public-path';import {reproOption} from './repro';import {scaleOption} from './scale';@@ -65,6 +66,7 @@ export const allOptions = {forSeamlessAacConcatenationOption,separateAudioOption,publicPathOption,+ publicDirOption,};export type AvailableOptions = keyof typeof allOptions;diff --git a/packages/renderer/src/options/public-dir.tsx b/packages/renderer/src/options/public-dir.tsxnew file mode 100644index 0000000000..a05e60ba8a--- /dev/null+++ b/packages/renderer/src/options/public-dir.tsx@@ -0,0 +1,48 @@+import type {AnyRemotionOption} from './option';++const cliFlag = 'public-dir' as const;++let currentPublicDir: string | null = null;++export const publicDirOption = {+ name: 'Public Directory',+ cliFlag,+ description: () => {+ return (+ <>+ Define the location of the{' '}+ <a href="/docs/terminology/public-dir">+ <code>public/ directory</code>+ </a>+ . If not defined, Remotion will assume the location is the `public`+ folder in your Remotion root.+ </>+ );+ },+ ssrName: 'publicDir' as const,+ docLink: 'https://www.remotion.dev/docs/terminology/public-dir',+ getValue: ({commandLine}) => {+ if (commandLine[cliFlag] !== undefined) {+ return {+ source: 'cli',+ value: commandLine[cliFlag] as string,+ };+ }++ if (currentPublicDir !== null) {+ return {+ source: 'config',+ value: currentPublicDir,+ };+ }++ return {+ source: 'default',+ value: null,+ };+ },+ setConfig: (value: string | null) => {+ currentPublicDir = value;+ },+ type: '' as string | null,+} satisfies AnyRemotionOption<string | null>;diff --git a/packages/studio-server/src/preview-server/get-absolute-public-dir.ts b/packages/studio-server/src/preview-server/get-absolute-public-dir.tsindex 602ad0bedf..7fc9cd4b70 100644--- a/packages/studio-server/src/preview-server/get-absolute-public-dir.ts+++ b/packages/studio-server/src/preview-server/get-absolute-public-dir.ts@@ -1,15 +1,13 @@import path from 'node:path';export const getAbsolutePublicDir = ({- userPassedPublicDir,+ relativePublicDir,remotionRoot,}: {- userPassedPublicDir: string | null;+ relativePublicDir: string | null;remotionRoot: string;}) => {- const publicDir = userPassedPublicDir- ? path.resolve(remotionRoot, userPassedPublicDir)+ return relativePublicDir+ ? path.resolve(remotionRoot, relativePublicDir): path.join(remotionRoot, 'public');-- return publicDir;};diff --git a/packages/studio-server/src/preview-server/start-server.ts b/packages/studio-server/src/preview-server/start-server.tsindex f4dfacfd49..26093fd15b 100644--- a/packages/studio-server/src/preview-server/start-server.ts+++ b/packages/studio-server/src/preview-server/start-server.ts@@ -28,7 +28,6 @@ export const startServer = async (options: {remotionRoot: string;keyboardShortcutsEnabled: boolean;publicDir: string;- userPassedPublicDir: string | null;poll: number | null;staticHash: string;staticHashPrefix: string;diff --git a/packages/studio-server/src/start-studio.ts b/packages/studio-server/src/start-studio.tsindex 341328a42f..2b62b524b0 100644--- a/packages/studio-server/src/start-studio.ts+++ b/packages/studio-server/src/start-studio.ts@@ -67,7 +67,7 @@ export const startStudio = async ({maxTimelineTracks,remotionRoot,keyboardShortcutsEnabled,- userPassedPublicDir,+ relativePublicDir,webpackOverride,poll,getRenderDefaults,@@ -93,7 +93,7 @@ export const startStudio = async ({bufferStateDelayInMilliseconds: number | null;remotionRoot: string;keyboardShortcutsEnabled: boolean;- userPassedPublicDir: string | null;+ relativePublicDir: string | null;webpackOverride: WebpackOverrideFn;poll: number | null;getRenderDefaults: () => RenderDefaults;@@ -108,7 +108,7 @@ export const startStudio = async ({}) => {watchRootFile(remotionRoot);const publicDir = getAbsolutePublicDir({- userPassedPublicDir,+ relativePublicDir,remotionRoot,});const hash = crypto.randomBytes(6).toString('hex');@@ -152,7 +152,6 @@ export const startStudio = async ({publicDir,webpackOverride,poll,- userPassedPublicDir,staticHash,staticHashPrefix,outputHash,