Hello all, I am trying to develop a scalable video processing pipeline on AWS infrastructure and need some ideas on how I can go about it.
What currently happens: I take a recorded video and convert it into 4 formats (1080, 720, 480, 360) streamable on the web and store all 4 videos on the S3 bucket behind CloudFront.
How I do it: I manually upload the videos to an EC2 instance I manually create and run a script in the background on that EC2 which launches FFmpeg and converts the videos. Then I manually ssh into the EC2 after a few hours and run a script that uploads them all to S3.
I want to automate this “processing” part. By this, I mean I want to have something like how YouTube does → allows you to upload the video, processes it as long as it wants, and once it’s ready, it shows that your video is processed.
If someone has a thought on how they will go about building such a pipeline in terms of the tech stack and the flow of information (which is scalable and robust), I would really appreciate it.
I have explored AWS MediaConvert in the past but didn’t go with it as it is way too expensive compared to for how much I am able to get it done for in the current solution (which has a few manual steps)
Yes, my initial idea was to kick a lambda on every upload and then process the video. But the hard 512MB limit on the lambda storage is a big bottleneck.
OP I second this, push the PUT events to an SQS topic, and on your EC2 instance you can run a cronjob to get messages from the queue, process the videos and then delete those messages and original files from the bucket.
You could improve on this and maybe have a lambda spawn that creates a new EC2 instance using some kind of AMI that you have pre-built, to run a script when it boots to do the same thing, then shut down when its finished everything in the queue.
AWS MediaConvert is $0.027/minute for VP8 HD <=30fps. For a 3-hour long video course, it comes out close to $5. The cost of re-encoding the videos through ffmpeg on an EC2 instance is much less than that. That’s my only problem with AWS in-built processing solutions
Autoscaling group of spot instances that scales on SQS queue length scales up, processes video, uploads to S3
Send SQS job to update DB with status
Dead letter queue for bad videos for you to investigate
Autoscaling group scales to 0 when queue is empty
That’s pretty much what I did. I wrote a simple go app that long polls SQS, gets the job, download the asset, shells out to ffmpeg to process the video, then uploads the completed assets to s3.
An option would be upload to S3 → an event is triggered which is processed by elastic transcoder (forget if you need Lambda in the middle or not) → uploaded to new S3 bucket → SNS sends an email or text to say it’s all done. Also could work in step functions if you need more complex workflows.
You’ll either need to pay AWS for their automated solution or develop an automated solution yourself. One solution costs very little upfront but you pay over time, the other requires large upfront costs but is cheaper over time. That’s pretty much AWS pricing in a nutshell…
I said Elastic Transcoder, not MediaConvert. I have no idea what MediaConvert is, but Elastic Transcoder does what you talk about and is not that expensive.
Edit: ok nvm mediaconvert is the new name of elastic transcoder, I had no idea
Oh yeah there is lots of different ways to do this, one of the joys of AWS is finding the best ways to do something. Also thought about ECS as well, and if it was something OP wanted even using the GPU capabilities of ECS for transcoding.
FIFO queues are exactly-once processing, if you need that.
Re: visibility timeout, if processing is long, set a background function that extends the visibility timeout while your processing is taking place. So in golang, I would for example accept the job, start processing and fire off a go routine that every 5 minutes resets the visibility timeout to 10 mins, then kill the go routine on completion and delete the message
Doesn’t ffmpeg rearrange video bits (move flags, etc.) after writing a few chunks? Writing directly to S3 would probably either break the video or deoptimize those optimizations? Correct me if I am wrong