🎥 Make videos programmatically with React
write test for payload that gets generated
Jonny Burger6608a894dcc3
diff --git a/packages/goclient/goclient_test.go b/packages/goclient/goclient_test.goindex a586782635..9ae0c948e9 100644--- a/packages/goclient/goclient_test.go+++ b/packages/goclient/goclient_test.go@@ -12,6 +12,7 @@ func TestPrintVersion(t *testing.T) {Composition: "react-svg",FunctionName: "remotion-render",ServeUrl: "testbed",+ Codec: "h264",})if err != nil {log.Fatalf("Error marshaling struct to JSON: %v", err)diff --git a/packages/goclient/internalops.go b/packages/goclient/internalops.goindex 2453649de2..59434e564b 100644--- a/packages/goclient/internalops.go+++ b/packages/goclient/internalops.go@@ -128,20 +128,20 @@ func constructRenderInternals(options *RemotionOptions) (*renderInternalOptions,internalParams.Gl = options.Gl}- if &options.DownloadBehavior == nil {+ if options.DownloadBehavior == nil {internalParams.DownloadBehavior = map[string]interface{}{"type": "play-in-browser",}} else {internalParams.DownloadBehavior = options.DownloadBehavior}- if &options.ChromiumOptions == nil {+ if options.ChromiumOptions == nil {internalParams.ChromiumOptions = []interface{}{}} else {internalParams.ChromiumOptions = options.ChromiumOptions}- if &options.EnvVariables == nil {+ if options.EnvVariables == nil {internalParams.EnvVariables = []interface{}{}} else {internalParams.EnvVariables = options.EnvVariablesdiff --git a/packages/goclient/models.go b/packages/goclient/models.goindex aea1e8c9ee..78c5a6480a 100644--- a/packages/goclient/models.go+++ b/packages/goclient/models.go@@ -6,7 +6,7 @@ type RemotionOptions struct {Region string `json:"region" validate:"required"`InputProps interface{} `json:"inputProps"`Composition string `json:"composition" validate:"required"`- Codec string `json:"codec"`+ Codec string `json:"codec" validate:"required"`Version string `json:"version"`ImageFormat string `json:"imageFormat"`Crf int `json:"crf"`@@ -39,7 +39,6 @@ type RemotionOptions struct {type renderInternalOptions struct {ServeUrl string `json:"serveUrl" validate:"required"`- FunctionName string `json:"functionName" validate:"required"`Region string `json:"region" validate:"required"`InputProps interface{} `json:"inputProps"`Composition string `json:"composition" validate:"required"`diff --git a/packages/goclient/version.go b/packages/goclient/version.goindex 5ecb8645d4..fd473fb60e 100644--- a/packages/goclient/version.go+++ b/packages/goclient/version.go@@ -1,3 +1,3 @@-package goclient+package goclient;-const VERSION = "3.3.88"+const VERSION = "3.3.88"\ No newline at end of filediff --git a/packages/it-tests/src/monorepo/go-package.test.ts b/packages/it-tests/src/monorepo/go-package.test.tsindex 758b540056..fa71a891a7 100644--- a/packages/it-tests/src/monorepo/go-package.test.ts+++ b/packages/it-tests/src/monorepo/go-package.test.ts@@ -1,6 +1,8 @@+import { execSync } from "child_process";import { readFileSync, writeFileSync } from "fs";import path from "path";import { expect, test } from "vitest";+import { LambdaInternals } from "@remotion/lambda";test("Set the right version for gotest", () => {const referenceVersion = readFileSync(@@ -12,9 +14,28 @@ test("Set the right version for gotest", () => {const version = referenceVersionJson.version;expect(typeof version).toBe("string");- const VERSION = `const VERSION = "${version}"`;+ const VERSION = `package goclient;\n\nconst VERSION = "${version}"`;writeFileSync(path.join(process.cwd(), "..", "goclient", "version.go"),VERSION);});++test("Go package should create the same payload as normal Lambda package", async () => {+ const goOutput = execSync("go test", {+ cwd: path.join(process.cwd(), "..", "goclient"),+ });+ const firstLine = goOutput.toString().split("\n")[0];+ const parsed = JSON.parse(firstLine);++ const nativeVersion = await LambdaInternals.makeLambdaPayload({+ region: "us-east-1",+ composition: "react-svg",+ functionName: "remotion-render",+ serveUrl: "testbed",+ codec: "h264",+ });++ console.log(parsed, nativeVersion);+ expect(parsed).toEqual(nativeVersion);+});diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.tsnew file mode 100644index 0000000000..b9488cbc04--- /dev/null+++ b/packages/lambda/src/api/make-lambda-payload.ts@@ -0,0 +1,97 @@+import {VERSION} from 'remotion/version';+import {serializeInputProps} from '../shared/serialize-input-props';+import {validateDownloadBehavior} from '../shared/validate-download-behavior';+import {validateFramesPerLambda} from '../shared/validate-frames-per-lambda';+import {validateLambdaCodec} from '../shared/validate-lambda-codec';+import {validateServeUrl} from '../shared/validate-serveurl';+import type {RenderMediaOnLambdaInput} from './render-media-on-lambda';++export const makeLambdaPayload = async ({+ rendererFunctionName,+ frameRange,+ framesPerLambda,+ forceBucketName: bucketName,+ codec,+ composition,+ serveUrl,+ imageFormat,+ inputProps,+ region,+ crf,+ envVariables,+ pixelFormat,+ proResProfile,+ quality,+ maxRetries,+ privacy,+ logLevel,+ outName,+ timeoutInMilliseconds,+ chromiumOptions,+ scale,+ everyNthFrame,+ numberOfGifLoops,+ audioBitrate,+ concurrencyPerLambda,+ audioCodec,+ forceHeight,+ forceWidth,+ webhook,+ videoBitrate,+ downloadBehavior,+ muted,+ overwrite,+ dumpBrowserLogs,+}: RenderMediaOnLambdaInput) => {+ const actualCodec = validateLambdaCodec(codec);+ validateServeUrl(serveUrl);+ validateFramesPerLambda({+ framesPerLambda: framesPerLambda ?? null,+ durationInFrames: 1,+ });+ validateDownloadBehavior(downloadBehavior);++ const serializedInputProps = await serializeInputProps({+ inputProps,+ region,+ type: 'video-or-audio',+ userSpecifiedBucketName: bucketName ?? null,+ });+ return {+ rendererFunctionName: rendererFunctionName ?? null,+ framesPerLambda: framesPerLambda ?? null,+ composition,+ serveUrl,+ inputProps: serializedInputProps,+ codec: actualCodec,+ imageFormat: imageFormat ?? 'jpeg',+ crf,+ envVariables,+ pixelFormat,+ proResProfile,+ quality,+ maxRetries: maxRetries ?? 1,+ privacy: privacy ?? 'public',+ logLevel: logLevel ?? 'info',+ frameRange: frameRange ?? null,+ outName: outName ?? null,+ timeoutInMilliseconds: timeoutInMilliseconds ?? 30000,+ chromiumOptions: chromiumOptions ?? {},+ scale: scale ?? 1,+ everyNthFrame: everyNthFrame ?? 1,+ numberOfGifLoops: numberOfGifLoops ?? 0,+ concurrencyPerLambda: concurrencyPerLambda ?? 1,+ downloadBehavior: downloadBehavior ?? {type: 'play-in-browser'},+ muted: muted ?? false,+ version: VERSION,+ overwrite: overwrite ?? false,+ audioBitrate: audioBitrate ?? null,+ videoBitrate: videoBitrate ?? null,+ webhook: webhook ?? null,+ forceHeight: forceHeight ?? null,+ forceWidth: forceWidth ?? null,+ bucketName: bucketName ?? null,+ audioCodec: audioCodec ?? null,+ dumpBrowserLogs: dumpBrowserLogs ?? false,+ };+};diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.tsindex a8fb62b528..4124113077 100644--- a/packages/lambda/src/api/render-media-on-lambda.ts+++ b/packages/lambda/src/api/render-media-on-lambda.ts@@ -7,19 +7,14 @@ import type {PixelFormat,ProResProfile,} from '@remotion/renderer';-import {VERSION} from 'remotion/version';import type {AwsRegion} from '../pricing/aws-regions';import {callLambda} from '../shared/call-lambda';import type {OutNameInput, Privacy} from '../shared/constants';import {LambdaRoutines} from '../shared/constants';import type {DownloadBehavior} from '../shared/content-disposition-header';import {getCloudwatchStreamUrl, getS3RenderUrl} from '../shared/get-aws-urls';-import {serializeInputProps} from '../shared/serialize-input-props';-import {validateDownloadBehavior} from '../shared/validate-download-behavior';-import {validateFramesPerLambda} from '../shared/validate-frames-per-lambda';import type {LambdaCodec} from '../shared/validate-lambda-codec';-import {validateLambdaCodec} from '../shared/validate-lambda-codec';-import {validateServeUrl} from '../shared/validate-serveurl';+import {makeLambdaPayload} from './make-lambda-payload';export type RenderMediaOnLambdaInput = {region: AwsRegion;@@ -91,99 +86,16 @@ export type RenderMediaOnLambdaOutput = {* @returns {Promise<RenderMediaOnLambdaOutput>} See documentation for detailed structure*/-export const renderMediaOnLambda = async ({- functionName,- serveUrl,- inputProps,- codec,- imageFormat,- crf,- envVariables,- pixelFormat,- proResProfile,- quality,- region,- maxRetries,- composition,- framesPerLambda,- privacy,- logLevel,- frameRange,- outName,- timeoutInMilliseconds,- chromiumOptions,- scale,- numberOfGifLoops,- everyNthFrame,- concurrencyPerLambda,- downloadBehavior,- muted,- overwrite,- audioBitrate,- videoBitrate,- webhook,- forceHeight,- forceWidth,- rendererFunctionName,- forceBucketName: bucketName,- audioCodec,- dumpBrowserLogs,-}: RenderMediaOnLambdaInput): Promise<RenderMediaOnLambdaOutput> => {- const actualCodec = validateLambdaCodec(codec);- validateServeUrl(serveUrl);- validateFramesPerLambda({- framesPerLambda: framesPerLambda ?? null,- durationInFrames: 1,- });- validateDownloadBehavior(downloadBehavior);+export const renderMediaOnLambda = async (+ input: RenderMediaOnLambdaInput+): Promise<RenderMediaOnLambdaOutput> => {+ const {functionName, region, rendererFunctionName} = input;- const serializedInputProps = await serializeInputProps({- inputProps,- region,- type: 'video-or-audio',- userSpecifiedBucketName: bucketName ?? null,- });try {const res = await callLambda({functionName,type: LambdaRoutines.start,- payload: {- rendererFunctionName: rendererFunctionName ?? null,- framesPerLambda: framesPerLambda ?? null,- composition,- serveUrl,- inputProps: serializedInputProps,- codec: actualCodec,- imageFormat: imageFormat ?? 'jpeg',- crf,- envVariables,- pixelFormat,- proResProfile,- quality,- maxRetries: maxRetries ?? 1,- privacy: privacy ?? 'public',- logLevel: logLevel ?? 'info',- frameRange: frameRange ?? null,- outName: outName ?? null,- timeoutInMilliseconds: timeoutInMilliseconds ?? 30000,- chromiumOptions: chromiumOptions ?? {},- scale: scale ?? 1,- everyNthFrame: everyNthFrame ?? 1,- numberOfGifLoops: numberOfGifLoops ?? 0,- concurrencyPerLambda: concurrencyPerLambda ?? 1,- downloadBehavior: downloadBehavior ?? {type: 'play-in-browser'},- muted: muted ?? false,- version: VERSION,- overwrite: overwrite ?? false,- audioBitrate: audioBitrate ?? null,- videoBitrate: videoBitrate ?? null,- webhook: webhook ?? null,- forceHeight: forceHeight ?? null,- forceWidth: forceWidth ?? null,- bucketName: bucketName ?? null,- audioCodec: audioCodec ?? null,- dumpBrowserLogs: dumpBrowserLogs ?? false,- },+ payload: await makeLambdaPayload(input),region,});return {diff --git a/packages/lambda/src/internals.ts b/packages/lambda/src/internals.tsindex 426a69b1d9..888903d637 100644--- a/packages/lambda/src/internals.ts+++ b/packages/lambda/src/internals.ts@@ -1,4 +1,7 @@+import {makeLambdaPayload} from './api/make-lambda-payload';import {executeCommand} from './cli/index';+export const LambdaInternals = {executeCommand,+ makeLambdaPayload,};diff --git a/packages/lambda/src/shared/serialize-input-props.ts b/packages/lambda/src/shared/serialize-input-props.tsindex b48acb7c4d..95467cc0dc 100644--- a/packages/lambda/src/shared/serialize-input-props.ts+++ b/packages/lambda/src/shared/serialize-input-props.ts@@ -6,7 +6,7 @@ import {inputPropsKey} from './constants';import {randomHash} from './random-hash';export const serializeInputProps = async ({- inputProps,+ inputProps = {},region,type,userSpecifiedBucketName,