A serverless, event-driven video transcoding platform built on AWS. Users upload raw videos through a React frontend, and the system automatically transcodes them to 480p using FFmpeg running inside a Dockerised ECS Fargate container — all without managing any servers.
- Overview
- Architecture
- How It Works — Step by Step
- Tech Stack
- Frontend
- AWS Services Used
- Authentication Flow
- Video Upload Flow
- Transcoding Pipeline
- Cost Efficiency — Batch Triggering
- Environment Variables
- Local Development
- Project Structure
ScaleTranscode lets authenticated users upload videos (MP4, MOV, up to 2 GB) via a drag-and-drop interface. Once uploaded to S3, a CloudWatch alarm monitors the queue and triggers an ECS Fargate task in batches of 10. The Fargate container runs FFmpeg to transcode each video to 480p and stores the output in a separate S3 bucket. Users can then view and download their processed videos directly from the dashboard.
┌─────────────────────────────────────────────────────────────────────┐
│ User's Browser │
│ │
│ React + Vite + Tailwind │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
│ │ AuthModal │ │ UploadZone │ │ VideoList │ │
│ │ (Cognito) │ │ (Presigned │ │ (Polls /videos API) │ │
│ └──────┬───────┘ │ PUT URL) │ └──────────────────────┘ │
│ │ └──────┬───────┘ │
└──────────┼──────────────────┼──────────────────────────────────────┘
│ │
▼ ▼
┌──────────────────┐ ┌───────────────────────────────────────────┐
│ Amazon Cognito │ │ API Gateway │
│ User Pool │ │ (JWT Authorizer — validates Cognito │
│ │ │ idToken before forwarding to Lambda) │
│ - Sign Up │ └──────────────────┬────────────────────────┘
│ - Confirm Email │ │
│ - Sign In │ ┌──────────┴──────────┐
│ - JWT issuance │ │ │
└──────────────────┘ ▼ ▼
┌─────────────────┐ ┌─────────────────────┐
│ Lambda │ │ Lambda │
│ get-upload-url │ │ GET /videos │
│ │ │ │
│ - Validates │ │ - Reads DynamoDB │
│ file size │ │ - Returns video │
│ - Checks daily │ │ list + presigned │
│ quota │ │ download URLs │
│ - Issues S3 │ └─────────────────────┘
│ presigned URL │
└────────┬────────┘
│
▼
┌──────────────────────┐
│ S3 — Input Bucket │ ◄── Raw video uploaded
│ (raw uploads) │ directly by browser
└──────────┬───────────┘ via presigned PUT URL
│
│ S3 ObjectCreated event
▼
┌──────────────────────┐
│ CloudWatch Alarm │
│ │
│ Metric: number of │
│ objects in input │
│ bucket prefix │
│ │
│ Threshold: ≥ 10 │
│ unprocessed videos │
└──────────┬───────────┘
│ Triggers (alarm state → ALARM)
▼
┌──────────────────────┐
│ ECS Fargate Task │
│ (spun up on demand) │
│ │
│ Docker image with │
│ FFmpeg installed │
│ │
│ - Pulls videos from │
│ input S3 bucket │
│ - Transcodes to │
│ 480p (libx264) │
│ - Pushes output to │
│ output S3 bucket │
│ - Updates DynamoDB │
│ record → COMPLETED│
│ - Deletes source │
│ from input bucket │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ S3 — Output Bucket │
│ (480p transcoded │
│ videos) │
└──────────────────────┘
│
┌──────────┴───────────┐
│ DynamoDB │
│ │
│ Stores per-user │
│ video metadata: │
│ - fileName │
│ - status │
│ (PENDING/ │
│ COMPLETED) │
│ - createdAt │
│ - processedKey │
└──────────────────────┘
-
User signs in via Amazon Cognito. The frontend receives a JWT
idToken. -
User selects a video (MP4 or MOV, max 2 GB) in the drag-and-drop upload zone.
-
Frontend calls
POST /get-upload-urlon API Gateway, passing the file name, content type, and size. The Cognito JWT is sent in theAuthorizationheader — API Gateway's JWT Authorizer validates it before the Lambda even runs. -
Lambda
get-upload-urlchecks file size limits and the user's daily upload quota, then generates a short-lived S3 presigned PUT URL and returns it to the browser. -
Browser uploads the raw video directly to S3 using the presigned URL via an HTTP PUT. The file bytes never pass through any backend server.
-
S3 records the new object. A CloudWatch metric tracks the number of unprocessed videos in the input bucket.
-
CloudWatch Alarm fires when the unprocessed video count reaches 10. This triggers an ECS Fargate task to start.
-
ECS Fargate container (Docker image with FFmpeg) wakes up, pulls the pending videos from the input S3 bucket, and transcodes each one to 480p using
libx264. -
Transcoded videos are stored in the output S3 bucket. DynamoDB records for each video are updated from
PENDING→COMPLETED, and the source files are removed from the input bucket. -
Frontend polls
GET /videosevery 10 seconds while any video is inPENDINGstate. Once the status flips toCOMPLETED, a presigned download URL is shown and the user can view/download the processed video.
| Layer | Technology |
|---|---|
| Frontend | React 18, TypeScript, Vite, Tailwind CSS |
| Auth | Amazon Cognito (User Pool + JWT) |
| API | Amazon API Gateway (HTTP API, JWT Authorizer) |
| Compute (API) | AWS Lambda (Node.js) |
| Storage | Amazon S3 (two buckets: input + output) |
| Database | Amazon DynamoDB |
| Transcoding | AWS ECS Fargate + Docker + FFmpeg |
| Monitoring | Amazon CloudWatch (metrics + alarms) |
| HTTP Client | Axios (with upload progress + cancel support) |
The frontend is a single-page React application built with Vite and styled with Tailwind CSS.
App.tsx
Root component. Manages upload state, calls the presigned URL API, streams the file to S3 with progress tracking, and supports upload cancellation via Axios cancel tokens.
Header.tsx
Sticky top bar with the app logo, a GitHub link, and a Sign In / Sign Out button that opens the auth modal.
UploadZone.tsx
Drag-and-drop upload area. Shows a lock icon when the user is not authenticated. Displays a real-time progress bar with file name and size while uploading. Includes a cancel button.
VideoList.tsx
Fetches the authenticated user's video list from GET /videos. Polls every 10 seconds automatically while any video is in PENDING status. Shows a status badge (Pending / Completed) and a View/Download button for completed videos.
AuthModal.tsx
Handles Sign Up (with email verification code), Sign In, and error display — all backed by amazon-cognito-identity-js.
AuthContext.tsx
React context that holds the Cognito JWT token, restores the session from local storage on page load, and exposes setToken and logout helpers.
cognito.ts
Thin wrapper around amazon-cognito-identity-js exposing signUp, confirmSignUp, signIn, getCurrentToken, and signOut.
- Input bucket — receives raw video uploads via presigned PUT URLs. Acts as the trigger source for the transcoding pipeline.
- Output bucket — stores the 480p transcoded videos. Lambda generates short-lived presigned GET URLs from this bucket for the frontend to download.
- Manages user registration, email verification, and authentication.
- Issues JWT
idTokens that are validated by API Gateway on every protected request.
- HTTP API with a Cognito JWT Authorizer.
- Routes:
POST /get-upload-url— issues a presigned S3 PUT URLGET /videos— returns the user's video list with download URLs
get-upload-url— validates request, checks quota, generates presigned URL, writes aPENDINGrecord to DynamoDB.get-videos— queries DynamoDB for the user's videos, generates presigned download URLs for completed ones.
Stores video metadata per user:
| Attribute | Type | Description |
|---|---|---|
userId |
String (PK) | Cognito sub (user ID) |
fileName |
String | Original file name |
status |
String | PENDING or COMPLETED |
createdAt |
String | ISO-8601 upload timestamp |
processedKey |
String | S3 key of the transcoded output |
- A custom metric tracks the number of unprocessed videos sitting in the input S3 bucket.
- An alarm is configured with a threshold of 10 videos. When the metric crosses this threshold, the alarm transitions to
ALARMstate and triggers the ECS Fargate task. - This batching strategy avoids spinning up a container for every single upload, keeping compute costs low.
- Runs a Docker container built on a lightweight Linux base image with FFmpeg installed.
- The container is stateless and ephemeral — it starts on demand, processes the batch, and stops.
- No EC2 instances to manage or pay for when idle.
- Transcodes each video to 480p (854×480) using the
libx264codec. - Command pattern used:
ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -preset fast -c:a aac output_480p.mp4
Browser Cognito API Gateway + Lambda
│ │ │
│── signUp(email, pw) ────►│ │
│◄─ confirmation code ─────│ │
│── confirmSignUp(code) ──►│ │
│◄─ success ───────────────│ │
│── signIn(email, pw) ─────►│ │
│◄─ idToken (JWT) ──────────│ │
│ │ │
│── POST /get-upload-url ──────────────────────────────► │
│ Authorization: Bearer <idToken> │
│ │◄── JWT validation ──────────►│
│◄─ { presignedUrl, key } ────────────────────────────────│
The idToken is stored in the browser's local storage by amazon-cognito-identity-js and automatically restored on page reload via getCurrentToken().
Browser S3 (Input) Lambda / DynamoDB
│ │ │
│── POST /get-upload-url ───────────────────────────────► │
│◄─ { presignedUrl, key } ──────────────────────────────── │
│ │ writes PENDING record
│── PUT <presignedUrl> ────────►│ │
│ (raw video bytes) │ │
│◄─ 200 OK ─────────────────────│ │
│ │ │
│── GET /videos (poll) ─────────────────────────────────► │
│◄─ [{ status: "PENDING", ... }] ───────────────────────── │
│ │ │
│ ... (waits for Fargate) ... │ │
│ │ │
│── GET /videos (poll) ─────────────────────────────────► │
│◄─ [{ status: "COMPLETED", downloadUrl: "..." }] ──────── │
S3 Input Bucket
│
│ (ObjectCreated events accumulate)
│
▼
CloudWatch Metric: UnprocessedVideoCount
│
│ Threshold reached (≥ 10 videos)
▼
CloudWatch Alarm → ALARM state
│
▼
ECS Fargate Task starts
│
├── Pull pending video keys from DynamoDB (status = PENDING)
│
├── For each video:
│ ├── Download from S3 input bucket
│ ├── Run FFmpeg → 480p output
│ ├── Upload output to S3 output bucket
│ ├── Update DynamoDB record → COMPLETED
│ └── Delete source from input bucket
│
└── Task exits (Fargate stops, no idle cost)
Rather than triggering a Fargate task for every single video upload (which would be expensive and slow for small files), the CloudWatch alarm waits until 10 videos have accumulated before starting the container. This means:
- Fargate cold-start overhead is amortised across 10 videos.
- Compute costs are significantly lower for high-volume usage.
- The alarm resets after the batch is processed and the input bucket drains below the threshold.
Create a .env file in the project root with the following variables:
# Cognito
VITE_COGNITO_USER_POOL_ID=ap-south-1_XXXXXXXXX
VITE_COGNITO_CLIENT_ID=XXXXXXXXXXXXXXXXXXXXXXXXXX
# API Gateway base URL (no trailing slash)
VITE_API_GATEWAY_URL=https://xxxxxxxxxx.execute-api.ap-south-1.amazonaws.com/prodThese are injected at build time by Vite and exposed to the browser as import.meta.env.*.
Never commit
.envto version control. It is already listed in.gitignore.
- Node.js 18+
- npm or yarn
# Install dependencies
npm install
# Start the development server
npm run devThe app will be available at http://localhost:5173.
# Type-check without emitting files
npm run typecheck
# Lint the codebase
npm run lint
# Build for production
npm run build
# Preview the production build locally
npm run preview├── src/
│ ├── components/
│ │ ├── AuthModal.tsx # Sign up / sign in modal (Cognito)
│ │ ├── Header.tsx # Top navigation bar
│ │ ├── JobsList.tsx # Job status list component
│ │ ├── UploadZone.tsx # Drag-and-drop upload area with progress
│ │ └── VideoList.tsx # User's video list with polling
│ ├── context/
│ │ └── AuthContext.tsx # Global auth state (token, login, logout)
│ ├── lib/
│ │ └── cognito.ts # Cognito SDK wrapper (signUp, signIn, etc.)
│ ├── App.tsx # Root component, upload orchestration
│ ├── main.tsx # React entry point
│ └── index.css # Global styles + Tailwind directives
├── index.html
├── vite.config.ts
├── tailwind.config.js
├── tsconfig.app.json
└── package.json