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.
- Upload: The user uploads a video file through the
/api/uploadendpoint. - Queue: The video is added to a
video-queueusingbullmq. - 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. - Status: The user can check the status of the video processing by using the
/api/statusendpoint. - Cleanup: A cleanup worker runs every 12 hours to remove uploaded videos and clear the Redis cache.
- 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.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Clone the repo
git clone https://github.com/tomarrohitt/video-processing-app.git
- Install NPM packages
or
npm install
yarn install
- Make sure your Redis server is running.
-
Start the server:
npm run dev
This will start the Express server on port 4000.
-
Start the worker:
npm run worker
This will start the background worker that processes the video jobs.
/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:bullmqqueue definitions.routes: Express routes.services: Business logic and services (e.g.,ffmpegwrapper).socket: Socket server for real-time communication.types: TypeScript type definitions.utils: Utility functions.workers: Background workers that process queue jobs.
Uploads a video for processing.
- Request:
multipart/form-datawith avideofield 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.
Gets the status of a video processing jobs in queue.
- Response:
200 OK: Returns the status of the video.
Gets the last 3 compressed videos.
- Response:
200 OK: Returns an array of the last 3 compressed videos.
Downloads a compressed video.
- Response:
200 OK: Returns the compressed video file.
Downloads a video thumbnail.
- Response:
200 OK: Returns the thumbnail image file.