How hammad123454321/gta-game-kill-detect works
1. Overall shape
This is a two-tier MVP: a Next.js frontend for upload/configuration/results, and a FastAPI backend that handles video ingestion, asynchronous clip generation, storage, and download delivery.
2. User-facing flow
The main workflow is: upload a gameplay recording, choose clip padding and detection mode, start processing, wait for job completion, then download either individual clips or a ZIP archive. The frontend is the orchestration UI; the backend owns all heavy video work.
3. Frontend boundary
frontend/app/page.js is the main UI surface. It likely talks to backend endpoints for upload, job start, status polling, and result retrieval. The frontend is intentionally thin: it does not process media locally, and only presents progress/results.
4. API layer
The backend exposes separate route modules under backend/app/routes/:
- upload.py for accepting source videos
- process.py for starting clip generation
- status.py for job progress
- results.py for listing/downloading generated artifacts
This separation makes the API boundary clear: upload, start, monitor, fetch.
5. Async job processing
Heavy work is offloaded from the HTTP request path into a background pipeline under backend/app/jobs/. worker.py is the queue worker entrypoint, and processor.py coordinates the end-to-end pipeline. The readme indicates Redis + RQ is used so video processing runs asynchronously instead of blocking the web server.
6. Core processing pipeline
The main media pipeline is split into focused services under backend/app/services/:
- detector.py finds kill timestamps
- cutter.py extracts clips with FFmpeg
- compressor.py shrinks clips to the 9.9 MB target
- zipper.py bundles outputs for download
- cleanup.py removes temporary artifacts
This is the key backend boundary: detect → cut → compress → package → cleanup.
7. Detection modes and signal sources
The repo supports multiple detection strategies, reflected in the README and detector.py:
- manual timestamp entry for exact verified kills
- OpenCV-based hitmarker / flash detection
- OCR-based kill-feed detection
- OCR-validated top-center kill counter detection
Architecturally, this means the detection layer is pluggable, while the downstream clip pipeline stays the same regardless of how timestamps were produced.
8. Storage model
The backend uses SQLite via SQLAlchemy (database.py, models.py) for persistent metadata such as jobs, uploads, detected events, and processing state. Generated media lives in a Docker-managed storage volume (backend_storage in the README), not in the database. That keeps metadata and large binary artifacts separated.
9. Media and filesystem utilities
Utility modules under backend/app/utils/ wrap low-level concerns:
- ffmpeg_utils.py for FFmpeg interaction
- file_utils.py for path/file management and validation
These utilities form the boundary between application logic and system-level media tooling.
10. Configuration and tuning
backend/app/config.py and backend/.env.example expose a lot of detector and pipeline tuning, especially for GTA RP HUD variability: ROI bounds, score thresholds, OCR sampling, cooldowns, and clip spacing. That configuration layer is important because detection accuracy is environment-dependent and changes the behavior of the same processing pipeline.
11. Deployment and runtime
The repo is container-first: docker-compose.yml runs the frontend, backend, Redis, and supporting storage; docker-compose.prod.yml and backend/Dockerfile/frontend/Dockerfile support production packaging; .github/workflows/deploy.yml indicates CI/CD deployment automation. This means the architecture is designed to run as a small distributed system rather than a single monolith.
12. Artifact lifecycle
The output of a successful run is a set of compressed MP4 clips plus an optional ZIP archive. Temporary frames, raw cuts, and intermediate encodes are transient and cleaned up by the backend. That lifecycle is important for diagramming: source video enters once, processing stages fan out internally, and final artifacts exit through download endpoints.
Main entry points: processor.py Processor · main.py API App · docker-compose.yml Compose Stack · detector.py Detector
Components 22
Frontend
Next.js user interface for upload, processing, and results
API Layer
FastAPI app entrypoint and route modules
- API App · Backend application entrypoint and router wiring
backend/app/main.py - Upload API · Accepts source video uploads
backend/app/routes/upload.py - Process API · Starts clip generation jobs
backend/app/routes/process.py - Status API · Reports job progress and state
backend/app/routes/status.py - Results API · Lists and serves generated clips and archives
backend/app/routes/results.py
Processing Core
Async jobs, media pipeline, storage, and config
- Worker · Background queue worker entrypoint
backend/app/jobs/worker.py - Processor · Coordinates the end-to-end async pipeline
backend/app/jobs/processor.py - Detector · Finds kill timestamps using manual and vision/OCR modes
backend/app/services/detector.py - Cutter · Extracts clips from the source recording
backend/app/services/cutter.py - Compressor · Shrinks clips toward the target size limit
backend/app/services/compressor.py - Zipper · Bundles clips into downloadable ZIP archives
backend/app/services/zipper.py - Cleanup · Removes temporary frames, cuts, and intermediates
backend/app/services/cleanup.py - SQLite DB · Persists jobs, uploads, detected events, and processing state
backend/app/database.py - Data Models · Database schema and ORM entities
backend/app/models.py - Config · Environment-driven thresholds and detector settings
backend/app/config.py - FFmpeg Utils · Low-level FFmpeg integration helpers
backend/app/utils/ffmpeg_utils.py - File Utils · Path, validation, and file management helpers
backend/app/utils/file_utils.py
Infrastructure
Runtime services and deployment packaging
- Redis Queue · Backs asynchronous RQ processing
- Storage Volume · Docker-managed volume for source videos and outputs
- Compose Stack · Container orchestration for frontend, backend, Redis, and storage
docker-compose.yml
Connections 28
- Main UI → API App: API calls · UI talks to backend endpoints for upload, processing, status, and downloads
- App Shell → Main UI: wraps · App shell provides the page framework and styling
- API App → Upload API: mounts · Main app registers upload routes
- API App → Process API: mounts · Main app registers process routes
- API App → Status API: mounts · Main app registers status routes
- API App → Results API: mounts · Main app registers results routes
- Upload API → Storage Volume: writes · Uploaded source media is stored on disk volume
- Process API → Redis Queue: enqueues · Processing requests are queued for async execution
- Status API → SQLite DB: reads · Status endpoint reads persisted job state
- Results API → Storage Volume: serves · Results endpoint exposes generated artifacts
- Redis Queue → Worker: dequeues · Worker consumes queued processing jobs
- Worker → Processor: executes · Worker hands off to pipeline orchestration
- Processor → Detector: detects · Pipeline first identifies kill timestamps
- Processor → Cutter: cuts · Pipeline extracts clips after detection
- Processor → Compressor: compresses · Pipeline reduces clip sizes before delivery
- Processor → Zipper: packages · Pipeline optionally bundles outputs into ZIPs
- Processor → Cleanup: cleans · Pipeline removes temporary artifacts at the end
- Detector → Config: uses · Detection behavior is tuned by environment settings
- Detector → FFmpeg Utils: analyzes · Media analysis relies on low-level video tooling
- Cutter → FFmpeg Utils: encodes · Clip extraction uses FFmpeg helpers
- Compressor → FFmpeg Utils: transcodes · Compression is implemented through FFmpeg wrappers
- Processor → SQLite DB: updates · Processing state is persisted through ORM-backed metadata
- SQLite DB → Data Models: maps · ORM models define persisted entities
- Processor → File Utils: manages files · Pipeline uses filesystem helpers for paths and validation
- Compose Stack → Main UI: runs · Compose stack deploys the frontend service
- Compose Stack → API App: runs · Compose stack deploys the backend service
- Compose Stack → Redis Queue: runs · Compose stack provides the queue broker
- Compose Stack → Storage Volume: mounts · Compose stack provisions persistent artifact storage