Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Video Transcoder

A simple distributed video transcoding service built with Node.js, Express, Redis, Multer, and FFmpeg.

The API accepts uploaded videos, pushes transcoding jobs into a Redis queue, and a worker consumes those jobs and generates multiple video resolutions such as 72p, 144p, and 240p using FFmpeg.

Architecture

Client
  │
  │ POST /transcode
  ▼
Express API
  │
  │ Upload video
  ▼
Multer
  │
  │ Push file path
  ▼
Redis Queue
  │
  │ BRPOP
  ▼
Transcoding Worker
  │
  │ FFmpeg
  ├──────────► 72p.mp4
  ├──────────► 144p.mp4
  └──────────► 240p.mp4

Features

  • Video upload API
  • Redis-backed job queue
  • Asynchronous video processing
  • FFmpeg-based transcoding
  • Multiple output resolutions
  • Concurrent transcoding jobs
  • Static serving of generated videos
  • CORS support
  • Separate API and worker processes

Tech Stack

  • Node.js
  • TypeScript
  • Express
  • Redis
  • Multer
  • FFmpeg
  • child_process
  • HTTP/REST API

Project Structure

video-transcoder/
├── api/
│   └── index.ts
├── worker/
│   └── index.ts
├── uploads/
├── outputs/
├── package.json
└── README.md

How It Works

1. Upload a video

Send a POST request to:

POST /transcode

with the video as multipart form data:

video: <video-file>

Example using cURL:

curl -X POST http://localhost:8000/transcode \
  -F "video=@video.mp4"

Successful response:

{
  "response": "success",
  "file": "generated-file-name"
}

2. Job enters Redis

The API stores the uploaded video's path in the Redis list:

video-queue
await client.lPush("video-queue", req.file.path);

This separates uploading from video processing, so the API doesn't have to wait for FFmpeg.

3. Worker consumes the job

The worker continuously waits for jobs:

const job = await client.brPop("video-queue", 0);

BRPOP blocks until a new video becomes available.

4. FFmpeg transcoding

Each uploaded video is processed into multiple resolutions:

72p
144p
240p

The worker runs FFmpeg with:

ffmpeg -i input.mp4 \
  -vf scale=-2:240 \
  -c:v libx264 \
  -preset fast \
  -c:a aac \
  output.mp4

The -2 width keeps the video's aspect ratio while ensuring a compatible even width.

Running Locally

Prerequisites

Install:

  • Node.js
  • Redis
  • FFmpeg

Verify FFmpeg:

ffmpeg -version

Verify Redis:

redis-cli ping

Expected:

PONG

Install dependencies

npm install

Start Redis

Make sure your Redis server is running.

For Docker:

docker run -d \
  --name redis \
  -p 6379:6379 \
  redis

Start the API

npm run dev

The API runs on:

http://localhost:8000

Start the worker

In another terminal:

npm run worker

The worker will continuously listen to the Redis queue.

Output

After processing, videos are generated under:

outputs/

For example:

outputs/
└── video-id/
    ├── 72p.mp4
    ├── 144p.mp4
    └── 240p.mp4

Generated videos can be served through the API's /public route.

API

POST /transcode

Uploads a video and adds it to the transcoding queue.

Request

Content-Type: multipart/form-data

Field:

video

Success

{
  "response": "success",
  "file": "filename"
}

Failure

{
  "response": "error"
}

Queue Architecture

Redis acts as a lightweight message broker:

Producer                  Consumer
   │                         │
   │ LPUSH                   │ BRPOP
   ▼                         ▼
┌─────────────────────────────────┐
│          video-queue            │
└─────────────────────────────────┘

This architecture makes it possible to run multiple workers independently of the API server.

For example:

             ┌── Worker 1
             │
API ──► Redis├── Worker 2
             │
             └── Worker 3

More workers can be added when transcoding workload increases.

Future Improvements

  • Add job IDs and job status tracking
  • Add progress tracking from FFmpeg
  • Support more resolutions and codecs
  • Add authentication
  • Add persistent job metadata
  • Use Docker for API, workers, Redis, and FFmpeg
  • Add retry handling for failed jobs
  • Add dead-letter queues
  • Add S3/object-storage support
  • Add automatic cleanup of uploaded files
  • Add HLS/DASH streaming output
  • Add horizontal worker scaling
  • Add monitoring and metrics

Activity

Project activity:

GitHub Activity

License

This project is intended for learning and experimentation with video processing, FFmpeg, Redis queues, and distributed worker architectures.

About

This ia a Video Transcoder which uses ffmpeg, redis queues to transcode videos to different formats like 144p 240p as specified

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages