Skip to content

Lambda to trigger a Fargate container that generates videos thumbnails after a file be uploaded and save it into S3

License

Notifications You must be signed in to change notification settings

DiegoVictor/video-thumbnailer

Repository files navigation

Video Thumbnailer

CircleCI serverless eslint airbnb-style jest typescript coverage MIT License PRs Welcome
Run in Insomnia}

This application trigger a container with ffmpeg to generate thumbnails when a video is uploaded into a S3 Bucket folder. Output example (compressed file for faster load):

Example

Infrastructure Diagram:

Infrastructure Diagram

Table of Contents

Requirements

Install

npm install

Or simple:

yarn

Was installed and configured the eslint and prettier to keep the code clean and patterned.

Deploy

Deploy the application:

$ sls deploy

Now push the container image:

$ cd scripts
$ ./deploy-container.sh

The script will:

  1. Build the container image.
  2. Get authentication credentials in the ECR service.
  3. Push the container to the ECR repository created during the deploy.

Container

This container make usage of the aws cli to download the mp4 video file uploaded in the S3 Bucket, makes some calculations, then it uses ffmpeg binary to capture a thumbnail at each 1 second of video and save them into a single file.

Refer to the docker/main.sh script.

Output

Once the thumbnails file is generate it is uploaded into S3 Bucket.

Useful Links

Teardown

To completly remove the resources from AWS, follow these steps:

  1. Run the teardown script:
$ cd scripts
$ ./teardown.sh
  1. Then remove the stack:
$ sls remove

That is all.

Usage

After deploy the application use the outputed Lambda URL to request a signed URL to upload a video file:

GET /signedURL

Then use the signedUrl to upload the video file:

PUT <signed URL>

Once the upload finish S3 will trigger a Lambda that will fire a container to generate the video thumbnails file, all you need to do is wait the generated file be uploaded in the same S3 Bucket in a folder called preview.

Running the tests

Jest was the choice to test the app, to run:

$ yarn test

Or:

$ npm run test

Run the command in the root folder

Coverage report

You can see the coverage report inside tests/coverage. They are automatically created after the tests run.