https://github.com/diegovictor/video-thumbnailer
Lambda to trigger a Fargate container that generates videos thumbnails after a file be uploaded and save it into S3
https://github.com/diegovictor/video-thumbnailer
aws container docker fargate ffmpeg javascript js node nodejs s3 serverless thumbnail ts typescript video video-processing
Last synced: about 1 year ago
JSON representation
Lambda to trigger a Fargate container that generates videos thumbnails after a file be uploaded and save it into S3
- Host: GitHub
- URL: https://github.com/diegovictor/video-thumbnailer
- Owner: DiegoVictor
- License: mit
- Created: 2022-07-31T15:09:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-21T12:26:27.000Z (over 1 year ago)
- Last Synced: 2025-03-05T08:42:46.021Z (over 1 year ago)
- Topics: aws, container, docker, fargate, ffmpeg, javascript, js, node, nodejs, s3, serverless, thumbnail, ts, typescript, video, video-processing
- Language: TypeScript
- Homepage:
- Size: 3.47 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Video Thumbnailer
[](https://app.circleci.com/pipelines/github/DiegoVictor/video-thumbnailer?branch=main)
[](https://www.serverless.com/)
[](https://eslint.org/)
[](https://github.com/airbnb/javascript)
[](https://jestjs.io/)
[](https://www.typescriptlang.org/)
[](https://codecov.io/gh/DiegoVictor/video-thumbnailer)
[](https://raw.githubusercontent.com/DiegoVictor/video-thumbnailer/main/LICENSE)
[](http://makeapullrequest.com)
[](https://insomnia.rest/run/?label=Video%20Thumbnailer&uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Fvideo-thumbnailer%2Fmain%2FInsomnia_2024-12-05.json)
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):

#### Infrastructure Diagram:

## Table of Contents
* [Requirements](#requirements)
* [Install](#install)
* [Deploy](#deploy)
* [Container](#container)
* [Useful Links](useful-links)
* [Teardown](#teardown)
* [Usage](#usage)
* [Running the tests](#running-the-tests)
* [Coverage report](#coverage-report)
# Requirements
* Node.js ^14.15.0
* Serveless Framework
* AWS Account
* [S3](https://aws.amazon.com/s3/)
* [Lambda](https://aws.amazon.com/lambda)
* [API Gateway](https://aws.amazon.com/api-gateway/)
* [Elastic Container Registry](https://aws.amazon.com/pt/ecr/)
* [Fargate](https://aws.amazon.com/pt/fargate/)
# Install
```
npm install
```
Or simply:
```
yarn
```
> Was installed and configured the [`eslint`](https://eslint.org/) and [`prettier`](https://prettier.io/) 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](https://aws.amazon.com/cli) to download the mp4 video file uploaded in the S3 Bucket, makes some calculations, then it uses [ffmpeg](https://ffmpeg.org/) 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.
Once the thumbnails file is generate it is uploaded into S3 Bucket.
#### Useful Links
* https://trac.ffmpeg.org/wiki/FilteringGuide
* http://ffmpeg.org/ffmpeg-filters.html#streamselect_002c-astreamselect
## Teardown
To completly remove the resources from AWS, follow these steps:
1. Run the teardown script:
```
$ cd scripts
$ ./teardown.sh
```
2. 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
```
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](https://jestjs.io/) 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.