mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
feat(aws-lambda): a cloud render mixes its audio beside its chunks (#5997)
* feat(aws-lambda): a cloud render mixes its audio beside its chunks * fix(aws-lambda): the audio task keeps a worker free and runs only when the plan left audio out * test(aws-lambda): the audio task's free worker holds for a reserved pool of 1 and 2 * refactor(aws-lambda): one helper points every handler at the bundled Chrome
This commit is contained in:
@@ -318,6 +318,7 @@ export class HyperframesRenderStack extends Construct {
|
||||
"MaxChunkConcurrency.$": "$.Payload.MaxChunkConcurrency",
|
||||
"Format.$": "$.Payload.Format",
|
||||
"HasAudio.$": "$.Payload.HasAudio",
|
||||
"SeparateAudio.$": "$.Payload.SeparateAudio",
|
||||
},
|
||||
resultPath: "$.Plan",
|
||||
});
|
||||
@@ -479,8 +480,8 @@ export class HyperframesRenderStack extends Construct {
|
||||
"PlanV2ManifestS3Uri.$": "$.Plan.PlanV2ManifestS3Uri",
|
||||
"PlanV2ArtifactS3Prefix.$": "$.Plan.PlanV2ArtifactS3Prefix",
|
||||
"PlanHash.$": "$.Plan.PlanHash",
|
||||
"ChunkS3Uris.$": "$.Chunks[*].ChunkS3Uri",
|
||||
AudioS3Uri: sfn.JsonPath.stringToJson("null"),
|
||||
"ChunkS3Uris.$": "$.Render.Chunks[*].ChunkS3Uri",
|
||||
"AudioS3Uri.$": "$.Render.Audio.AudioS3Uri",
|
||||
"OutputS3Uri.$": "$.OutputS3Uri",
|
||||
"Format.$": "$.Plan.Format",
|
||||
}),
|
||||
@@ -501,11 +502,47 @@ export class HyperframesRenderStack extends Construct {
|
||||
maxDelay: Duration.seconds(60),
|
||||
});
|
||||
|
||||
// The plan left its audio out: mix it while the chunks render.
|
||||
const audio = new tasks.LambdaInvoke(this, "Audio", {
|
||||
lambdaFunction: this.renderFunction,
|
||||
payload: sfn.TaskInput.fromObject({
|
||||
Action: "audio",
|
||||
"ProjectS3Uri.$": "$.ProjectS3Uri",
|
||||
"PlanOutputS3Prefix.$": "$.PlanOutputS3Prefix",
|
||||
"Config.$": "$.Config",
|
||||
}),
|
||||
resultSelector: {
|
||||
"HasAudio.$": "$.Payload.HasAudio",
|
||||
"AudioS3Uri.$": "$.Payload.AudioS3Uri",
|
||||
},
|
||||
resultPath: "$.Audio",
|
||||
});
|
||||
audio.addRetry({ errors: NON_RETRYABLE_PLAN, maxAttempts: 0 });
|
||||
audio.addRetry(THROTTLED_RETRY);
|
||||
audio.addRetry({
|
||||
errors: ["States.ALL"],
|
||||
interval: Duration.seconds(2),
|
||||
maxAttempts: 4,
|
||||
backoffRate: 2,
|
||||
maxDelay: Duration.seconds(60),
|
||||
});
|
||||
const audioNeeded = new sfn.Choice(this, "AudioNeeded")
|
||||
.when(sfn.Condition.booleanEquals("$.Plan.SeparateAudio", true), audio)
|
||||
.otherwise(
|
||||
new sfn.Pass(this, "NoAudio", {
|
||||
result: sfn.Result.fromObject({ HasAudio: false, AudioS3Uri: null }),
|
||||
resultPath: "$.Audio",
|
||||
}),
|
||||
);
|
||||
const renderV2 = new sfn.Parallel(this, "RenderV2", {
|
||||
resultSelector: { "Chunks.$": "$[0].Chunks", "Audio.$": "$[1].Audio" },
|
||||
resultPath: "$.Render",
|
||||
})
|
||||
.branch(renderChunksV2)
|
||||
.branch(audioNeeded);
|
||||
|
||||
const selectWorkerProtocol = new sfn.Choice(this, "SelectWorkerProtocol")
|
||||
.when(
|
||||
sfn.Condition.stringEquals("$.Plan.PlanProtocol", "v2"),
|
||||
renderChunksV2.next(assembleV2),
|
||||
)
|
||||
.when(sfn.Condition.stringEquals("$.Plan.PlanProtocol", "v2"), renderV2.next(assembleV2))
|
||||
.otherwise(renderChunks.next(assemble));
|
||||
const assertChunkCount = new sfn.Choice(this, "AssertChunkCount")
|
||||
.when(sfn.Condition.numberGreaterThan("$.Plan.ChunkCount", 0), selectWorkerProtocol)
|
||||
|
||||
Reference in New Issue
Block a user