Skip to content

🎥 Make videos programmatically with React

refactor

Jonny Burger09c32006f08b
diff --git a/packages/cli/src/get-cli-options.ts b/packages/cli/src/get-cli-options.ts
index 7c85f075e1..a69f9bada8 100644
--- a/packages/cli/src/get-cli-options.ts
+++ b/packages/cli/src/get-cli-options.ts
@@ -27,7 +27,7 @@ const getFinalCodec = async (options: {isLambda: boolean}) => {
const codec = Internals.getFinalOutputCodec({
codec: userCodec,
- fileExtension: getUserPassedFileExtension(),
+ fileExtension: options.isLambda ? null : getUserPassedFileExtension(),
emitWarning: true,
isLambda: options.isLambda,
});
@@ -172,7 +172,9 @@ export const getCliOptions = async (options: {isLambda: boolean}) => {
frameRange
);
const codec = await getFinalCodec({isLambda: options.isLambda});
- const outputFile = getOutputFilename(codec, shouldOutputImageSequence);
+ const outputFile = options.isLambda
+ ? null
+ : getOutputFilename(codec, shouldOutputImageSequence);
const overwrite = Internals.getShouldOverwrite();
const crf = getAndValidateCrf(shouldOutputImageSequence, codec);
const pixelFormat = getAndValidatePixelFormat(codec);
@@ -193,7 +195,9 @@ export const getCliOptions = async (options: {isLambda: boolean}) => {
envVariables: await getEnvironmentVariables(),
quality: Internals.getQuality(),
browser: await getAndValidateBrowser(),
- absoluteOutputFile: getAndValidateAbsoluteOutputFile(outputFile, overwrite),
+ absoluteOutputFile: outputFile
+ ? getAndValidateAbsoluteOutputFile(outputFile, overwrite)
+ : null,
crf,
pixelFormat,
imageFormat,
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 12487d2d98..03ed5d3433 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -86,7 +86,13 @@ export const render = async () => {
crf,
pixelFormat,
imageFormat,
- } = await getCliOptions();
+ } = await getCliOptions({isLambda: false});
+
+ if (!absoluteOutputFile) {
+ throw new Error(
+ 'assertion error - expected absoluteOutputFile to not be null'
+ );
+ }
await checkAndValidateFfmpegVersion();
@@ -156,6 +162,10 @@ export const render = async () => {
? absoluteOutputFile
: await fs.promises.mkdtemp(path.join(os.tmpdir(), 'react-motion-render'));
+ if (!outputDir) {
+ throw new Error('Assertion error: Expected outputDir to not be null');
+ }
+
Log.verbose('Output dir', outputDir);
const renderProgress = createOverwriteableCliOutput();
diff --git a/packages/lambda/src/api/bundle-lambda.ts b/packages/lambda/src/api/bundle-lambda.ts
index 9efe2c4815..287a623674 100644
--- a/packages/lambda/src/api/bundle-lambda.ts
+++ b/packages/lambda/src/api/bundle-lambda.ts
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
+import {tmpDir} from '../shared/tmpdir';
import esbuild = require('esbuild');
import zl = require('zip-lib');
@@ -24,7 +25,7 @@ export const bundleLambda = async (type: 'render') => {
entryPoints: [template],
});
- const out = path.join(process.cwd(), `function-${type}.zip`);
+ const out = path.join(tmpDir('remotion-fn'), `function-${type}.zip`);
await zl.archiveFolder(outdir, out);
return out;
};
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index 003870fe5e..621d29af9b 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -6,7 +6,6 @@ export const REGION: AwsRegion = 'eu-central-1';
// TODO: Rename other buckets in Jonnys accoudn first
export const REMOTION_BUCKET_PREFIX = 'remotionlambda-';
export const RENDER_FN_PREFIX = 'remotion-render-';
-export const EFS_MOUNT_PATH = '/mnt/efs';
export const rendersPrefix = (renderId: string) => `renders/${renderId}`;
export const encodingProgressKey = (renderId: string) =>
`${rendersPrefix(renderId)}/encoding-progress.json`;
diff --git a/packages/lambda/src/shared/tmpdir.ts b/packages/lambda/src/shared/tmpdir.ts
index 02ff02ba33..76a7e1c317 100644
--- a/packages/lambda/src/shared/tmpdir.ts
+++ b/packages/lambda/src/shared/tmpdir.ts
@@ -1,4 +1,6 @@
-import {mkdirSync, mkdtempSync} from 'fs';
+import {mkdirSync} from 'fs';
+import os from 'os';
+import path from 'path';
import {randomHash} from './random-hash';
const isLambda = Boolean(process.env.LAMBDA_TASK_ROOT);
@@ -7,9 +9,10 @@ export const tmpDir = (str: string) => {
if (isLambda) {
const dir = '/tmp/' + str + randomHash();
mkdirSync(dir);
-
return dir;
}
- return mkdtempSync(str);
+ const newDir = path.join(os.tmpdir(), str + randomHash());
+ mkdirSync(newDir);
+ return newDir;
};