🎥 Make videos programmatically with React
Merge branch 'main' into cloudrun-propogate-back-render-errors
Matt McGillivray3be1549e2e95
diff --cc packages/cloudrun/src/functions/render-media-single-thread.tsindex 8c8f9f4f49,ec83f9afe0..60aa15f641--- a/packages/cloudrun/src/functions/render-media-single-thread.ts+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts@@@ -19,122 -18,106 +19,123 @@@ export const renderMediaSingleThread =throw new Error('expected type media');}- const composition = await getCompositionFromBody(body);-- const defaultOutName = `out.${RenderInternals.getFileExtensionFromCodec(- body.codec,- body.audioCodec- )}`;- const tempFilePath = `/tmp/${defaultOutName}`;const renderId = randomHash({randomInTests: true});- let previousProgress = 2;- const onProgress: RenderMediaOnProgress = ({progress}) => {- if (previousProgress !== progress) {- res.write(JSON.stringify({onProgress: progress}) + '\n');- previousProgress = progress;- }- };-- res.writeHead(200, {'Content-Type': 'text/html'});- const actualChromiumOptions: ChromiumOptions = {- ...body.chromiumOptions,- // Override the `null` value, which might come from CLI with swANGLE- gl: body.chromiumOptions?.gl ?? 'swangle',- };+ try {+ const composition = await getCompositionFromBody(body);- await RenderInternals.internalRenderMedia({- composition: {- ...composition,- height: body.forceHeight ?? composition.height,- width: body.forceWidth ?? composition.width,- },- serveUrl: body.serveUrl,- codec: body.codec,- outputLocation: tempFilePath,- serializedInputPropsWithCustomSchema:- body.serializedInputPropsWithCustomSchema,- serializedResolvedPropsWithCustomSchema: Internals.serializeJSONWithDate({- data: composition.props,- indent: undefined,- staticBase: null,- }).serializedString,- jpegQuality: body.jpegQuality,- audioCodec: body.audioCodec,- audioBitrate: body.audioBitrate,- videoBitrate: body.videoBitrate,- crf: body.crf,- pixelFormat: body.pixelFormat,- imageFormat: body.imageFormat,- scale: body.scale,- proResProfile: body.proResProfile ?? undefined,- x264Preset: body.x264Preset ?? undefined,- everyNthFrame: body.everyNthFrame,- numberOfGifLoops: body.numberOfGifLoops,- onProgress,- frameRange: body.frameRange,- envVariables: body.envVariables,- chromiumOptions: actualChromiumOptions,- muted: body.muted,- logLevel: body.logLevel,- browserExecutable: null,- timeoutInMilliseconds: body.delayRenderTimeoutInMilliseconds,- cancelSignal: undefined,- concurrency: body.concurrency ?? '100%',- disallowParallelEncoding: false,- enforceAudioTrack: body.enforceAudioTrack,- ffmpegOverride: undefined,- indent: false,- onBrowserLog: null,- onCtrlCExit: () => undefined,- onDownload: () => undefined,- onStart: () => undefined,- overwrite: true,- port: null,- preferLossless: body.preferLossless,- puppeteerInstance: undefined,- server: undefined,- });+ const defaultOutName = `out.${RenderInternals.getFileExtensionFromCodec(+ body.codec,+ body.audioCodec+ )}`;+ const tempFilePath = `/tmp/${defaultOutName}`;+ let previousProgress = 2;+ const onProgress: RenderMediaOnProgress = ({progress}) => {+ if (previousProgress !== progress) {+ res.write(JSON.stringify({onProgress: progress}) + '\n');+ previousProgress = progress;+ }+ };- const storage = new Storage();+ res.writeHead(200, {'Content-Type': 'text/html'});- const publicUpload = body.privacy === 'public' || !body.privacy;+ const actualChromiumOptions: ChromiumOptions = {+ ...body.chromiumOptions,+ // Override the `null` value, which might come from CLI with swANGLE+ gl: body.chromiumOptions?.gl ?? 'swangle',+ };- const uploadedResponse = await storage- .bucket(body.outputBucket)- .upload(tempFilePath, {- destination: `renders/${renderId}/${body.outName ?? defaultOutName}`,- predefinedAcl: publicUpload ? 'publicRead' : 'projectPrivate',+ await RenderInternals.internalRenderMedia({+ composition: {+ ...composition,+ height: body.forceHeight ?? composition.height,+ width: body.forceWidth ?? composition.width,+ },+ serveUrl: body.serveUrl,+ codec: body.codec,+ outputLocation: tempFilePath,+ serializedInputPropsWithCustomSchema:+ body.serializedInputPropsWithCustomSchema,+ serializedResolvedPropsWithCustomSchema: Internals.serializeJSONWithDate({+ data: composition.props,+ indent: undefined,+ staticBase: null,+ }).serializedString,+ jpegQuality: body.jpegQuality,+ audioCodec: body.audioCodec,+ audioBitrate: body.audioBitrate,+ videoBitrate: body.videoBitrate,+ crf: body.crf,+ pixelFormat: body.pixelFormat,+ imageFormat: body.imageFormat,+ scale: body.scale,+ proResProfile: body.proResProfile ?? undefined,++ x264Preset: body.x264Preset ?? undefined,+ everyNthFrame: body.everyNthFrame,+ numberOfGifLoops: body.numberOfGifLoops,+ onProgress,+ frameRange: body.frameRange,+ envVariables: body.envVariables,+ chromiumOptions: actualChromiumOptions,+ muted: body.muted,+ logLevel: body.logLevel,+ browserExecutable: null,+ timeoutInMilliseconds: body.delayRenderTimeoutInMilliseconds,+ cancelSignal: undefined,+ concurrency: body.concurrency ?? '100%',+ disallowParallelEncoding: false,+ enforceAudioTrack: body.enforceAudioTrack,+ ffmpegOverride: undefined,+ indent: false,+ onBrowserLog: null,+ onCtrlCExit: () => undefined,+ onDownload: () => undefined,+ onStart: () => undefined,+ overwrite: true,+ port: null,+ preferLossless: body.preferLossless,+ puppeteerInstance: undefined,+ server: undefined,});- const uploadedFile = uploadedResponse[0];- const renderMetadata = await uploadedFile.getMetadata();- const responseData: RenderMediaOnCloudrunOutput = {- status: 'success',- publicUrl: publicUpload ? uploadedFile.publicUrl() : null,- cloudStorageUri: uploadedFile.cloudStorageURI.href,- size: renderMetadata[0].size,- bucketName: body.outputBucket,- renderId,- privacy: publicUpload ? 'public-read' : 'project-private',- };+ const storage = new Storage();++ const publicUpload = body.privacy === 'public' || !body.privacy;++ const uploadedResponse = await storage+ .bucket(body.outputBucket)+ .upload(tempFilePath, {+ destination: `renders/${renderId}/${body.outName ?? defaultOutName}`,+ predefinedAcl: publicUpload ? 'publicRead' : 'projectPrivate',+ });- RenderInternals.Log.info('Render Completed:', responseData);- res.end(JSON.stringify({response: responseData}));+ const uploadedFile = uploadedResponse[0];+ const renderMetadata = await uploadedFile.getMetadata();+ const responseData: RenderMediaOnCloudrunOutput = {+ type: 'success',+ publicUrl: publicUpload ? uploadedFile.publicUrl() : null,+ cloudStorageUri: uploadedFile.cloudStorageURI.href,+ size: renderMetadata[0].size,+ bucketName: body.outputBucket,+ renderId,+ privacy: publicUpload ? 'public-read' : 'project-private',+ };++ RenderInternals.Log.info('Render Completed:', responseData);+ res.end(JSON.stringify({response: responseData}));+ } catch (err) {+ await writeCloudrunError({+ bucketName: body.outputBucket,+ renderId,+ errorInfo: {+ name: (err as Error).name as string,+ message: (err as Error).message as string,+ stack: (err as Error).stack as string,+ type: 'renderer',+ },+ publicUpload: body.privacy === 'public' || !body.privacy,+ });++ throw err;+ }};diff --cc packages/cloudrun/src/gcpInstaller/gcpInstaller.tarindex 4c52ec20bf,06c0f72a4d..1b32c5b104Binary files differ