Skip to content

🎥 Make videos programmatically with React

add working test

Alex Fernandezb05ad07a9f97
diff --git a/packages/it-tests/src/monorepo/python-package.test.ts b/packages/it-tests/src/monorepo/python-package.test.ts
index c96b688f2d..1d7d9f3211 100644
--- a/packages/it-tests/src/monorepo/python-package.test.ts
+++ b/packages/it-tests/src/monorepo/python-package.test.ts
@@ -4,6 +4,7 @@ import path from "path";
import { expect, test } from "vitest";
import { LambdaInternals } from "@remotion/lambda";
+const PYTHON_OUTPUT_MARKER = 11;
const referenceVersion = readFileSync(
path.join(process.cwd(), "..", "core", "package.json"),
"utf-8"
@@ -32,13 +33,13 @@ test("Set the right version for pytest", () => {
test("Python package should create the same renderMedia payload as normal Lambda package", async () => {
const cwd = path.join(process.cwd(), "..", "lambda-python");
const pythonOutput = execSync(
- "python -m pytest -rP tests/test_render_client.py",
+ "python -m pytest -rP tests/test_render_client_render_media.py",
{
cwd,
}
);
const output = pythonOutput.toString().split("\n");
- const toParse = output[10];
+ const toParse = output[PYTHON_OUTPUT_MARKER];
const nativeVersion = await LambdaInternals.makeLambdaRenderMediaPayload({
region: "us-east-1",
composition: "react-svg",
@@ -104,7 +105,7 @@ test("Python package should create the same progress payload as normal Lambda pa
}
);
const output = pythonOutput.toString().split("\n");
- const toParse = output[10];
+ const toParse = output[PYTHON_OUTPUT_MARKER];
const nativeVersion = LambdaInternals.getRenderProgressPayload({
region: "us-east-1",
functionName: "remotion-render",
@@ -116,6 +117,57 @@ test("Python package should create the same progress payload as normal Lambda pa
expect(parsedJson).toEqual({ ...nativeVersion, s3OutputProvider: null });
});
+test("Python package should create the same renderStill payload as normal Lambda package", async () => {
+ const cwd = path.join(process.cwd(), "..", "lambda-python");
+ const pythonOutput = execSync(
+ "python -m pytest -rP tests/test_render_client_render_still.py",
+ {
+ cwd,
+ }
+ );
+ const output = pythonOutput.toString().split("\n");
+ const toParse = output[PYTHON_OUTPUT_MARKER];
+ const nativeVersion = await LambdaInternals.makeLambdaRenderStillPayload({
+ region: "us-east-1",
+ composition: "still-helloworld",
+ functionName: "remotion-render",
+ serveUrl: "testbed",
+ inputProps: {
+ message: "Hello from props!",
+ },
+ chromiumOptions: {},
+ deleteAfter: null,
+ downloadBehavior: { type: "play-in-browser" },
+ envVariables: {},
+ forceBucketName: undefined,
+ forceHeight: null,
+ forceWidth: null,
+ imageFormat: "jpeg",
+ jpegQuality: 80,
+ logLevel: "info",
+ maxRetries: 1,
+ offthreadVideoCacheSizeInBytes: null,
+ outName: undefined,
+ privacy: "public",
+ scale: 1,
+ timeoutInMilliseconds: 30000,
+ videoBitrate: null,
+ });
+ const jsonOutput = toParse.substring(0, toParse.lastIndexOf("}") + 1);
+ const parsedJson = JSON.parse(jsonOutput);
+ // remove the bucketName field because request input does not have that value
+ // forceBucketName is being set in bucketName
+ const { bucketName, ...newObject } = nativeVersion;
+ const assertValue = {
+ ...newObject,
+ forceBucketName: nativeVersion.bucketName,
+ };
+ expect(
+ removeUndefined({
+ ...parsedJson,
+ })
+ ).toEqual(removeUndefined(assertValue));
+});
const removeUndefined = (data: unknown) => {
return JSON.parse(JSON.stringify(data));
};
diff --git a/packages/lambda-python/build.mjs b/packages/lambda-python/build.mjs
index 7ae1e0b4fa..ac89f196e1 100644
--- a/packages/lambda-python/build.mjs
+++ b/packages/lambda-python/build.mjs
@@ -19,7 +19,7 @@ if (!hasPython()) {
const commands = [
"python -m venv remotion-env-lint",
". ./remotion-env-lint/bin/activate",
- "pip install boto3 pylint attr",
+ "pip install boto3 pylint",
"pylint ./remotion_lambda",
"deactivate",
"rm -rf remotion-env-lint",
diff --git a/packages/lambda-python/remotion_lambda/__init__.py b/packages/lambda-python/remotion_lambda/__init__.py
index b2755bde36..98dbd94a6b 100644
--- a/packages/lambda-python/remotion_lambda/__init__.py
+++ b/packages/lambda-python/remotion_lambda/__init__.py
@@ -1,8 +1,8 @@
# pylint: disable=missing-module-docstring
from .models import (
- RenderParams, RenderProgress,
- RenderResponse, RenderProgressParams,
- RenderStillParams
+ RenderMediaParams, RenderMediaProgress,
+ RenderMediaResponse, RenderProgressParams,
+ RenderStillParams, RenderStillResponse
)
from .remotionclient import RemotionClient
from .version import VERSION
diff --git a/packages/lambda-python/remotion_lambda/models.py b/packages/lambda-python/remotion_lambda/models.py
index f821e355b6..3be7249e0e 100644
--- a/packages/lambda-python/remotion_lambda/models.py
+++ b/packages/lambda-python/remotion_lambda/models.py
@@ -87,7 +87,7 @@ class ChromiumOptions:
"""
ignore_certificate_errors: Optional[bool] = None
disable_web_security: Optional[bool] = None
- gl: Optional[OpenGlRenderer] = OpenGlRenderer.SWANGLE
+ gl: Optional[OpenGlRenderer] = None
headless: Optional[bool] = None
user_agent: Optional[str] = None
enable_multi_process_on_linux: Optional[bool] = None
@@ -173,8 +173,61 @@ class DeleteAfter(Enum):
THIRTY_DAYS = '30-days'
+# pylint: disable=too-many-instance-attributes
+class RenderMediaResponse:
+ """
+ Response data after rendering.
+ """
+
+ def __init__(self, bucketName, renderId):
+ self.bucketName = bucketName
+ self.renderId = renderId
+
+
@dataclass
-class RenderParams:
+class RenderProgressParams:
+ """
+ Parameters for checking the progress of video rendering.
+ """
+
+ render_id: str
+ bucket_name: str
+ function_name: str
+ region: str
+
+ def serialize_params(self) -> Dict:
+ """
+ Convert instance attributes to a dictionary for serialization.
+ """
+ parameters = {
+ 'renderId': self.render_id,
+ 'bucketName': self.bucket_name,
+ 'type': 'status',
+ "version": VERSION,
+ "s3OutputProvider": None,
+ }
+ return parameters
+
+
+@dataclass
+class CostsInfo:
+ """
+ Represents the cost-related information for a specific service or product.
+
+ Attributes:
+ accrued_so_far (float): The total cost that has been accrued so far.
+ display_cost (str): The cost displayed to the user, possibly formatted as a string.
+ currency (str): The type of currency used for the costs, e.g., 'USD', 'EUR'.
+ disclaimer (str): Any disclaimer or additional information related to the costs.
+ """
+ accrued_so_far: float
+ display_cost: str
+ currency: str
+ disclaimer: str
+
+
+@dataclass
+class RenderMediaParams:
"""
Parameters for video rendering.
"""
@@ -188,17 +241,17 @@ class RenderParams:
private_serialized_input_props: Optional[Dict] = None
codec: str = 'h264'
version: str = ""
- image_format: str = 'jpeg'
+ image_format: ValidStillImageFormats = ValidStillImageFormats.JPEG
crf: Optional[int] = None
env_variables: Optional[Dict] = None
max_retries: int = 1
jpeg_quality: int = 80
- privacy: str = 'public'
+ privacy: Privacy = Privacy.PUBLIC
color_space: str = 'default'
- log_level: str = 'info'
+ log_level: Optional[LogLevel] = LogLevel.INFO
frame_range: Optional[str] = None
timeout_in_milliseconds: Optional[int] = 30000
- chromium_options: Optional[Dict] = None
+ chromium_options: Optional[ChromiumOptions] = None
scale: Optional[int] = 1
every_nth_frame: Optional[int] = 1
number_of_gif_loops: Optional[int] = 0
@@ -285,81 +338,6 @@ class RenderParams:
return parameters
-# pylint: disable=too-many-instance-attributes
-class RenderResponse:
- """
- Response data after rendering.
- """
-
- def __init__(self, bucketName, renderId):
- self.bucketName = bucketName
- self.renderId = renderId
-
-
-@dataclass
-class RenderProgressParams:
- """
- Parameters for checking the progress of video rendering.
- """
-
- render_id: str
- bucket_name: str
- function_name: str
- region: str
-
- def serialize_params(self) -> Dict:
- """
- Convert instance attributes to a dictionary for serialization.
- """
- parameters = {
- 'renderId': self.render_id,
- 'bucketName': self.bucket_name,
- 'type': 'status',
- "version": VERSION,
- "s3OutputProvider": None,
- }
- return parameters
-
-
-@dataclass
-class CostsInfo:
- """
- Represents the cost-related information for a specific service or product.
-
- Attributes:
- accrued_so_far (float): The total cost that has been accrued so far.
- display_cost (str): The cost displayed to the user, possibly formatted as a string.
- currency (str): The type of currency used for the costs, e.g., 'USD', 'EUR'.
- disclaimer (str): Any disclaimer or additional information related to the costs.
- """
- accrued_so_far: float
- display_cost: str
- currency: str
- disclaimer: str
-
-
-@dataclass
-class RenderStillOnLambdaOutput:
- """
- Represents the output information of a rendering operation performed on AWS Lambda.
-
- Attributes:
- estimated_price (CostsInfo):
- An object containing detailed cost information related to the rendering.
- url (str): The URL where the rendered image is stored or can be accessed.
- size_in_bytes (int): The size of the rendered image file in bytes.
- bucket_name (str): The name of the S3 bucket where the rendered image is stored.
- render_id (str): A unique identifier for the rendering operation.
- cloud_watch_logs (str): The CloudWatch logs associated with the rendering operation.
- """
- estimated_price: CostsInfo
- url: str
- size_in_bytes: int
- bucket_name: str
- render_id: str
- cloud_watch_logs: Optional[str] = None
-
-
@dataclass
class RenderStillParams:
"""
@@ -380,9 +358,7 @@ class RenderStillParams:
log_level: Optional[LogLevel] = LogLevel.INFO
out_name: Optional[Union[str, OutNameInputObject]] = None
timeout_in_milliseconds: Optional[int] = 30000
- chromium_options: Optional[ChromiumOptions] = field(
- default_factory=lambda: ChromiumOptions()
- )
+ chromium_options: Optional[ChromiumOptions] = None
scale: Optional[float] = 1
download_behavior: Dict = field(default_factory=lambda: {
'type': 'play-in-browser'})
@@ -391,6 +367,7 @@ class RenderStillParams:
force_bucket_name: Optional[str] = None
dump_browser_logs: Optional[bool] = None
delete_after: Optional[DeleteAfter] = None
+ offthreadvideo_cache_size_in_bytes: Optional[int] = None
def serialize_params(self) -> Dict:
"""
@@ -403,7 +380,7 @@ class RenderStillParams:
The optional attributes include maxRetries, envVariables, jpegQuality, frame,
logLevel, outName, timeoutInMilliseconds, chromiumOptions, scale, downloadBehavior,
- forceWidth, forceHeight, forceBucketName, dumpBrowserLogs, and deleteAfter.
+ forceWidth, forceHeight, forceBucketName, and deleteAfter.
Default values are provided for 'inputProps' (empty dictionary) and 'downloadBehavior'
('type': 'play-in-browser') if they are not explicitly set.
@@ -411,35 +388,57 @@ class RenderStillParams:
Dict: A dictionary containing all the serialized parameters of the object.
"""
parameters = {
+ 'type': 'still',
'composition': self.composition,
'inputProps': self.private_serialized_input_props or {},
'imageFormat': self.image_format,
'privacy': self.privacy,
'serveUrl': self.serve_url,
'version': VERSION,
- 'type': 'still',
'timeoutInMilliseconds': self.timeout_in_milliseconds,
'maxRetries': self.max_retries,
- 'envVariables': self.env_variables,
+ 'envVariables': self.env_variables if self.env_variables is not None else {},
'jpegQuality': self.jpeg_quality,
'frame': self.frame,
'logLevel': self.log_level,
'outName': self.out_name,
- 'chromiumOptions': self.chromium_options,
+ 'chromiumOptions': self.chromium_options if self.chromium_options is not None else {},
'scale': self.scale,
'downloadBehavior': self.download_behavior or {'type': 'play-in-browser'},
'forceWidth': self.force_width,
'forceHeight': self.force_height,
'forceBucketName': self.force_bucket_name,
- 'dumpBrowserLogs': self.dump_browser_logs,
'deleteAfter': self.delete_after,
- 'attempt': self.attempt
+ 'attempt': self.attempt,
+ 'offthreadVideoCacheSizeInBytes': self.offthreadvideo_cache_size_in_bytes
}
return parameters
-class RenderProgress:
+@dataclass
+class RenderStillResponse:
+ """
+ Represents the output information of a rendering operation performed on AWS Lambda.
+
+ Attributes:
+ estimated_price (CostsInfo):
+ An object containing detailed cost information related to the rendering.
+ url (str): The URL where the rendered image is stored or can be accessed.
+ size_in_bytes (int): The size of the rendered image file in bytes.
+ bucket_name (str): The name of the S3 bucket where the rendered image is stored.
+ render_id (str): A unique identifier for the rendering operation.
+ cloud_watch_logs (str): The CloudWatch logs associated with the rendering operation.
+ """
+ estimated_price: CostsInfo
+ url: str
+ size_in_bytes: int
+ bucket_name: str
+ render_id: str
+ cloud_watch_logs: Optional[str] = None
+
+
+class RenderMediaProgress:
"""
Progress of video rendering.
"""
diff --git a/packages/lambda-python/remotion_lambda/remotionclient.py b/packages/lambda-python/remotion_lambda/remotionclient.py
index 068ff1b123..ea553f0bf5 100644
--- a/packages/lambda-python/remotion_lambda/remotionclient.py
+++ b/packages/lambda-python/remotion_lambda/remotionclient.py
@@ -1,12 +1,12 @@
# pylint: disable=too-few-public-methods, missing-module-docstring, broad-exception-caught
-from dataclasses import asdict, is_dataclass
+from dataclasses import asdict
import json
from math import ceil
from typing import Union, Literal
from enum import Enum
import boto3
-from .models import (CostsInfo, RenderParams, RenderProgress,
- RenderResponse, RenderProgressParams, RenderStillOnLambdaOutput,
+from .models import (CostsInfo, RenderMediaParams, RenderMediaProgress,
+ RenderMediaResponse, RenderProgressParams, RenderStillResponse,
RenderStillParams)
@@ -106,7 +106,7 @@ class RemotionClient:
response = client.invoke(
FunctionName=function_name, Payload=payload, )
result = response['Payload'].read().decode('utf-8')
- decoded_result = (self._parse_stream(result)[-1])
+ decoded_result = self._parse_stream(result)[-1]
if 'errorMessage' in decoded_result:
raise ValueError(decoded_result['errorMessage'])
@@ -122,14 +122,13 @@ class RemotionClient:
if isinstance(obj, Enum):
return obj.value if hasattr(obj, 'value') else obj.name
- elif hasattr(obj, '__dict__'):
+ if hasattr(obj, '__dict__'):
return obj.__dict__
- elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
+ if hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
return list(obj)
- else:
- return asdict(obj)
+ return asdict(obj)
- def construct_render_request(self, render_params: Union[RenderParams, RenderStillParams],
+ def construct_render_request(self, render_params: Union[RenderMediaParams, RenderStillParams],
render_type:
Union[Literal["video-or-audio"], Literal["still"]]) -> str:
"""
@@ -170,7 +169,7 @@ class RemotionClient:
)
return json.dumps(progress_params.serialize_params())
- def render_media_on_lambda(self, render_params: RenderParams) -> RenderResponse:
+ def render_media_on_lambda(self, render_params: RenderMediaParams) -> RenderMediaResponse:
"""
Render media using AWS Lambda.
@@ -185,11 +184,11 @@ class RemotionClient:
body_object = self._invoke_lambda(
function_name=self.function_name, payload=params)
if body_object:
- return RenderResponse(body_object['bucketName'], body_object['renderId'])
+ return RenderMediaResponse(body_object['bucketName'], body_object['renderId'])
return None
- def render_still_on_lambda(self, render_params: RenderStillParams) -> RenderResponse:
+ def render_still_on_lambda(self, render_params: RenderStillParams) -> RenderStillResponse:
"""
Render still using AWS Lambda.
@@ -206,7 +205,7 @@ class RemotionClient:
function_name=self.function_name, payload=params)
if body_object:
- return RenderStillOnLambdaOutput(
+ return RenderStillResponse(
estimated_price=CostsInfo(
accrued_so_far=body_object['estimatedPrice']['accruedSoFar'],
display_cost=body_object['estimatedPrice']['displayCost'],
@@ -222,7 +221,7 @@ class RemotionClient:
return None
- def get_render_progress(self, render_id: str, bucket_name: str) -> RenderProgress:
+ def get_render_progress(self, render_id: str, bucket_name: str) -> RenderMediaProgress:
"""
Get the progress of a render.
@@ -237,7 +236,7 @@ class RemotionClient:
progress_response = self._invoke_lambda(
function_name=self.function_name, payload=params)
if progress_response:
- render_progress = RenderProgress()
+ render_progress = RenderMediaProgress()
render_progress.__dict__.update(progress_response)
return render_progress
return None
diff --git a/packages/lambda-python/tests/test_render_client.py b/packages/lambda-python/tests/test_render_client_render_media.py
similarity index 73%
rename from packages/lambda-python/tests/test_render_client.py
rename to packages/lambda-python/tests/test_render_client_render_media.py
index 5e1de1c4df..c82d4c7c57 100644
--- a/packages/lambda-python/tests/test_render_client.py
+++ b/packages/lambda-python/tests/test_render_client_render_media.py
@@ -1,6 +1,6 @@
from unittest import TestCase
-from remotion_lambda.models import RenderParams
+from remotion_lambda.models import RenderMediaParams
from remotion_lambda.remotionclient import RemotionClient
@@ -9,7 +9,7 @@ class TestRemotionClient(TestCase):
client = RemotionClient(region="us-east-1",
serve_url="testbed",
function_name="remotion-render")
- render_params = RenderParams(
+ render_params = RenderMediaParams(
composition="react-svg",
data={
'hi': 'there'
@@ -19,4 +19,5 @@ class TestRemotionClient(TestCase):
self.assertEqual(client.region, "us-east-1")
self.assertIsNotNone(render_params)
self.assertIsNotNone(render_params.data)
- print(client.construct_render_request(render_params=render_params))
+ print(client.construct_render_request(
+ render_params=render_params, render_type="video-or-audio"))
diff --git a/packages/lambda-python/tests/test_render_client_render_still.py b/packages/lambda-python/tests/test_render_client_render_still.py
new file mode 100644
index 0000000000..b899286bbb
--- /dev/null
+++ b/packages/lambda-python/tests/test_render_client_render_still.py
@@ -0,0 +1,23 @@
+from unittest import TestCase
+
+from remotion_lambda.models import RenderStillParams
+from remotion_lambda.remotionclient import RemotionClient
+
+
+class TestRemotionClient(TestCase):
+ def test_remotion_construct_request(self):
+ client = RemotionClient(region="us-east-1",
+ serve_url="testbed",
+ function_name="remotion-render")
+ render_still_params = RenderStillParams(
+ composition="still-helloworld",
+ data={
+ 'message': 'Hello from props!'
+ },
+ )
+
+ self.assertEqual(client.region, "us-east-1")
+ self.assertIsNotNone(render_still_params)
+ self.assertIsNotNone(render_still_params.data)
+ print(client.construct_render_request(
+ render_params=render_still_params, render_type='still'))
diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.ts
index 043787a8b5..48836a2ae6 100644
--- a/packages/lambda/src/api/make-lambda-payload.ts
+++ b/packages/lambda/src/api/make-lambda-payload.ts
@@ -12,15 +12,16 @@ import type {
} from '@remotion/renderer';
import type {BrowserSafeApis} from '@remotion/renderer/client';
import {VERSION} from 'remotion/version';
-import type {AwsRegion, DeleteAfter} from '../client';
+import type {AwsRegion, DeleteAfter, RenderStillOnLambdaInput} from '../client';
import type {
+ LambdaPayloads,
LambdaStartPayload,
LambdaStatusPayload,
OutNameInput,
Privacy,
WebhookOption,
} from '../defaults';
-import {LambdaRoutines} from '../defaults';
+import {DEFAULT_MAX_RETRIES, LambdaRoutines} from '../defaults';
import {
compressInputProps,
getNeedsToUpload,
@@ -201,3 +202,71 @@ export const getRenderProgressPayload = ({
s3OutputProvider,
};
};
+
+export const makeLambdaRenderStillPayload = async ({
+ serveUrl,
+ inputProps,
+ imageFormat,
+ envVariables,
+ quality,
+ jpegQuality,
+ region,
+ maxRetries,
+ composition,
+ privacy,
+ frame,
+ logLevel,
+ outName,
+ timeoutInMilliseconds,
+ chromiumOptions,
+ scale,
+ downloadBehavior,
+ forceHeight,
+ forceWidth,
+ forceBucketName,
+ dumpBrowserLogs,
+ offthreadVideoCacheSizeInBytes,
+ deleteAfter,
+}: RenderStillOnLambdaInput): Promise<LambdaPayloads[LambdaRoutines.still]> => {
+ if (quality) {
+ throw new Error(
+ 'The `quality` option is deprecated. Use `jpegQuality` instead.',
+ );
+ }
+
+ const stringifiedInputProps = serializeOrThrow(inputProps, 'input-props');
+
+ const serializedInputProps = await compressInputProps({
+ stringifiedInputProps,
+ region,
+ needsToUpload: getNeedsToUpload('still', [stringifiedInputProps.length]),
+ userSpecifiedBucketName: forceBucketName ?? null,
+ propsType: 'input-props',
+ });
+
+ return {
+ composition,
+ serveUrl,
+ inputProps: serializedInputProps,
+ imageFormat,
+ envVariables,
+ jpegQuality,
+ maxRetries: maxRetries ?? DEFAULT_MAX_RETRIES,
+ frame: frame ?? 0,
+ privacy,
+ attempt: 1,
+ logLevel: dumpBrowserLogs ? 'verbose' : logLevel ?? 'info',
+ outName: outName ?? null,
+ timeoutInMilliseconds: timeoutInMilliseconds ?? 30000,
+ chromiumOptions: chromiumOptions ?? {},
+ scale: scale ?? 1,
+ downloadBehavior: downloadBehavior ?? {type: 'play-in-browser'},
+ version: VERSION,
+ forceHeight: forceHeight ?? null,
+ forceWidth: forceWidth ?? null,
+ bucketName: forceBucketName ?? null,
+ offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
+ deleteAfter: deleteAfter ?? null,
+ type: LambdaRoutines.still,
+ };
+};
diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.ts
index dbb842ca04..ed665cf378 100644
--- a/packages/lambda/src/api/render-still-on-lambda.ts
+++ b/packages/lambda/src/api/render-still-on-lambda.ts
@@ -6,22 +6,17 @@ import type {
} from '@remotion/renderer';
import type {BrowserSafeApis} from '@remotion/renderer/client';
import {PureJSAPIs} from '@remotion/renderer/pure';
-import {VERSION} from 'remotion/version';
import type {DeleteAfter} from '../functions/helpers/lifecycle';
import type {AwsRegion} from '../pricing/aws-regions';
import {callLambda} from '../shared/call-lambda';
-import {
- compressInputProps,
- getNeedsToUpload,
- serializeOrThrow,
-} from '../shared/compress-props';
import type {CostsInfo, OutNameInput, Privacy} from '../shared/constants';
-import {DEFAULT_MAX_RETRIES, LambdaRoutines} from '../shared/constants';
+import {LambdaRoutines} from '../shared/constants';
import type {DownloadBehavior} from '../shared/content-disposition-header';
import {
getCloudwatchMethodUrl,
getLambdaInsightsUrl,
} from '../shared/get-aws-urls';
+import {makeLambdaRenderStillPayload} from './make-lambda-payload';
export type RenderStillOnLambdaInput = {
region: AwsRegion;
@@ -69,77 +64,15 @@ export type RenderStillOnLambdaOutput = {
cloudWatchLogs: string;
};
-const renderStillOnLambdaRaw = async ({
- functionName,
- serveUrl,
- inputProps,
- imageFormat,
- envVariables,
- quality,
- jpegQuality,
- region,
- maxRetries,
- composition,
- privacy,
- frame,
- logLevel,
- outName,
- timeoutInMilliseconds,
- chromiumOptions,
- scale,
- downloadBehavior,
- forceHeight,
- forceWidth,
- forceBucketName,
- dumpBrowserLogs,
- onInit,
- offthreadVideoCacheSizeInBytes,
- deleteAfter,
-}: RenderStillOnLambdaInput): Promise<RenderStillOnLambdaOutput> => {
- if (quality) {
- throw new Error(
- 'The `quality` option is deprecated. Use `jpegQuality` instead.',
- );
- }
-
- const stringifiedInputProps = serializeOrThrow(inputProps, 'input-props');
-
- const serializedInputProps = await compressInputProps({
- stringifiedInputProps,
- region,
- needsToUpload: getNeedsToUpload('still', [stringifiedInputProps.length]),
- userSpecifiedBucketName: forceBucketName ?? null,
- propsType: 'input-props',
- });
-
+const renderStillOnLambdaRaw = async (
+ input: RenderStillOnLambdaInput,
+): Promise<RenderStillOnLambdaOutput> => {
+ const {functionName, region, onInit} = input;
try {
const res = await callLambda({
functionName,
type: LambdaRoutines.still,
- payload: {
- composition,
- serveUrl,
- inputProps: serializedInputProps,
- imageFormat,
- envVariables,
- jpegQuality,
- maxRetries: maxRetries ?? DEFAULT_MAX_RETRIES,
- frame: frame ?? 0,
- privacy,
- attempt: 1,
- logLevel: dumpBrowserLogs ? 'verbose' : logLevel ?? 'info',
- outName: outName ?? null,
- timeoutInMilliseconds: timeoutInMilliseconds ?? 30000,
- chromiumOptions: chromiumOptions ?? {},
- scale: scale ?? 1,
- downloadBehavior: downloadBehavior ?? {type: 'play-in-browser'},
- version: VERSION,
- forceHeight: forceHeight ?? null,
- forceWidth: forceWidth ?? null,
- bucketName: forceBucketName ?? null,
- offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
- deleteAfter: deleteAfter ?? null,
- },
+ payload: await makeLambdaRenderStillPayload(input),
region,
receivedStreamingPayload: (payload) => {
if (payload.type === 'render-id-determined') {
diff --git a/packages/lambda/src/internals.ts b/packages/lambda/src/internals.ts
index 0bcea9632d..4a9f8f20b5 100644
--- a/packages/lambda/src/internals.ts
+++ b/packages/lambda/src/internals.ts
@@ -1,6 +1,7 @@
import {
getRenderProgressPayload,
makeLambdaRenderMediaPayload,
+ makeLambdaRenderStillPayload,
} from './api/make-lambda-payload';
import {executeCommand} from './cli/index';
@@ -8,4 +9,5 @@ export const LambdaInternals = {
executeCommand,
makeLambdaRenderMediaPayload,
getRenderProgressPayload,
+ makeLambdaRenderStillPayload,
};