This is a POC of how to use lambda to transcode video files.
The cdk.json
file tells the CDK Toolkit how to execute your app.
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
To get started first initialize the cdk using npx cdk bootstrap
. Then deploy this app using npm run build
followed by npx cdk deploy
.
Once the app is deployed, simply upload a video file to the source/
directory inside the SourceBucket
that is created to trigger the pipeline (you will need to manually create the source/
directory).
This is still a work in progress so it doesn't work on big videos just yet, I recommend a ~60mb .mov
file as that's what I was testing with.
- When a file is uploaded to the
SourceBucket
'ssource/
directory a lambda calledOnUploadInitTranscodeHandler
is triggered. OnUploadInitTranscodeHandler
takes theKey
andBucket
of the uploaded file and kicks off aTranscodeMachine
execution.- The
TranscodeMachine
consists of:- A
ProbeTask
that reads the file and creates a list of start+end times so we can parallelize the transcoding in 5s chunks. - A
TranscodeParts
task that takes the list of start+end times and triggers anTranscodePartTask
for each 5s chunk to process in parallel. - An
AssemblePartsTask
that takes all the chunks produced by theTranscodePartTask
s and concats their outputs into a single file in theoutput/
directory of theSourceBucket
. - Finally a
CleanUpTask
is fired to clean up all the temporary chunks created by theTranscodePartTasks
s.
- A