Skip to content

🎥 Make videos programmatically with React

Remotion Studio: Allow starting server with IPv4

Jonny Burger8e835bf667ad
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index ff512c8a94..5585053e9e 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -96,6 +96,7 @@ type CommandLineOptions = {
['browser-args']: string;
['user-agent']: string;
['out-dir']: string;
+ ipv4: boolean;
[deleteAfterOption.cliFlag]: TypeOfOption<typeof deleteAfterOption>;
[folderExpiryOption.cliFlag]: TypeOfOption<typeof folderExpiryOption>;
[enableMultiprocessOnLinuxOption.cliFlag]: TypeOfOption<
@@ -127,6 +128,7 @@ export const BooleanFlags = [
'disable-keyboard-shortcuts',
'default-only',
'no-open',
+ 'ipv4',
beepOnFinishOption.cliFlag,
'repro',
];
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 56a0e48384..df43d0c5c4 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -275,6 +275,7 @@ export const renderVideoFlow = async ({
webpackConfigOrServeUrl: urlOrBundle,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
});
addCleanupCallback(() => server.closeServer(false));
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index 000a29dcd0..fda85cabc6 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -189,6 +189,7 @@ export const renderStillFlow = async ({
webpackConfigOrServeUrl: urlOrBundle,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
});
addCleanupCallback(() => server.closeServer(false));
diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.ts
index 7e7fa9084e..f71b750d4e 100644
--- a/packages/cli/src/studio.ts
+++ b/packages/cli/src/studio.ts
@@ -128,5 +128,6 @@ export const studioCommand = async (
bufferStateDelayInMilliseconds:
ConfigInternals.getBufferStateDelayInMilliseconds(),
binariesDirectory,
+ forceIPv4: parsedCli.ipv4,
});
};
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index f3ed86833a..7ddcfc7552 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -138,6 +138,7 @@ export const renderCommand = async (
webpackConfigOrServeUrl: serveUrl,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
});
const {compositionId} =
diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.ts
index 88e7f39c21..4ab34a3210 100644
--- a/packages/cloudrun/src/cli/commands/still.ts
+++ b/packages/cloudrun/src/cli/commands/still.ts
@@ -106,6 +106,7 @@ export const stillCommand = async (
webpackConfigOrServeUrl: serveUrl,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
});
const {compositionId} =
diff --git a/packages/it-tests/src/bundle/bundle-studio.test.ts b/packages/it-tests/src/bundle/bundle-studio.test.ts
index 6ea9864d29..f7ca9f25fa 100644
--- a/packages/it-tests/src/bundle/bundle-studio.test.ts
+++ b/packages/it-tests/src/bundle/bundle-studio.test.ts
@@ -22,6 +22,7 @@ test("Bundle studio", async () => {
offthreadVideoCacheSizeInBytes: null,
remotionRoot: path.join(process.cwd(), "..", "example"),
binariesDirectory: null,
+ forceIPv4: false,
}
);
await tab.goto({
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 80df172d87..0493b65c67 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -203,6 +203,7 @@ export const renderCommand = async (
webpackConfigOrServeUrl: serveUrl,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
});
const {compositionId} =
diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.ts
index 8b5032a540..17cc03108f 100644
--- a/packages/lambda/src/cli/commands/still.ts
+++ b/packages/lambda/src/cli/commands/still.ts
@@ -134,6 +134,7 @@ export const stillCommand = async (
webpackConfigOrServeUrl: serveUrl,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
});
const {compositionId} = await getCompositionWithDimensionOverride({
diff --git a/packages/lambda/src/functions/still.ts b/packages/lambda/src/functions/still.ts
index d3ad9c0554..e3f4be6f36 100644
--- a/packages/lambda/src/functions/still.ts
+++ b/packages/lambda/src/functions/still.ts
@@ -125,6 +125,7 @@ const innerStillHandler = async ({
webpackConfigOrServeUrl: serveUrl,
offthreadVideoCacheSizeInBytes: lambdaParams.offthreadVideoCacheSizeInBytes,
binariesDirectory: null,
+ forceIPv4: false,
});
const browserInstance = await browserInstancePromise;
diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.ts
index 3ee8ae93e1..f4b1bb49e7 100644
--- a/packages/renderer/src/get-compositions.ts
+++ b/packages/renderer/src/get-compositions.ts
@@ -194,6 +194,7 @@ const internalGetCompositionsRaw = async ({
indent,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
},
{
onDownload: () => undefined,
diff --git a/packages/renderer/src/port-config.ts b/packages/renderer/src/port-config.ts
index a4d8ce881c..01a2058e98 100644
--- a/packages/renderer/src/port-config.ts
+++ b/packages/renderer/src/port-config.ts
@@ -9,14 +9,14 @@ type PortConfig = {
let cached: PortConfig | null = null;
-export const getPortConfig = (): PortConfig => {
+export const getPortConfig = (preferIpv4: boolean): PortConfig => {
if (cached) {
return cached;
}
const networkInterfaces = os.networkInterfaces();
const flattened = flattenNetworkInterfaces(networkInterfaces);
- const host = getHostToBind(flattened);
+ const host = getHostToBind(flattened, preferIpv4);
const hostsToTry = getHostsToTry(flattened);
const response: PortConfig = {host, hostsToTry};
@@ -24,8 +24,15 @@ export const getPortConfig = (): PortConfig => {
return response;
};
-export const getHostToBind = (flattened: os.NetworkInterfaceInfo[]) => {
- return isIpV6Supported(flattened) ? '::' : '0.0.0.0';
+export const getHostToBind = (
+ flattened: os.NetworkInterfaceInfo[],
+ preferIpv4: boolean,
+) => {
+ if (preferIpv4 || !isIpV6Supported(flattened)) {
+ return '0.0.0.0';
+ }
+
+ return '::';
};
export const getHostsToTry = (flattened: os.NetworkInterfaceInfo[]) => {
diff --git a/packages/renderer/src/prepare-server.ts b/packages/renderer/src/prepare-server.ts
index be3d7505b5..bf4eafbdff 100644
--- a/packages/renderer/src/prepare-server.ts
+++ b/packages/renderer/src/prepare-server.ts
@@ -37,6 +37,7 @@ type PrepareServerOptions = {
indent: boolean;
offthreadVideoCacheSizeInBytes: number | null;
binariesDirectory: string | null;
+ forceIPv4: boolean;
};
export const prepareServer = async ({
@@ -48,6 +49,7 @@ export const prepareServer = async ({
indent,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4,
}: PrepareServerOptions): Promise<RemotionServer> => {
const downloadMap = makeDownloadMap();
Log.verbose(
@@ -70,6 +72,7 @@ export const prepareServer = async ({
indent,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4,
});
let remoteSourceMap: AnySourceMapConsumer | null = null;
@@ -143,6 +146,7 @@ export const prepareServer = async ({
indent,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4,
});
return Promise.resolve({
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index 8ae19ccced..0179df80d1 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -687,6 +687,7 @@ const internalRenderFramesRaw = ({
indent,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
},
{
onDownload,
diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.ts
index 9b91091bda..e04c5d0337 100644
--- a/packages/renderer/src/render-media.ts
+++ b/packages/renderer/src/render-media.ts
@@ -543,6 +543,7 @@ const internalRenderMediaRaw = ({
offthreadVideoCacheSizeInBytes:
offthreadVideoCacheSizeInBytes ?? null,
binariesDirectory,
+ forceIPv4: false,
},
{
onDownload,
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 91fd30d204..9b9106ef31 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -350,6 +350,7 @@ const internalRenderStillRaw = (
indent: options.indent,
offthreadVideoCacheSizeInBytes: options.offthreadVideoCacheSizeInBytes,
binariesDirectory: options.binariesDirectory,
+ forceIPv4: false,
},
{
onDownload: options.onDownload,
diff --git a/packages/renderer/src/select-composition.ts b/packages/renderer/src/select-composition.ts
index ae07d9a861..074ad643bc 100644
--- a/packages/renderer/src/select-composition.ts
+++ b/packages/renderer/src/select-composition.ts
@@ -229,6 +229,7 @@ export const internalSelectCompositionRaw = async (
indent,
offthreadVideoCacheSizeInBytes,
binariesDirectory,
+ forceIPv4: false,
},
{
onDownload: () => undefined,
diff --git a/packages/renderer/src/serve-static.ts b/packages/renderer/src/serve-static.ts
index 7668857c0f..408ae555ae 100644
--- a/packages/renderer/src/serve-static.ts
+++ b/packages/renderer/src/serve-static.ts
@@ -19,6 +19,7 @@ export const serveStatic = async (
indent: boolean;
offthreadVideoCacheSizeInBytes: number | null;
binariesDirectory: string | null;
+ forceIPv4: boolean;
},
): Promise<{
port: number;
@@ -74,7 +75,7 @@ export const serveStatic = async (
const maxTries = 5;
- const portConfig = getPortConfig();
+ const portConfig = getPortConfig(options.forceIPv4);
for (let i = 0; i < maxTries; i++) {
let unlock = () => {};
diff --git a/packages/renderer/src/test/port-config.test.ts b/packages/renderer/src/test/port-config.test.ts
index ffe23cf381..551ab95bb7 100644
--- a/packages/renderer/src/test/port-config.test.ts
+++ b/packages/renderer/src/test/port-config.test.ts
@@ -267,7 +267,10 @@ const macOsM1Interfaces: NodeJS.Dict<NetworkInterfaceInfo[]> = {
};
test('Port config on Docker with IPv6 support', () => {
- const hostToBind = getHostToBind(flattenNetworkInterfaces(dockerInterfaces));
+ const hostToBind = getHostToBind(
+ flattenNetworkInterfaces(dockerInterfaces),
+ false,
+ );
expect(hostToBind).toBe('::');
});
@@ -277,7 +280,10 @@ test('Port config on Docker with no loopback address', () => {
});
test('Port config on M1 Mac', () => {
- const hostToBind = getHostToBind(flattenNetworkInterfaces(macOsM1Interfaces));
+ const hostToBind = getHostToBind(
+ flattenNetworkInterfaces(macOsM1Interfaces),
+ false,
+ );
expect(hostToBind).toBe('::');
});
diff --git a/packages/studio-server/src/preview-server/start-server.ts b/packages/studio-server/src/preview-server/start-server.ts
index 9fa968abdc..a31e3ec408 100644
--- a/packages/studio-server/src/preview-server/start-server.ts
+++ b/packages/studio-server/src/preview-server/start-server.ts
@@ -41,6 +41,7 @@ export const startServer = async (options: {
queueMethods: QueueMethods;
gitSource: GitSource | null;
binariesDirectory: string | null;
+ forceIPv4: boolean;
}): Promise<{
port: number;
liveEventsServer: LiveEventsServer;
@@ -129,7 +130,7 @@ export const startServer = async (options: {
const maxTries = 5;
- const portConfig = RenderInternals.getPortConfig();
+ const portConfig = RenderInternals.getPortConfig(options.forceIPv4);
for (let i = 0; i < maxTries; i++) {
try {
diff --git a/packages/studio-server/src/start-studio.ts b/packages/studio-server/src/start-studio.ts
index d96c23533f..341328a42f 100644
--- a/packages/studio-server/src/start-studio.ts
+++ b/packages/studio-server/src/start-studio.ts
@@ -79,6 +79,7 @@ export const startStudio = async ({
gitSource,
bufferStateDelayInMilliseconds,
binariesDirectory,
+ forceIPv4,
}: {
browserArgs: string;
browserFlag: string;
@@ -103,6 +104,7 @@ export const startStudio = async ({
previewEntry: string;
gitSource: GitSource | null;
binariesDirectory: string | null;
+ forceIPv4: boolean;
}) => {
watchRootFile(remotionRoot);
const publicDir = getAbsolutePublicDir({
@@ -163,6 +165,7 @@ export const startStudio = async ({
gitSource,
bufferStateDelayInMilliseconds,
binariesDirectory,
+ forceIPv4,
});
setLiveEventsListener(liveEventsServer);