This project provides an online video editing web API that allows users to upload, trim, merge, and share videos.
- Node.js (>= 16.x)
- npm (>= 8.x)
- FFmpeg (must be installed on your system)
- Clone the repository:
git clone https://github.com/Mayureshjoshi18/video-api-mern.git cd video-api-mern - Install dependencies:
npm install
Start the server:
npm startThe server will run on http://localhost:3000.
Run end-to-end tests:
npx jest tests/e2e/__test__/video-api.e2e.test.tsor
npm test- Endpoint:
POST /upload - Headers:
{ "Authorization": "Bearer static-token" } - Form Data:
video: <file> - Response:
{ "videoId": "generated-video-id" }
- Endpoint:
POST /trim - Headers:
{ "Authorization": "Bearer static-token", "Content-Type": "application/json" } - Request Body:
{ "videoId": "generated-video-id", "startTime": 10, "endTime": 30 } - Response:
{ "trimmedVideoId": "trimmed-video-id" }
- Endpoint:
POST /merge - Headers:
{ "Authorization": "Bearer static-token", "Content-Type": "application/json" } - Request Body:
{ "videoIds": ["video1-id", "video2-id"] } - Response:
{ "mergedVideoId": "merged-video-id" }
- Endpoint:
POST /share - Headers:
{ "Authorization": "Bearer static-token", "Content-Type": "application/json" } - Request Body:
{ "videoId": "generated-video-id", "expiryTime": 3600 } - Response:
{ "link": "/view/shared-link-id" }
- Endpoint:
GET /view/:sharedLinkId - Response:
{ "videoUrl": "https://localhost:3000/link.mp4" }
- Router (
routes.ts) - Defines API endpoints and forwards requests to corresponding controllers. - Controller (
controller.ts) - Extracts request data, calls the service layer, and handles responses. - Service (
service.ts) - Contains business logic for video processing (upload, trim, merge, share). - Database (
database.ts) - Executes SQL queries to store and retrieve video data.
For example, when a user shares a video:
- The request goes to
routes.ts, which callsshareVideoHandlerincontroller.ts. - The
controller.tsextractsvideoIdandexpiryTimeand callsshareVideofromservice.ts. service.tsvalidates inputs, queries the database to check if the video exists, and generates a shareable link.- The generated link is saved in
shared_linkstable, and a response is returned to the user.
MIT