Includes: - Installation instructions for testing in a virtualenv - Detailed reference for all ps-serve commands (init, create-user, create-key, serve) - Complete workflow examples - Troubleshooting guide - Development tips and security best practices - Quick reference cheat sheet Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Update readme Add userinfo endpoint and asset backup script. Fix s3 and add new DB fields Add pyproject file Cleanup
7.0 KiB
Private Studio - Video Transcoding Web Service
A FastAPI-based video transcoding management service with S3-compatible file uploads, API key authentication, and per-user resource isolation.
Features
- S3-Compatible Interface: Upload, download, delete, and list files using S3-compatible HTTP endpoints
- API Key Authentication: Secure bearer token authentication with per-user isolation
- YAML-Based Transcode API: Request transcode jobs and manage encoding profiles via YAML
- SQLite Database: Lightweight file-based database with SQLAlchemy ORM
- User Management: Create users and API keys via CLI
Installation
Install the package with all dependencies:
pip install -e .
Or install development dependencies:
pip install -e ".[dev]"
Quick Start
1. Initialize Database
ps-serve init
This creates a transcoding.db file in the current directory.
2. Create a User
ps-serve create-user myuser
3. Create an API Key
ps-serve create-key 1
This outputs an API key that should be kept secret:
API key created for user 1
Key: 4YXDJoXf26auwGFQPKB6aB-kY6HxbkKPJzmWFbs7cnM
Keep this key safe - you won't be able to see it again!
4. Start the Server
ps-serve serve
The server will start at http://localhost:8000
Configuration
Environment variables:
DATABASE_URL: SQLite database path (default:./transcoding.db)STORAGE_PATH: File storage directory (default:./storage)SERVER_HOST: Server host address (default:0.0.0.0)SERVER_PORT: Server port (default:8000)SQL_ECHO: Enable SQL query logging (default:false)
Example:
export DATABASE_URL="sqlite:///./my_transcoding.db"
export STORAGE_PATH="./media"
ps-serve serve --host 127.0.0.1 --port 8080
API Usage
Authentication
All endpoints require an API key via Bearer token:
curl -H "Authorization: Bearer YOUR_API_KEY" http://localhost:8000/api/keys
S3-Compatible File Operations
Upload a file:
curl -X PUT \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@video.mp4" \
http://localhost:8000/s3/1/videos/video.mp4
Download a file:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/s3/1/videos/video.mp4 \
-o video.mp4
List files:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/s3/1
Delete a file:
curl -X DELETE \
-H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/s3/1/videos/video.mp4
Transcode Profile Management
Create a profile:
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/yaml" \
-d @profile.yaml \
http://localhost:8000/api/profiles?name=my-profile
Where profile.yaml:
profiles:
hd:
resolution: "1280x720"
bitrate: "2500k"
fps: 30
sd:
resolution: "854x480"
bitrate: "1000k"
fps: 30
List profiles:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/profiles
Transcode Job Requests
Request a transcode job with a stored profile:
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/yaml" \
-d 'asset: video.mp4
profile: my-profile' \
http://localhost:8000/api/transcode
Or with an inline profile:
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/yaml" \
-d 'asset: video.mp4
profile:
profiles:
hd:
resolution: "1280x720"
bitrate: "2500k"' \
http://localhost:8000/api/transcode
Get job status:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/transcode/1
List jobs:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/transcode
List jobs by status:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/transcode?status=pending
API Key Management
Create an API key:
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/keys
List keys:
curl -H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/keys
Revoke a key:
curl -X DELETE \
-H "Authorization: Bearer YOUR_API_KEY" \
http://localhost:8000/api/keys/KEY_ID
Testing
Run the test suite:
pytest tests/test_web.py -v
Database Schema
Users
id: Primary keyusername: Unique usernamecreated_at: Creation timestamp
API Keys
id: Primary keykey_hash: SHA256 hash of the API keyuser_id: Foreign key to userscreated_at: Creation timestampis_active: Whether the key is active
Uploaded Assets
id: Primary keyuser_id: Foreign key to usersfilename: Original filenamesize: File size in bytess3_path: Path relative to storage rootupload_timestamp: Upload time
Transcode Profiles
id: Primary keyuser_id: Foreign key to usersname: Profile nameprofile_definition: YAML definition as stringcreated_at: Creation timestamp
Transcode Jobs
id: Primary keyuser_id: Foreign key to usersasset_id: Foreign key to uploaded_assetsprofile_id: Foreign key to transcode_profiles (nullable for inline profiles)status: Job status (pending, in_progress, completed, failed)requested_at: Request timestampcompleted_at: Completion timestamp (nullable)
Packaging Jobs
id: Primary keyuser_id: Foreign key to userstranscode_job_id: Foreign key to transcode_jobsstatus: Job status (pending, in_progress, completed, failed)requested_at: Request timestampcompleted_at: Completion timestamp (nullable)
Transcoded Assets
id: Primary keyuser_id: Foreign key to userstranscode_job_id: Foreign key to transcode_jobsfilename: Output filenames3_path: Path relative to storage rootformat: Output format (e.g., "mp4", "audio")created_at: Creation timestamp
Architecture
Authentication
API keys are stored as SHA256 hashes in the database and validated via FastAPI's HTTPBearer security scheme. Each authenticated endpoint receives the user context automatically.
Per-User Isolation
All resources (assets, profiles, jobs) are scoped to the authenticated user. Users can only access their own resources, enforced at the database query level.
File Storage
Files are stored on disk in user-specific directories under STORAGE_PATH:
storage/
├── 1/ (user 1)
│ ├── video1.mp4
│ └── video2.mp4
└── 2/ (user 2)
└── presentation.mp4
Symlink traversal attacks are prevented by validating file paths.
Development
Enable Auto-Reload
ps-serve serve --reload
View SQL Queries
export SQL_ECHO=true
ps-serve serve
Run Tests
pytest tests/test_web.py -v
With coverage:
pytest tests/test_web.py --cov=privatestudio.web --cov-report=html