Fussball-Videoanalyse · Pre-Alpha
Kickframe
Kickframe is local-first football video analysis in pure Rust, with a native app and a headless command-line tool on one command engine.
Diese technische Dokumentation gibt es nur auf Englisch.
Overview
Kickframe turns a football video into tracks, teams and ball positions on the user’s own machine. Every action is an engine command, so the native app and the CLI behave the same.
Kickframe never invents analysis. A result that has no data shows as unavailable and names what it waits on. Every number carries its pipeline run, coverage and sample size.
Analysis stages
A video moves through import, proxy, frames, detection, tracking and team assignment.
Prepare
- Import
- Proxy
- Frames
Perceive
- Detect
Follow
- Track
- Teams
Each stage writes its own artifact, so a later stage can rerun without repeating earlier ones.
Code size
- engine18,136
- ui-egui12,464
- pipeline10,970
- domain5,264
- geom3,696
Architecture
Kickframe is a Rust workspace of 16 crates in eight layers, with dependencies checked in CI.
Kickframe is one Rust workspace with a native desktop app and a headless CLI. Both are thin shells over the same engine. There is no webview and no server process in normal use.
Layers
Crates sit in eight layers, L0 to L7. A crate depends on crates below it. cargo xtask layers checks this rule and fails the build when a crate breaks it.
Eight layers from applications at L7 down to foundation crates at L0. Arrows point toward lower layers.
L7 Apps
- apps/kickframe
- apps/kickframe-cli
L6 Surfaces
- ui-egui
- automation
L5 Engine
- enginetyped commands
L4 Jobs
- jobsleases and retries
L3 Pipeline
- pipeline
- store
L2 Perception
- infer
- track
- teams
- ball
L1 Domain
- domain
L0 Foundation
- geom
- media-probe
- artifact
Arrows point from a layer toward the layers it can depend on.
Crates
| Layer | Crate | Rust lines | Role |
|---|---|---|---|
| L0 | geom |
3,696 | Geometry |
| L0 | media-probe |
802 | Media file inspection |
| L0 | artifact |
711 | Analysis artifact files |
| L1 | domain |
5,264 | Core types and motion calculations |
| L2 | infer |
3,519 | Object detector and model loading |
| L2 | track |
1,843 | Multi-object tracking |
| L2 | teams |
630 | Team assignment from jersey colour |
| L2 | ball |
691 | Ball detection and filtering |
| L3 | pipeline |
10,970 | Analysis stages from import to trajectories |
| L3 | store |
2,120 | SQLite database and migrations |
| L4 | jobs |
629 | Background job execution |
| L5 | engine |
18,136 | Session, Command and the command registry |
| L6 | ui-egui |
12,464 | Native interface |
| L6 | automation |
390 | Loopback control server and snapshots |
| L7 | apps/kickframe |
654 | Desktop app binary |
| L7 | apps/kickframe-cli |
2,163 | Headless CLI binary |
The workspace holds about 64,700 lines of Rust.
- engine18,136
- ui-egui12,464
- pipeline10,970
- domain5,264
- geom3,696
- infer3,519
- kickframe-cli2,163
- store2,120
- track1,843
- media-probe802
- artifact711
- ball691
- kickframe654
- teams630
- jobs629
- automation390
Project rules
| Rule | What it means in the code |
|---|---|
| Never crash | Non-test code has no unwrap, expect, panic, todo, unreachable or indexing. unsafe_code is forbidden. |
| Respect layers | cargo xtask layers rejects a dependency that points the wrong way. |
| Everything is a command | The app and the CLI perform actions through engine commands. |
| No fake analysis | Missing results are Availability::Unavailable and name what they wait on. |
| Corrections are overlays | A user correction is stored on top of the analysis and never rewrites it. |
| Tests are the gate | A change lands only when the checks pass. |
| Pin models by hash | A model file with the wrong hash does not load. |
Recorded decisions
The project records architecture decisions as numbered ADRs.
| ADR | Decision |
|---|---|
| 0001 | SQLite now, with portable SQL so Postgres stays possible |
| 0002 | Video input and output through external FFmpeg and FFprobe |
| 0004 | RF-DETR detector with four classes |
| 0007 | Proposal for a GPUI Kit desktop interface |
Analysis pipeline
How Kickframe turns an imported video into detections, tracks, teams, ball positions and measured motion.
The pipeline takes one video and writes its results as artifacts for that match and run. Frame-level data goes to JSONL files under data/processed/{match}/{run}. Relational rows in SQLite hold the summaries.
Four groups of stages. Prepare has import, proxy and frames. Perceive has object detection and the scene map. Follow has tracking, team assignment and ball filtering. Measure has calibration, trajectories and the overlay window.
Prepare
- Importchecks and SHA-256
- ProxyH.264 MP4, time map
- FramesRGB24, source PTS
Perceive
- detect_objectsdetections.jsonl
- Scene mapcut positions
Follow
- track_objectstracks.jsonl
- assign_teamsteams.jsonl
- Ballball.jsonl
Measure
- calibratemanual-calibration-v1
- trajectoriesdistance and speed
- overlay-windowvideo overlays
Import
Import validates a file before any analysis starts. It checks rights, file type, size and duration, and records a SHA-256 checksum.
Proxy and frames
The proxy stage writes an H.264 MP4 and a map between source frame times and proxy frame times. Results can then point back to the original video.
The frame stage decodes into bounded RGB24 buffers. Each frame keeps its source presentation timestamp (PTS). Video input and output run through external FFmpeg and FFprobe processes, using ffmpeg-sidecar.
Detection and scene map
detect_objects runs the detector on frames and writes detections.jsonl. The model has four classes, player, goalkeeper, referee and ball. The Models and evidence page covers how models load.
The scene map marks camera cuts. Tracking and ball filtering use it, so a track or ball path does not continue across a cut.
Tracking
track_objects takes the detections and writes tracks.jsonl.
| Step | Method |
|---|---|
| Pitch filter | A green mask removes detections outside the pitch |
| Scene cuts | Tracking respects the cuts in the scene map |
| Association | ByteTrack links detections into tracks |
| Jersey samples | Each track collects colour samples for team assignment |
Team assignment
assign_teams reads the jersey samples and writes teams.jsonl. It takes Lab colour medians and clusters them with 2-means, one cluster per team. Samples far from both clusters are outliers, which covers goalkeepers and referees.
Ball
The ball is small and fast, so it has its own stage and writes ball.jsonl.
- A tiled detector looks at parts of the frame at a higher effective resolution.
- A displacement gate in source time rejects jumps that are too large for the elapsed time.
- Predicted positions carry a label that separates them from observed positions.
- The filter resets at scene cuts.
Calibration and motion
calibrate takes landmarks that a user marks by hand and computes a homography from image to pitch coordinates. The result is stored as manual-calibration-v1.
trajectories computes observed distance and speed with domain::motion. These values are limited to what the video observed. overlay-window serves overlay data for a span of video.
Storage and jobs
Kickframe's SQLite schema, JSONL artifacts, leased job queue and append-only corrections.
Kickframe keeps two kinds of data. SQLite holds matches, runs, jobs and reviews. JSONL artifacts hold frame-level data, one directory per match and run.
Database
The store uses SQLite through rusqlite. The ADR for this choice keeps the SQL portable so Postgres stays possible later. On macOS the default database lives under Application Support/Kickframe. The KICKFRAME_DB variable selects another file. Nine migrations build the current schema.
SQLite tables grouped into analysis, jobs, review, squads and storage upkeep.
Analysis
- matches
- pipeline_runs
- step_runs
- model_runs
- artifacts
Jobs
- jobs
Review
- corrections
- segment_reviews
- video_review_revisions
- identity_corrections
Squads
- squads
- squad_matches
- match_roster
Upkeep
- cleanup_history
- cleanup_pending
Tables grouped by what they store.
Artifacts
| File | Written by | Holds |
|---|---|---|
detections.jsonl |
detect_objects |
Detector output per frame |
tracks.jsonl |
track_objects |
Linked tracks |
teams.jsonl |
assign_teams |
Team per track |
ball.jsonl |
Ball stage | Filtered and labelled ball positions |
Artifacts live at data/processed/{match}/{run}. Each run keeps its own files, so one run’s output stays separate from another’s.
Job queue
The queue lives in SQLite. A worker holds a job through a lease with an owner and an expiry time.
Cancel is a separate operation that stops a job.
| Operation | Effect |
|---|---|
enqueue |
Adds a job |
claim |
Takes the next job atomically inside BEGIN IMMEDIATE |
heartbeat |
Renews the lease |
complete |
Marks the job done |
fail |
Records a failure and schedules a retry after a delay |
cancel |
Cancels the job |
BEGIN IMMEDIATE takes the write lock at the start of the claim, so two workers cannot take the same job.
The attempts counter fences stale holders. A worker whose lease has passed to a newer attempt receives LeaseLost and cannot write a result. When the lease of a final attempt expires, the job fails instead of staying stuck.
Corrections
A user can fix analysis results, and the fixes are stored as overlays. The corrections table is append-only, so the original analysis stays intact and a correction can be reverted.
| Kind | Purpose |
|---|---|
merge_tracks |
Join two tracks into one |
split_track |
Split one track into two |
set_team |
Change a track’s team |
confirm |
Confirm a result |
mark_ball |
Mark the ball position |
revert |
Undo an earlier correction |
Models and evidence
How Kickframe loads detection models, pins them by hash and reports what each number is based on.
Detector
The Detector trait hides the inference backend from the rest of the code.
| Backend | Status | Used for |
|---|---|---|
| tract-onnx | Default | Pure Rust ONNX inference |
| ORT with CoreML | Opt-in, feature coreml |
Hardware acceleration on Apple devices |
The chosen architecture is RF-DETR in Small and Medium sizes, under the Apache-2.0 licence. It predicts four classes, player, goalkeeper, referee and ball.
Model release
A model release is a versioned directory.
data/models/<version>/
model.onnx
manifest.json
The manifest pins the model by hash. A startup gate checks the hash and class map, and rejects a model that does not match.
Training happens in Python and produces a release directory. The app checks the release at startup, and only a matching model reaches the detector.
Training
- Python toolingoutside the app
Release
- model.onnx
- manifest.jsonhash and classes
Startup gate
- Hash and class map checkrejects a mismatch
Inference
- tract-onnx
- ORT with CoreML
The app only runs models. It never trains them.
Evidence
Kickframe has a strict rule against fake analysis, and the types enforce it.
- A result with no data is
Availability::Unavailable { waiting_on }. The interface shows what it waits on. - Every number carries its
PipelineRun, its coverage and its sample size. - Predicted ball positions are labelled as predictions.
- Distance and speed describe what the video observed.
A reader can always see which run produced a number and how much of the match it covers.
Engine and interfaces
The typed command engine behind Kickframe's native app, headless CLI and automation server.
Every action in Kickframe is an engine command. A Session executes typed Command values, and the COMMANDS registry lists what exists. The native app, the CLI and the automation server all go through this path, so a feature behaves the same in each.
The native interface, the CLI and the control server send commands to the engine session, which uses the pipeline, the store and the job queue.
Interfaces
- egui app
- Headless CLI
- Control server
Engine
- Session
- Command
- COMMANDS registry
Services
- pipeline
- store
- jobs
Commands
| Area | Commands |
|---|---|
| Matches | import, list, status, relink |
| Analysis | run, work, tracks, trajectories, calibrate, correct |
| Video | video-index, video-frame, overlay-window |
| Review | video-review, video-review-save |
| Squads | squads, squad, squad-save, squad-assign |
| Storage | storage, backup, cleanup, cleanup-resume, export, snapshot |
| Diagnostics | doctor, commands |
Native app
The desktop app uses egui, in the ui-egui crate. It runs natively with no webview. An ADR records a proposal for a GPUI Kit desktop interface.
Headless CLI
apps/kickframe-cli exposes the same engine in a terminal. It suits scripted runs and machines with no display.
Automation
The automation crate serves JSON control requests on a loopback port, started with --control <port>. It also renders offscreen PNG snapshots of the interface, so tests and tools can check it without a visible window.
Quality and roadmap
The checks every Kickframe change passes, and the milestones toward a first usable release.
Kickframe is pre-alpha, at version 0.0.1. It has about 668 tests.
Change gate
CI / check runs on every pull request. A documentation check always runs. A change to anything other than documentation runs the full gate.
| Check | Command or scope |
|---|---|
| Documentation | cargo xtask docs |
| Formatting | cargo fmt --check |
| Layer rules | cargo xtask layers |
| Lints | clippy with -D warnings |
| Tests | Unit and integration tests |
| Model tooling | Training and release tools |
| Media | FFmpeg integration |
Roadmap
| Milestone | Scope | Status |
|---|---|---|
| M0 | Foundation | Complete |
| M1 | Media and jobs | Complete |
| M2 | Perception | In progress |
| M3 | Tracking and teams | In progress |
| M4 | Viewer | In progress |
| M5 | Review and MVP gate | In progress |
The project tracks readiness for a first usable release at about 3%.