This Node.js application provides a RESTful API for video upload, trimming, concatenation, and sharing with time-based expiry links. It leverages FFmpeg for video processing and SQLite for data storage.
- User Authentication: Secure user authentication using JWT.
- Video Upload: Upload videos with configurable size and duration limits.
- Video Trimming: Trim videos to specified start and end times.
- Video Concatenation: Concatenate multiple videos into a single video.
- Database: Uses SQLite for data storage.
Ensure you have the following installed before starting:
- Node.js: Version 14 or higher.
- npm: Node Package Manager.
- FFmpeg: Installed on your system.
- SQLite: Installed on your system.
Follow these steps to set up the project:
-
Clone the Repository:
- Using SSH:
git@github.com:ruthwikchikoti/vidcraft-api.git - Using HTTPS:
git clone https://github.com/ruthwikchikoti/vidcraft-api.git - Alternatively, download the repository as a ZIP file and extract it.
- Using SSH:
-
Navigate to the Project Directory:
cd video-processing-api -
Install Dependencies:
npm install
-
Set Up Environment Variables:
- Create a
.envfile in the root directory and add the following:JWT_SECRET_KEY=your_secret_key_here
- Create a
-
Install Nodemon (Optional):
- For easier development, install Nodemon:
npm install -g nodemon
- For easier development, install Nodemon:
-
Start the Server:
- Use Nodemon for development:
nodemon index.js
- Or use Node.js directly:
node index.js
- Use Nodemon for development:
-
Access the API:
- The API will be available at
http://localhost:3000.
- The API will be available at
- Sign Up:
POST /api/auth/signup- Create a new user account.
- Log In:
POST /api/auth/login- Log in and receive a JWT.
All video processing endpoints require authentication. Include the JWT in the Authorization header.
- Upload Video:
POST /api/videos/upload- Upload a video file.
- Trim Video:
POST /api/videos/trim- Trim a video to specified start and end times.
- Concatenate Videos:
POST /api/videos/concatenate- Concatenate multiple videos into a single video.
-
Sign Up:
- Create an account using a username and password.
-
Log In:
- Log in with the same username and password to receive an accessToken.
-
Authorization:
- Include the accessToken in the Authorization header as a Bearer Token for subsequent requests.
-
Upload Video:
- Upload a video using form-data or binary.
-
Trim Video:
- Provide the videoId, start, and end times to trim the video.
-
Concatenate Videos:
- Provide the videoIds to concatenate multiple videos.
The API uses standard HTTP status codes for error responses. Check the response body for detailed error messages.
- Authentication: JWT is used for stateless authentication to improve scalability.
- Video Processing: FFmpeg is chosen for its robustness and wide format support.
- Database: SQLite is used for simplicity and ease of setup. For production, consider using a more robust database like PostgreSQL.
- Link Expiry: Random tokens are generated for sharing links, with expiry times stored in the database. A background job periodically cleans up expired links.
- File Storage: Videos are stored in the local filesystem. For production, consider using cloud storage solutions.
- Error Handling: Centralized error handling middleware ensures consistent error responses across the API.
- MVC Pattern: The project follows the Model-View-Controller pattern for clear separation of concerns.
- Middleware: Used for authentication and request validation.
- Services: Encapsulate business logic.
- Repositories: Abstract database operations.
- Centralized Error Handling: Ensures consistent error responses.