This is the complete source code to accompany the article here.
It takes a video that was uploaded to an S3 bucket and generates n number of thumbnails from it.
Create a Lambda and use the files in the src/
folder. You need to read the article to see how it ties in the AWS infrastructure, but basically:
- Create an S3 bucket
- Create a trigger event to run a Lambda whenever an
.mp4
file is uploaded to that bucket - That event triggers the Lambda (created from this source code) which uses FFmpeg to generate n thumbnails
- Those thumbnails are then uploaded to another S3 bucket
You wouldn't, necessarily. AWS Transcoder is good but very expensive compared to doing it yourself in Lambda. I have processed a few hundred short videos using the above source code / technique laid out in the article; the cost has been $0.00. AWS Transcoder costs around $0.45 per 60 minutes of video processed.
AWS has begun defaulting Lambdas to v18 of Node. The code has been updated to use v18, which includes:
- Using ESM syntax rather than CJS (
export default
rather thanmodule.exports
) - Using the
.mjs
extension rather than.js
- Assuming V3 of the AWS-SDK rather than V2