My main inspiration was to create a universalizable application that would still be useful to a large number of people on the AWS Serverless Application Repo. Video stabilization seemed like a good choice: it could be used from anywhere from large media companies stabilizing camera footage to charitable organizations fighting human trafficking to process evidence.
What it does
When a user uploads a video to an S3 bucket, it triggers an AWS Lambda function that downloads them to the ephemeral storage in AWS Lambda and uses a trimmed down version of the vidstab Python package which uses OpenCV to stabilize videos based on a blog post written by Nghia Ho. It then saves the stabilized video to the output bucket using the same key it was uploaded with.
How I built it
I used the AWS Lambda Python 3 execution environment to run the code in the Lambda function and a modified version of the
vidstab package. I modified the package to remove its dependency on
progress. I was hoping to be able to get the code package small enough that it could be edited inline in the AWS Lambda console, but unfortunately OpenCV is a very big code base.
I used the Serverless Application Model to define and package the model for the Serverless Application Repo. The SAM Template defines several different customization options that affect the outputted video: the algorithm used for keypoint detection, and what to do with the border around the video. I also made the output and input buckets separate so that it could be integrated into a longer video processing pipeline.
Challenges I ran into
Some of the SAR errors were confusing, but thankfully the folks in Slack were extremely helpful in debugging applications. I also was unable to edit the function using the AWS Lambda inline editor, which meant rapid iteration on this application was harder.
Accomplishments that I'm proud of
Making an easily generalizable application that's live on the AWS SAR!
What I learned
Learned a lot about serverless applications and how to work with AWS.
What's next for Serverless Video Stabilizer
I could add to the SAM template in order to restrict execution to when video files under 240MB are uploaded to the bucket. I also would like to experiment with different architectures in order to allow bigger video files to be processed. The
vidstab repo has support for stabilizing streams of video, which I could potentially use in the future to stabilize videos on the fly.