How nikopueringer/corridorkey works
1. Overall shape
CorridorKey is a Python-based batch media processing tool, not a service or web app. Its architecture is centered on a CLI-driven workflow that takes shot folders or loose clips, generates/ingests an alpha hint, runs neural inference, and writes keying outputs back to disk.
2. Primary entry points
The main user-facing orchestrators are clip_manager.py and corridorkey_cli.py. These expose commands like wizard/list/run_inference and are responsible for device/backend selection, clip discovery, and launching the processing pipeline. The shell/batch launchers and install scripts are just wrappers around these entry points.
3. Workflow orchestration layer
The backend/ package is the repository’s coordination layer. It handles clip state, job queuing, project structure, validation, frame I/O, ffmpeg integration, and error handling. This is where the “batch processor” behavior lives: organizing clips into shot folders, deciding what is ready to process, and tracking per-clip progress and outputs.
4. Project and clip model
backend/project.py, backend/clip_state.py, and backend/validators.py define the repository’s notion of a valid shot. The expected folder structure is important: an input clip sequence plus hint folders such as AlphaHint/ and optional VideoMamaMaskHint/. The orchestration layer uses this structure to pair footage with the correct hints and to decide whether a clip needs auto-organization.
5. Frame and file boundary
backend/frame_io.py and backend/ffmpeg_tools.py form the boundary between filesystem/video assets and model-ready tensors. They are the bridge that reads image sequences or encoded media, converts frames into the formats the models expect, and writes output images/video-compatible artifacts back to disk.
6. Core CorridorKey inference
CorridorKeyModule/ contains the main unmixing model implementation. wrapper.py is the high-level model entry, while inference_engine.py and core/model_transformer.py represent the actual inference pipeline and tensor transformations. core/color_utils.py indicates that color-space handling is a first-class concern, which matches the repo’s emphasis on linear vs sRGB processing and preserving straight color plus alpha.
7. Main model outputs
The core model is designed to produce two key signals per pixel: a clean linear alpha matte and the straight foreground color. The repo’s output structure reflects this separation: /Matte for alpha, /FG for foreground color, /Processed for premultiplied preview/compositing convenience, and /Comp for quick checkerboard previews.
8. Alpha hint generation subsystem
The repository integrates two optional “hint generator” subsystems to supply coarse masks to the main keyer:
- gvm_core/ packages Generative Video Matting.
- VideoMaMaInferenceModule/ packages VideoMaMa.
These are not required for the keyer itself, but they are important upstream dependencies in the full workflow because CorridorKey’s quality depends heavily on the hint quality.
9. Optional hint backends
gvm_core/gvm/... contains the GVM model and pipeline code, and VideoMaMaInferenceModule/pipeline.py plus inference.py contain the VideoMaMa inference path. The orchestration layer can invoke these modules to generate alpha hints automatically when the user has not provided one manually.
10. Lightweight hinting / auxiliary model support
BiRefNetModule/ is a separate optional alpha-hint generator path. It is much lighter than GVM/VideoMaMa and functions as another upstream way to produce coarse subject masks for the main CorridorKey model.
11. Backend and hardware selection boundary
device_utils.py and the README’s backend logic show that inference can run through multiple runtimes: Torch on CUDA/MPS/CPU, or MLX on Apple Silicon. This affects architecture because device/backend choice happens before model execution and determines which code path, weights format, and runtime constraints are used.
12. Weights and checkpoint management
The repo separates code from large model assets. Each major subsystem has its own checkpoint/weights directory: CorridorKeyModule/checkpoints, gvm_core/weights, VideoMaMaInferenceModule/checkpoints, and BiRefNetModule/checkpoints. The application auto-downloads or expects these assets at runtime, so the architecture depends on external model repositories and local cache folders.
13. Processing lifecycle
The end-to-end flow is: discover clips → validate/organize shot folders → acquire or generate alpha hints → select screen color/backend/device → run core unmixing inference → write EXR/preview outputs. backend/job_queue.py and backend/service.py suggest the run is managed as queued work rather than a one-shot script.
14. Testing and support tooling
tests/ covers the key architecture boundaries: backend behavior, CLI behavior, device selection, frame I/O, color math, and end-to-end workflow. scripts/convert_pth_to_safetensors.py and the Docker/compose files support deployment and model packaging, but they are ancillary to the runtime architecture.
15. What to draw in an architecture diagram
The diagram should emphasize three tiers:
- CLI/orchestration: user commands, clip manager, backend services, project validation.
- Inference engines: CorridorKey core model plus optional hint generators (GVM, VideoMaMa, BiRefNet).
- Asset/runtime boundaries: clip folders, hint folders, checkpoint/weight stores, ffmpeg/frame I/O, and device/backend selection.
The main dataflow is from input footage and coarse hint to separated foreground/alpha outputs, with optional auto-generated hints feeding the same inference path.
Main entry points: service.py Service · backend.py Core wrapper · inference_engine.py Inference engine · project.py Project
Components 21
CLI & backend
User entry points and batch workflow coordination
- Clip manager · Interactive clip discovery, backend selection, and workflow launch
clip_manager.py - CLI · Command-line interface for running keying workflows
corridorkey_cli.py - Service · Top-level orchestration of queued clip processing
backend/service.py - Job queue · Queues and tracks per-clip processing work
backend/job_queue.py - Project · Represents valid shot folders and their processing state
backend/project.py - Clip state · Per-clip progress, readiness, and output status
backend/clip_state.py - Validators · Checks folder structure, hints, and clip readiness
backend/validators.py
Model engines
Core keying model and optional hint generators
- Core wrapper · High-level entry into CorridorKey inference
CorridorKeyModule/backend.py - Inference engine · Runs the main unmixing model pipeline
CorridorKeyModule/inference_engine.py - Transformer · Model-side tensor reshaping and inference preparation
CorridorKeyModule/core/model_transformer.py - Color utils · Linear and sRGB color handling for keying output
CorridorKeyModule/core/color_utils.py - GVM wrapper · Generative Video Matting hint generation entry point
gvm_core/wrapper.py - VideoMaMa · Optional video matting pipeline for alpha hints
VideoMaMaInferenceModule/pipeline.py - BiRefNet · Lightweight optional mask generator for coarse hints
BiRefNetModule/wrapper.py
Assets & runtime
Filesystem boundaries, checkpoints, and media I/O
- Frame I/O · Reads image sequences and prepares frame data
backend/frame_io.py - FFmpeg · Video encoding and decoding helpers at the file boundary
backend/ffmpeg_tools.py - Device utils · Selects Torch, MLX, CUDA, MPS, or CPU execution paths
device_utils.py - CK weights · CorridorKey model checkpoints and local asset cache
CorridorKeyModule/checkpoints - GVM weights · Generative Video Matting model assets
gvm_core/weights - VM checkpoints · VideoMaMa model checkpoints
VideoMaMaInferenceModule/checkpoints - BiRefNet ckpts · BiRefNet model checkpoints
BiRefNetModule/checkpoints
Connections 22
- Clip manager → Service: launches · Starts batch processing and workflow actions
- CLI → Service: dispatches · Runs commands that reach the orchestration layer
- Service → Job queue: queues · Schedules clips for processing
- Service → Project: loads · Builds project and shot structure
- Service → Validators: validates · Checks clip folders, hints, and readiness
- Project → Clip state: tracks · Persists per-clip state and outputs
- Validators → Project: gates · Accepts or rejects shot organization
- Job queue → Device utils: selects runtime · Chooses backend and hardware before inference
- Service → Frame I/O: reads frames · Bridges media files into model-ready data
- Service → FFmpeg: writes media · Encodes outputs and handles video boundary
- Frame I/O → Core wrapper: feeds frames · Provides input frames to the model entry
- Core wrapper → Inference engine: runs · Invokes the core unmixing pipeline
- Inference engine → Transformer: prepares tensors · Transforms inputs for the model
- Inference engine → Color utils: applies color · Handles linear and sRGB conversions
- GVM wrapper → GVM weights: loads · Uses GVM checkpoints for hint generation
- VideoMaMa → VM checkpoints: loads · Uses VideoMaMa checkpoints for hints
- BiRefNet → BiRefNet ckpts: loads · Uses BiRefNet checkpoints for masks
- GVM wrapper → Service: supplies hints · Can generate alpha hints before main inference
- VideoMaMa → Service: supplies hints · Can generate alpha hints before main inference
- BiRefNet → Service: supplies hints · Can generate alpha hints before main inference
- Service → Core wrapper: invokes core · Hands validated clips and hints to CorridorKey
- Core wrapper → CK weights: loads · Reads CorridorKey checkpoints at runtime