4.6 KiB
Remotion Render Service
A high-performance video rendering service built with ElysiaJS and Remotion. This service accepts S3 URLs for input videos, renders them using Remotion compositions, and returns S3 URLs for the rendered outputs.
Features
- S3 Integration: Direct integration with S3-compatible storage (MinIO)
- Remotion Rendering: Leverages Remotion for high-quality video rendering
- ElysiaJS Server: Fast, type-safe API with automatic validation
- Bun Runtime: Utilizes Bun for optimal performance
Project Structure
server/
├── server.ts # Main server entry point
├── shared/
│ └── config.ts # Global configuration
└── routers/
├── render_file/
│ ├── index.ts # Render endpoint
│ ├── service.ts # Render logic
│ ├── types.ts # Type definitions
│ └── constants.ts # Endpoint constants
└── services/
└── s3_storage/
├── index.ts # S3 service implementation
├── types.ts # Type definitions
├── utils.ts # Helper functions
└── constants.ts # Service constants
Setup
-
Install Dependencies
bun install -
Configure Environment Copy
.env.exampleto.envand fill in your configuration:cp .env.example .envRequired environment variables:
S3_ACCESS_KEY: Your S3/MinIO access keyS3_SECRET_KEY: Your S3/MinIO secret keyS3_BUCKET_NAME: Target bucket nameS3_ENDPOINT_URL: S3/MinIO endpoint URLPORT: Server port (default: 3001)
-
Start the Server
bun run server
API Endpoints
POST /render/file
Renders a video from an S3 input URL and returns the rendered output S3 URL.
Request Body:
{
"inputS3Url": "https://minio.example.com/bucket/input/video.mp4",
"compositionId": "Main",
"outputFormat": "mp4"
}
Response:
{
"success": true,
"outputS3Url": "https://minio.example.com/bucket/rendered/output.mp4",
"metadata": {
"inputFile": "https://minio.example.com/bucket/input/video.mp4",
"outputFile": "https://minio.example.com/bucket/rendered/output.mp4",
"renderTime": 12500,
"fileSize": 5242880
}
}
Error Response:
{
"success": false,
"error": "Error message description"
}
GET /health
Health check endpoint.
Response:
{
"status": "healthy",
"uptime": 123.456,
"timestamp": "2024-01-01T00:00:00.000Z"
}
GET /
Service information endpoint.
Response:
{
"service": "Remotion Render Service",
"version": "1.0.0",
"status": "running",
"timestamp": "2024-01-01T00:00:00.000Z"
}
S3 Storage Service
The S3 storage service provides a comprehensive interface for interacting with S3-compatible storage:
uploadFile(): Upload files to S3downloadFile(): Download files from S3getFileUrl(): Generate presigned URLsdeleteFile(): Remove files from S3checkFileExists(): Verify file existencegetFileInfo(): Retrieve file metadatagetLocalCopy(): Download file to temp locationuploadFromLocalPath(): Upload from local filesystem
Development
Run in Development Mode
bun run server
Type Checking
bun run lint
Architecture
The service follows a modular architecture:
- Server Layer (
server.ts): Main application setup and routing - Router Layer (
routers/): Endpoint definitions and request handling - Service Layer (
services/): Business logic and external integrations - Shared Layer (
shared/): Global configuration and utilities
Integration with Django Backend
This service is designed to work alongside the Django backend in coffee_project_backend_v2. The Django backend can make requests to this service to render videos stored in the shared MinIO storage.
Example Django integration:
import requests
response = requests.post(
'http://localhost:3001/render/file',
json={
'inputS3Url': input_url,
'compositionId': 'Main',
'outputFormat': 'mp4'
}
)
result = response.json()
if result['success']:
rendered_url = result['outputS3Url']
Technologies
- Bun: Fast JavaScript runtime
- ElysiaJS: High-performance web framework
- Remotion: Programmatic video rendering
- AWS SDK: S3 client for storage operations
- TypeScript: Type-safe development