Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Video Processing App

This is a Node.js application for processing videos. It uses Express.js for the server, bullmq for queueing video processing jobs, and ffmpeg to process the videos.

How it Works

  1. Upload: The user uploads a video file through the /api/upload endpoint.
  2. Queue: The video is added to a video-queue using bullmq.
  3. Process: A background worker picks up the job from the queue and processes the video using ffmpeg. The processing include creating thumbnails, compressing the video, and changing the resolution.
  4. Status: The user can check the status of the video processing by using the /api/status endpoint.
  5. Cleanup: A cleanup worker runs every 12 hours to remove uploaded videos and clear the Redis cache.

Features

  • Video upload with multer.
  • Queue-based video processing with bullmq.
  • Video processing with ffmpeg (thumbnail generation, compression, resolution change).
  • Background worker to process videos without blocking the main thread.
  • Cleanup worker to remove old videos and clear Redis cache.
  • Downloadable thumbnails and compressed videos.
  • Get the last 3 compressed videos.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Installation

  1. Clone the repo
    git clone https://github.com/tomarrohitt/video-processing-app.git
  2. Install NPM packages
    npm install
    or
    yarn install
  3. Make sure your Redis server is running.

Usage

  1. Start the server:

    npm run dev

    This will start the Express server on port 4000.

  2. Start the worker:

    npm run worker

    This will start the background worker that processes the video jobs.

Project Structure

/video-processing-app/

├───.git/…
├───node_modules/…
└───src/
    ├───config/
    │   └───index.ts
    ├───controller/
    │   └───video-controller.ts
    ├───middlewares/
    │   ├───stats-middleware.ts
    │   └───upload-middleware.ts
    ├───queues/
    │   ├───queue-event.ts
    │   └───video-queue.ts
    ├───routes/
    │   └───video-route.ts
    ├───services/
    │   ├───ffmpeg-service.ts
    │   ├───redis-service.ts
    │   ├───stream-service.ts
    │   └───video-service.ts
    ├───socket/
    │   └───socket-server.ts
    ├───types/
    │   ├───express.d.ts
    │   └───index.ts
    ├───utils/
    │   └───get-output-path.ts
    └───workers/
        ├───cleanup-worker.ts
        └───video-worker.ts
├───.gitignore
├───index.ts
├───package.json
├───README.md
├───tsconfig.json
  • config: Configuration files.
  • controller: Express controllers that handle incoming requests.
  • middlewares: Custom middlewares for Express.
  • queues: bullmq queue definitions.
  • routes: Express routes.
  • services: Business logic and services (e.g., ffmpeg wrapper).
  • socket: Socket server for real-time communication.
  • types: TypeScript type definitions.
  • utils: Utility functions.
  • workers: Background workers that process queue jobs.

API Endpoints

POST /api/upload

Uploads a video for processing.

  • Request: multipart/form-data with a video field containing the video file.
  • Response:
    • 202 Accepted: If the video is successfully uploaded and added to the queue.
    • 400 Bad Request: If no file is uploaded or if the file is invalid.
    • 500 Internal Server Error: If there is a server error.

GET /api/stats

Gets the status of a video processing jobs in queue.

  • Response:
    • 200 OK: Returns the status of the video.

GET /api/videos

Gets the last 3 compressed videos.

  • Response:
    • 200 OK: Returns an array of the last 3 compressed videos.

GET /api/videos/:videoId

Downloads a compressed video.

  • Response:
    • 200 OK: Returns the compressed video file.

GET /api/thumbnail/:videoId/

Downloads a video thumbnail.

  • Response:
    • 200 OK: Returns the thumbnail image file.

About

Node.js video processing app with background jobs, real-time progress, and streaming. Features FFmpeg compression, BullMQ queues, Redis storage, and WebSocket updates.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages