Implementing a thumbnail generator
Prerequisites
Make sure you've read the previous page on implementing video transcoding with serverless code here. You will need the same setup in AWS Lambda to do this, and many of the concepts carry over.
Generating thumbnails with ffmpeg
The basic command for thumbnail generation looks like this:
/opt/bin/ffmpeg \
-y \
-i "yourvideo.mp4" \
-ss 00:00:00.100 \
-frames:v 1 \
-filter:v scale=trunc(oh*a/2)*2:480 \
"outputthumbnail.jpg"
An overview of the commands used here:
/opt/bin/ffmpeg | Path to the ffmpeg executable. |
-y | Overwrite the output file if it exists. |
-i "yourvideo.mp4" | The input file to generate a thumbnail from. |
-ss 00:00:00.100 | Seek to 100 milliseconds into the video, i.e. use that timestamp to generate the thumbnail image. |
-frames:v 1 | Only encode one frame. |
-filter:v scale=trunc(oh*a/2)*2:480 | Scale the thumbnail image to 640x480, without stretching. |
"outputthumbnail.jpg" | The output file for the thumbnail image. |
You can choose any timestamp for the thumbnail to be generated from, but be aware that it obviously has to exist within the video (i.e. 00:00:10.000 will not work on a 5 second video).