How svsdval/video2midi works
Project Type and Purpose
• Type: A standalone, full-stack command-line tool (monolithic application) with an interactive UI layer for parameter tuning, and a video-to-MIDI conversion pipeline.
• Purpose: Read Synthesia (or similar) piano-roll videos, detect key presses frame by frame, and emit a corresponding multi-channel MIDI file.
File Structure
Top-level components:
• v2m.py – Entry point / command-line interface
• video2midi/ – Core processing package
– gl.py – OpenGL/pygame-based visualization & input handling
– midi.py – MIDI event creation (wraps midiutil)
– settings.py & prefs.py – Configuration & user preferences loader
• docs/ – Install & manual guides, screenshots
• tests/ – Unit tests for settings, sample INI files
• midis/ – Sample input/output data (not part of runtime)
• CI config (GitHub workflows), requirements.txt / pyproject.toml
README Insights
• Lists required libraries: python-opencv, python-pygame, python-opengl, python-midiutil.
• Describes the interactive controls (key mapping, frame ranges, channel splitting).
• Mentions optional multi-channel & instrument mapping via INI.
Main Components
A. CLI / Orchestration Layer
– v2m.py: argument parsing, loading settings, initializing UI and processing loop.
B. Configuration Store
– settings.py / prefs.py: load/override logic (home directory vs. working dir).
C. Video Input & Frame Grabber
– OpenCV module: open video file, read frames, handle start/end frame.
D. UI / Visualization & Control
E. Processing Pipeline
– Note Tracker: track active notes per channel, handle overlap/ignore/min-duration logic.
F. MIDI Generator
– midi.py (midiutil wrapper): translate tracked note events into MIDI tracks, apply program changes.
– Output Writer: write .mid file to disk when processing completes or on abort.
G. External Dependencies
– Libraries: OpenCV (cv2), pygame, PyOpenGL, midiutil.
– Operating system: reads/writes local files.
Relationships & Data Flow
1. User invokes v2m.py with a video path.
2. v2m.py loads settings (INI) → instantiates UI and processing components.
3. Video Input (OpenCV) supplies frames to Frame Processor.
4. Frame Processor sends results to Note Tracker.
5. Tracker emits note-on/note-off events to MIDI Generator.
6. UI Layer renders the live keyboard + assists in realtime parameter tuning.
7. MIDI Generator accumulates events, then writes the .mid file to disk.
Architectural Patterns & Design Principles
• Modular layering: separate I/O, processing, UI, and output responsibilities.
• Configuration-driven behavior: all thresholds, mappings, and instrument settings live in INI.
• Event-driven UI: asynchronous user commands modify runtime behavior (start/end frame, channel split).
• Single process, no services/microservices.