MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / handleAssemble

Function handleAssemble

packages/aws-lambda/src/handler.ts:392–443  ·  view source on GitHub ↗
(
  event: AssembleEvent,
  deps?: HandlerDeps,
)

Source from the content-addressed store, hash-verified

390// ── Assemble ────────────────────────────────────────────────────────────────
391
392async function handleAssemble(
393 event: AssembleEvent,
394 deps?: HandlerDeps,
395): Promise<AssembleLambdaResult> {
396 const started = Date.now();
397 const s3 = deps?.s3 ?? getS3Client();
398 const primitive = deps?.primitives?.assemble ?? assemble;
399
400 const work = mkdtempSync(join(deps?.tmpRoot ?? tmpdir(), "hf-lambda-assemble-"));
401 const planTar = join(work, "plan.tar.gz");
402 const planDir = join(work, "plan");
403
404 try {
405 await downloadS3ObjectToFile(s3, event.PlanS3Uri, planTar);
406 await untarDirectory(planTar, planDir);
407
408 const chunkPaths = await downloadChunkObjects(s3, event.ChunkS3Uris, work, event.Format);
409
410 let audioPath: string | null = null;
411 if (event.AudioS3Uri) {
412 audioPath = join(planDir, "audio.aac");
413 await downloadS3ObjectToFile(s3, event.AudioS3Uri, audioPath);
414 }
415
416 const finalOutput =
417 event.Format === "png-sequence"
418 ? join(work, "output-frames")
419 : join(work, `output${formatExtension(event.Format)}`);
420
421 const result: AssembleResult = await primitive(planDir, chunkPaths, audioPath, finalOutput, {
422 cfr: event.Cfr === true,
423 });
424
425 if (event.Format === "png-sequence") {
426 const tarball = `${finalOutput}.tar.gz`;
427 await tarDirectory(finalOutput, tarball);
428 await uploadFileToS3(s3, tarball, event.OutputS3Uri, "application/gzip");
429 } else {
430 await uploadFileToS3(s3, finalOutput, event.OutputS3Uri);
431 }
432
433 return {
434 Action: "assemble",
435 OutputS3Uri: event.OutputS3Uri,
436 FramesEncoded: result.framesEncoded,
437 FileSize: result.fileSize,
438 DurationMs: Date.now() - started,
439 };
440 } finally {
441 cleanupDir(work);
442 }
443}
444
445async function downloadChunkObjects(
446 s3: S3Client,

Callers 1

handlerFunction · 0.70

Calls 9

getS3ClientFunction · 0.85
downloadS3ObjectToFileFunction · 0.85
uploadFileToS3Function · 0.85
nowMethod · 0.80
untarDirectoryFunction · 0.70
downloadChunkObjectsFunction · 0.70
formatExtensionFunction · 0.70
tarDirectoryFunction · 0.70
cleanupDirFunction · 0.70

Tested by

no test coverage detected