Skip to content

🎥 Make videos programmatically with React

further support of disk size

Jonny Burger09317cfbfbde
diff --git a/packages/docs/components/lambda/default-disk-size.tsx b/packages/docs/components/lambda/default-disk-size.tsx
new file mode 100644
index 0000000000..4679d13dd3
--- /dev/null
+++ b/packages/docs/components/lambda/default-disk-size.tsx
@@ -0,0 +1,6 @@
+import { DEFAULT_EPHEMERAL_STORAGE_IN_MB } from "@remotion/lambda/dist/defaults";
+import React from "react";
+
+export const DefaultEphemerealStorageInMb: React.FC = () => {
+ return <span>{DEFAULT_EPHEMERAL_STORAGE_IN_MB}</span>;
+};
diff --git a/packages/docs/docs/lambda.md b/packages/docs/docs/lambda.md
index db6281ac1f..b3fc145b24 100644
--- a/packages/docs/docs/lambda.md
+++ b/packages/docs/docs/lambda.md
@@ -16,7 +16,7 @@ import {LambdaRegionList} from '../components/lambda/regions.tsx';
## When should I use it?
-- Your videos are less than 8 minutes long. <sub>(AWS Lambda storage constraint)</sub>
+- Your videos are less than 2 hours long. <sub>(AWS Lambda storage constraint)</sub>
- You are rendering less than 1 hour of video per minute. <sub>(AWS Lambda Burst Limit / Concurrency constraint)</sub>
- You are fine with using Amazon Web Services in one of the [supported regions](/docs/lambda/region-selection).
diff --git a/packages/docs/docs/lambda/cli/functions.md b/packages/docs/docs/lambda/cli/functions.md
index 187f5b57e8..925d9ba577 100644
--- a/packages/docs/docs/lambda/cli/functions.md
+++ b/packages/docs/docs/lambda/cli/functions.md
@@ -6,6 +6,7 @@ slug: /lambda/cli/functions
---
import {DefaultMemorySize} from '../../../components/lambda/default-memory-size';
+import {DefaultEphemerealStorageInMb} from '../../../components/lambda/default-disk-size';
import {DefaultTimeout} from '../../../components/lambda/default-timeout';
import {DefaultLogRetention} from '../../../components/lambda/default-log-retention';
import {DefaultArchitecture} from '../../../components/lambda/default-architecture';
@@ -36,6 +37,7 @@ Example output
<pre>
Region = eu-central-1,
Memory = 2048MB,
+Disk = 512MB,
Timeout = 120sec,
Version = 2021-12-17,
CloudWatch Enabled = true,
@@ -55,6 +57,10 @@ The [AWS region](/docs/lambda/region-selection) to select.
Memory size in megabytes. Default: <DefaultMemorySize /> MB.
+### `--disk`
+
+Disk size in megabytes. Default: <DefaultEphemerealStorageInMb /> MB. See also: [Disk size](/docs/lambda/disk-size).
+
### `--timeout`
Memory size in megabytes. Default: <DefaultTimeout /> seconds.
diff --git a/packages/docs/docs/lambda/deployfunction.md b/packages/docs/docs/lambda/deployfunction.md
index 140856d3e0..cd25097aa9 100644
--- a/packages/docs/docs/lambda/deployfunction.md
+++ b/packages/docs/docs/lambda/deployfunction.md
@@ -56,9 +56,9 @@ Whether logs should be saved into CloudWatch. We recommend enabling this option.
Optional. Retention period for the CloudWatch Logs. Default: 14 days.
-### `diskSizeInMb`
+### `diskSizeInMb`
-Optional. Sets the amount of disk storage that is available in the Lambda function. Must be between 512MB and 10240MB (10GB). Set this higher if you want to render longer videos.
+Optional. Sets the amount of disk storage that is available in the Lambda function. Must be between 512MB and 10240MB (10GB). Set this higher if you want to render longer videos. See also: [Disk size](/docs/lambda/disk-size)
## Return value
diff --git a/packages/docs/docs/lambda/disk-size.md b/packages/docs/docs/lambda/disk-size.md
index be0fdef216..36a44a7d3b 100644
--- a/packages/docs/docs/lambda/disk-size.md
+++ b/packages/docs/docs/lambda/disk-size.md
@@ -10,3 +10,26 @@ If you want to render longer videos, you can increase the disk size, and [potent
Disk space need increases linearly with the length of your video, meaning that for each 8 minutes of Full HD video, you approximately need another 512MB of video.
The minimum disk size is 512MB, and the maximum disk size is 10240MB.
+
+The approximate maximum video duration length is therefore around ~160 minutes at Full HD (not yet practically confirmed).
+
+| Disk size | Approximate Maximum video length |
+| ---------------- | -------------------------------- |
+| 512 MB (default) | 8 min - 1080p |
+| 1024 MB | 16 min - 1080p |
+| 2048 MB | 32 min - 1080p |
+| 4096 MB | 1h 4min - 1080p |
+| 8192 MB | 2h 8min - 1080p |
+| 10240 MB | 2h 40min - 1080p |
+
+> These are approximate values and will not exactly match your scenario. Video output size is dependant on the video content and audio. Measure and find the values that work best for you.
+
+## Setting the disk size
+
+- Use the [`diskSizeInMb` option of `deployFunction()`](/docs/lambda/deployfunction#disksizeinmb) to set the disk size when you deploy.
+- Use the [`--disk`](/docs/lambda/cli/functions) flag if you use the `remotion lambda functions deploy` command.
+
+## Pricing
+
+Using more disk space costs more. See the [Lambda pricing page](https://aws.amazon.com/lambda/pricing/) "Lambda Ephemereal Storage Pricing" section for pricing.
+The [`estimatePrice()`](/docs/lambda/estimateprice) API does also factor disk size into account.
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index 0381e08a58..41a38bc0cd 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -49,13 +49,14 @@ export type DeployFunctionOutput = {
export const deployFunction = async (
options: DeployFunctionInput
): Promise<DeployFunctionOutput> => {
+ const diskSizeInMb = options.diskSizeInMb ?? DEFAULT_EPHEMERAL_STORAGE_IN_MB;
+
validateMemorySize(options.memorySizeInMb);
validateTimeout(options.timeoutInSeconds);
validateAwsRegion(options.region);
validateCloudWatchRetentionPeriod(options.cloudWatchLogRetentionPeriodInDays);
validateArchitecture(options.architecture);
- validateDiskSizeInMb(options.diskSizeInMb);
- const diskSizeInMb = options.diskSizeInMb ?? DEFAULT_EPHEMERAL_STORAGE_IN_MB;
+ validateDiskSizeInMb(diskSizeInMb);
const fnNameRender = [
`${RENDER_FN_PREFIX}${CURRENT_VERSION}`,
@@ -75,7 +76,7 @@ export const deployFunction = async (
f.version === CURRENT_VERSION &&
f.memorySizeInMb === options.memorySizeInMb &&
f.timeoutInSeconds === options.timeoutInSeconds &&
- f.diskSizeInMb === options.diskSizeInMb
+ f.diskSizeInMb === diskSizeInMb
);
const created = await createFunction({
diff --git a/packages/lambda/src/cli/args.ts b/packages/lambda/src/cli/args.ts
index fdd6543efd..5f8c37f941 100644
--- a/packages/lambda/src/cli/args.ts
+++ b/packages/lambda/src/cli/args.ts
@@ -8,6 +8,7 @@ type LambdaCommandLineOptions = {
help: boolean;
region: AwsRegion;
memory: number;
+ disk: number;
timeout: number;
['retention-period']: number;
y: boolean;
diff --git a/packages/lambda/src/cli/commands/functions/deploy.ts b/packages/lambda/src/cli/commands/functions/deploy.ts
index 72a0167656..fd872749d7 100644
--- a/packages/lambda/src/cli/commands/functions/deploy.ts
+++ b/packages/lambda/src/cli/commands/functions/deploy.ts
@@ -5,10 +5,12 @@ import {
CURRENT_VERSION,
DEFAULT_ARCHITECTURE,
DEFAULT_CLOUDWATCH_RETENTION_PERIOD,
+ DEFAULT_EPHEMERAL_STORAGE_IN_MB,
DEFAULT_MEMORY_SIZE,
DEFAULT_TIMEOUT,
} from '../../../shared/constants';
import {validateArchitecture} from '../../../shared/validate-architecture';
+import {validateDiskSizeInMb} from '../../../shared/validate-disk-size-in-mb';
import {validateMemorySize} from '../../../shared/validate-memory-size';
import {validateTimeout} from '../../../shared/validate-timeout';
import {parsedLambdaCli} from '../../args';
@@ -20,6 +22,7 @@ export const functionsDeploySubcommand = async () => {
const region = getAwsRegion();
const timeoutInSeconds = parsedLambdaCli.timeout ?? DEFAULT_TIMEOUT;
const memorySizeInMb = parsedLambdaCli.memory ?? DEFAULT_MEMORY_SIZE;
+ const diskSizeInMb = parsedLambdaCli.disk ?? DEFAULT_EPHEMERAL_STORAGE_IN_MB;
const architecture = parsedLambdaCli.architecture ?? DEFAULT_ARCHITECTURE;
const createCloudWatchLogGroup = !parsedLambdaCli['disable-cloudwatch'];
const cloudWatchLogRetentionPeriodInDays =
@@ -28,12 +31,14 @@ export const functionsDeploySubcommand = async () => {
validateMemorySize(memorySizeInMb);
validateTimeout(timeoutInSeconds);
validateArchitecture(architecture);
+ validateDiskSizeInMb(diskSizeInMb);
if (!CliInternals.quietFlagProvided()) {
Log.info(
CliInternals.chalk.gray(
`
Region = ${region}
Memory = ${memorySizeInMb}MB
+Disk size = ${diskSizeInMb}MB
Timeout = ${timeoutInSeconds}sec
Version = ${CURRENT_VERSION}
Architecture = ${architecture}
@@ -55,6 +60,7 @@ CloudWatch Retention Period = ${cloudWatchLogRetentionPeriodInDays} days
memorySizeInMb,
cloudWatchLogRetentionPeriodInDays,
architecture,
+ diskSizeInMb,
});
if (CliInternals.quietFlagProvided()) {
Log.info(functionName);
diff --git a/packages/lambda/src/cli/commands/functions/ls.ts b/packages/lambda/src/cli/commands/functions/ls.ts
index 28e364ac0f..27b5c69f49 100644
--- a/packages/lambda/src/cli/commands/functions/ls.ts
+++ b/packages/lambda/src/cli/commands/functions/ls.ts
@@ -5,6 +5,7 @@ import {getAwsRegion} from '../../get-aws-region';
const NAME_COLS = 50;
const MEMORY_COLS = 15;
+const DISK_COLS = 15;
const TIMEOUT_COLS = 15;
const VERSION_COLS = 15;
@@ -44,6 +45,7 @@ export const functionsLsCommand = async () => {
[
'Name'.padEnd(NAME_COLS, ' '),
'Version'.padEnd(VERSION_COLS, ' '),
+ 'Disk (MB)'.padEnd(MEMORY_COLS, ' '),
'Memory (MB)'.padEnd(MEMORY_COLS, ' '),
'Timeout (sec)'.padEnd(TIMEOUT_COLS, ' '),
].join('')
@@ -57,6 +59,7 @@ export const functionsLsCommand = async () => {
datapoint.version
? datapoint.version.padEnd(VERSION_COLS, ' ')
: 'Error'.padEnd(VERSION_COLS, ' '),
+ String(datapoint.diskSizeInMb).padEnd(DISK_COLS, ' '),
String(datapoint.memorySizeInMb).padEnd(MEMORY_COLS, ' '),
String(datapoint.timeoutInSeconds).padEnd(TIMEOUT_COLS, ' '),
].join('')
diff --git a/packages/lambda/src/shared/validate-disk-size-in-mb.ts b/packages/lambda/src/shared/validate-disk-size-in-mb.ts
index c1e697282c..fe6e60df3e 100644
--- a/packages/lambda/src/shared/validate-disk-size-in-mb.ts
+++ b/packages/lambda/src/shared/validate-disk-size-in-mb.ts
@@ -4,9 +4,6 @@ import {
} from './constants';
export const validateDiskSizeInMb = (diskSizeInMb: unknown) => {
- if (typeof diskSizeInMb === 'undefined') {
- return;
- }
if (typeof diskSizeInMb !== 'number') {
throw new TypeError(
`parameter 'diskSizeInMb' must be a number, got a ${typeof diskSizeInMb}`
diff --git a/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts b/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts
index a8058027cd..81e57ab628 100644
--- a/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts
+++ b/packages/lambda/src/test/unit/validate-disk-size-in-mb.test.ts
@@ -2,7 +2,6 @@ import {validateDiskSizeInMb} from '../../shared/validate-disk-size-in-mb';
import {expectToThrow} from '../helpers/expect-to-throw';
test('Disk size tests', () => {
- expect(() => validateDiskSizeInMb(undefined)).not.toThrow();
expect(() => validateDiskSizeInMb(512)).not.toThrow();
expect(() => validateDiskSizeInMb(10240)).not.toThrow();
expectToThrow(() => {