DEV Community

Discussion on: How do I create thumbnails when I upload a video? aws lambda!

Collapse
 
deek87 profile image
Derek Cameron • Edited

Hey ben,

Its nice to see someone refactored my code, especially with the newish layer system, but theres a couple of things you can do that will fit your use case better.

First in my original I use jpg and -ss because I only needed one screenshot and it had to be jpg because of the file system we were using at the time.

You would be better to change to output codec to png - you can just remove the vcodec (theres also another line in there I left in which doesnt do anything for your use case).

For permissions you can move the ffmpeg/ffprobe to /tmp and then run chmod there but you need to update you ffmpeg path.

Solutions to this are to send a POST request from the Lambda function to your backend when the processing is complete.

Actually, in your use case its actually better not to use any of this, it would be better to use something like aws elemental media convert to generate thumbnails/gifs etc.

Though if you wanted to use this function, its better to use SNS to push to your application when its completed. So send to SNS after completing upload - SNS pushes to your application/sends email w/e.

You could also be crazy and use AWS Rekognition to autogenerate tags for the videos.

With your current setup you may run into memory problems seeking 75% on larger files, whats your current largest test files? I assume in your current setup you also use ffprobe to output JSON to get the metadata right?

Its good to see a refactored version of my code for a fake youtube. Never though of using it like that.

Collapse
 
benjaminadk profile image
benjaminadk

Thanks for your article, it was helpful and the best out there on this topic. I added a Resources section to give credit where credit's due.

I did some testing with PNG and I was surprised the PNGs were larger. I've been under the general impression that PNG for graphics, JPG for photos.

JPG ~ 12KB

PNG ~ 61KB

Thanks for the tip on SNS, it looks very useful. I would have to do more testing and use some larger files, I think I largest video I tested with so far was only 15MB.

I figured trying to recreate what I could of YouTube would be a good way to learn stuff. So far it has. Obviously, their code is complex, but its fun to come with a function to determine what video to play next for example.

Collapse
 
rohitshetty profile image
Rohit Shetty

Regarding the memory problem:

I wanted to implement this for one of my use cases and was worried about the memory issues too.
But this article here explains how the FFmpeg works with URL and seek. wistia.com/learn/marketing/faster-...

And looks like we are good?

Collapse
 
dajiangqingzhou profile image
jackson007

Hey Derek:
For the output codec, why do you suggest using png?