A secure, scalable video streaming service built with FastAPI, Celery, and MinIO for custom video hosting and streaming.
.
βββ .env
βββ .env.example
βββ .gitignore
βββ app
β βββ __init__.py
β βββ api
β β βββ __init__.py
β β βββ auth.py
β β βββ videos.py
β βββ core
β β βββ __init__.py
β β βββ config.py
β β βββ database.py
β β βββ security.py
β βββ main.py
β βββ models
β β βββ __init__.py
β β βββ video.py
β βββ services
β β βββ __init__.py
β β βββ minio_service.py
β β βββ video_service.py
β βββ storage
β β βββ __init__.py
β β βββ local_storage.p
β βββ workers
β βββ __init__.py
β βββ video_worker.py
βββ celery_worker
β βββ __init__.py
β βββ tasks.py
β βββ worker.py
βββ docker
β βββ docker-compose.yml
β βββ Dockerfile
βββ frontend
β βββ video-player.html
β βββ video-player.js
βββ README.md
βββ requirements.txt
Copy the example environment file and configure your settings:
cp .env.example .env
# Edit .env with your specific configuration
pip install -r requirements.txt
# Start all services (FastAPI, Celery, MinIO, Redis)
docker-compose -f docker/docker-compose.yml up --build --remove-orphans
# Or run locally for development
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- FastAPI API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- MinIO Console: http://localhost:9001 (admin/password123)
- Video Player Example: Open
frontend/video-player.html
POST /auth/login
- Admin loginPOST /auth/refresh
- Refresh JWT token
GET /videos/
- List all videos (admin only)POST /videos/upload
- Upload new video (admin only)GET /videos/{video_id}/status
- Check upload statusGET /videos/{video_id}/stream
- Stream video (blob response)DELETE /videos/{video_id}
- Delete video (admin only)
GET /videos/{video_id}/stream
- Secure video streaming endpointGET /videos/{video_id}/thumbnail
- Get video thumbnailPOST /videos/{video_id}/progress
- Save video progress
- Admin uploads video via
/videos/upload
- Celery task processes upload asynchronously
- Status tracking via
/videos/{video_id}/status
- Secure streaming via
/videos/{video_id}/stream
- JWT Authentication for admin operations
- Blob streaming prevents direct file access
- Presigned URLs for temporary access
- Rate limiting on streaming endpoints
- File validation (size, format, duration)
Videos automatically resume from the last watched position using:
- Frontend localStorage for position tracking
- Server-side progress API for cross-device sync
- Blob streaming with range requests
// Example: Streaming video in React
const VideoPlayer = ({ videoId }) => {
const videoRef = useRef(null);
useEffect(() => {
const streamVideo = async () => {
const response = await fetch(`/videos/${videoId}/stream`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const blob = await response.blob();
const videoUrl = URL.createObjectURL(blob);
if (videoRef.current) {
videoRef.current.src = videoUrl;
// Resume from saved position
const savedTime = localStorage.getItem(`video_${videoId}_time`);
if (savedTime) {
videoRef.current.currentTime = parseFloat(savedTime);
}
}
};
streamVideo();
}, [videoId]);
return (
<video
ref={videoRef}
controls
onTimeUpdate={(e) => {
// Save progress
localStorage.setItem(`video_${videoId}_time`, e.target.currentTime);
}}
/>
);
};
The docker-compose setup includes:
- FastAPI app (port 8000)
- Celery worker for background tasks
- Redis for Celery broker
- MinIO for object storage (port 9000/9001)
- PostgreSQL for production database
pytest tests/
alembic upgrade head
- Celery Flower: http://localhost:5555
- MinIO Metrics: Available via MinIO console
- Replace SQLite with PostgreSQL
- Use AWS S3 instead of MinIO
- Implement CDN for video delivery
- Add video transcoding pipeline
- Set up monitoring and logging
- Configure SSL/TLS certificates
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.