DEV Community

Building a super cheap transcoder using AWS Lambda

Sydney Schreckengost on December 18, 2018

Have you ever looked at the price of Amazon's Elastic Transcoder? If you haven't I'll spare you the lookup - it's 3 cents (USD) per minute of vide...
Collapse
 
voltrus2 profile image
voltrus • Edited

Hi Harold, Thanks for the life saving post.Im a newbie to coding, I got stuck at the tweaking part that you're saying after extracting the ffmpeg directory. I couldnt change any ffmpeg parameters and also couldnt find where the compressed files are going. Can you help me with that?

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost • Edited

That's handled by the script that actually calls ffmpeg. So, in this case, all I'm really after is to change codecs/container formats, so I just have the script/program that calls it do the output options. It never changes, so I can hard code most of the options, but you can also set it dynamically depending on your needs.

You'll need to download the file to /tmp, and also transcode it to their. This introduces the big issue with this setup - large files will fail, plainly.

Collapse
 
onlinecheckwriter profile image
onlinecheckwriter

Coding our function:

Can you give the code too? We are struggling on this

Thread Thread
 
sydneybrokeit profile image
Sydney Schreckengost

I can't yet, but I can give you the basics of it (the details are dependent on language, but the general gist):
1) Receive the lambda message and use the details to download the input file
2) Run ffmpeg with the options you need
3) Upload the file to S3

Collapse
 
dajiangqingzhou profile image
jackson007

Hi Harold:
Thank you for your great instrutions.
As I know, it is only 512MB for the /tmp directory, so you save the video in the memory?Does it take much time for downloading video from S3, and how you speed it up?
Thanks again!

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost

If I missed anything, please do mention it so I can update it.

Collapse
 
edithousedvd profile image
Edithouse

Hey Harold, Thank you for your great instructions, does it mean that the Lambda limitation will unable to encode full length film? e.g. feature film of 1hour and 45mins or longer for example?

Thanks again!

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost

Yeah, that's the big downside. It can't really do that. In fact, I found out that anything with loads of motion will break, because it only has so much room. But it's pretty good for the things we really need it for.

Collapse
 
sendmcjak profile image
Timothy McJak

New to Layers -- how do I import / reference the ffmpeg layer from within Lambda?

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost

Ah! My apologies - from within the function page, under "Designer", immediately under the function you should see a layers button. Everything you need is in there.

Collapse
 
thiagocardoso1988 profile image
Thiago Cardoso

I'd like to know how you overcome errors like 'moov atom not found', which I find very often in my process; I'm doing a similar job, but I'm using node.js in my case

Collapse
 
jamesdixon profile image
James Dixon

Unrelated question but have you found transcoding video to be especially slow with Node on Lambda? Harold mentioned a 10 minute video taking 105 seconds. I have a 30 second video that's taking over a minute to transcode. On my local system it takes seconds...

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost

If you're doing it using ffmpeg, it should be about the same across any runtime.

Are you accounting for the time to download, etc? Also, it will always run faster on a local machine with real resources behind it, and the videos I'm transcoding are going to be relatively low-motion by nature.

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost

That sounds like something specific to node. Not terribly familiar, unfortunately.

Collapse
 
jamesdixon profile image
James Dixon

Hi Harold,

Thanks for the article!

Curious if you have a repo where we could check out the function code?

Cheers

Collapse
 
sydneybrokeit profile image
Sydney Schreckengost

I don't anymore (I've since left this job). Another comment has the basic structure, though!

Collapse
 
david_j_eddy profile image
David J Eddy

This is just what I was looking for. Thank you for publishing this.