Skip to content

Start improving high-throughput multi-camera recording path and diagnostics#85

Draft
C-Achard wants to merge 6 commits into
cy/preserve-mono-supportfrom
cy/improve-encoding-speed
Draft

Start improving high-throughput multi-camera recording path and diagnostics#85
C-Achard wants to merge 6 commits into
cy/preserve-mono-supportfrom
cy/improve-encoding-speed

Conversation

@C-Achard

Copy link
Copy Markdown
Contributor

Summary

Improves multi-camera recording behavior under high-throughput conditions by separating recording frame delivery from the heavier GUI/DLC processing path, adding clearer recorder backlog/queue diagnostics, and introducing an optional faster encoding mode for supported FFmpeg codecs.
This is a first quick remediation to the deeper architectural concern requiring the recording to be moved closer to camera SDK frame grabbing.

Main changes

  1. Adds a dedicated recording_frame_ready(camera_id, frame, timestamp) signal for full-rate recording frames.
  2. Recording frames are now handled by a lean recording-only path instead of _on_multi_frame_processing_ready().
  3. Recording-frame emission is disabled by default and only enabled while recording is active.
  4. Adds a "Use faster encoding" parameters checkbox in the Recording panel.
    For libx264/libx265, this applies:
    • Preset ultrafast
    • Tune zerolatency
  5. Centralizes WriteGear/FFmpeg option generation in RecordingSettings.writegear_options().
  6. Adds recorder better diagnostics
  7. Updates multi-camera recorder summaries to aggregate queue/backlog/writer throughput across cameras.
  8. Switches Basler grabbing to GrabStrategy_OneByOne so recording-oriented acquisition does not silently prefer only the latest image.
  9. Reduces noisy Basler trigger debug logs behind an explicit DEBUG_TRIGGER_LOGS flag.
  10. Adds profiling artifacts to .gitignore.
  11. Updates tests for the new recording signal, fast encoding options, recorder stats formatting, and multi-camera recording aggregation.

What this improves

This makes it easier to diagnose when the recorder is falling behind before drops occur. Previously, dropped = 0 could hide the fact that recorder queues were filling. The new stats expose that state directly through queue fill and backlog.
The fast encoding option also provides a user-controlled way to trade compression efficiency/file size for higher recording throughput.

Not solved yet

  • Recording frames still pass through the Qt/main-window path before reaching VideoRecorder.write().
  • The actual encoder write is already threaded, but the producer/enqueue side can still add main-thread pressure at very high frame rates.
  • This PR does not introduce a dedicated recording router thread or direct camera-worker-to-recorder routing.
  • This does not guarantee full-rate recording for extreme cases, but makes bottlenecks more visible and improves slightly the x264 fast path at the cost of worst file size.

Testing

Added/updated unit tests for:

  • Recording-frame signal enable/disable behavior
  • Recording overlay routing
  • RecordingSettings.writegear_options()
  • Fast encoding option propagation
  • Recorder queue/backlog stats formatting
  • Multi-recorder stats aggregation

  • Note before merge: disable debug logging

C-Achard added 6 commits June 26, 2026 15:21
Switch Basler camera startup to `pylon.GrabStrategy_OneByOne` instead of `LatestImageOnly`, and update the nearby identity-persistence comment for clarity.
Add ignore patterns for generated profiling files (`profile*.svg`, `scalene*.json`, and `scalene*.html`) so local performance analysis outputs are not accidentally committed.
Introduce a new `profiling` optional dependency group in `pyproject.toml` and include `scalene` so profiling tools can be installed independently from test and framework extras.
Adds a dedicated full-rate `recording_frame_ready` signal path so recording is decoupled from the inference/display frame flow, reducing processing overhead during capture. The GUI now exposes a fast-encoding toggle and persists it into recording settings, and recorder startup passes codec-specific writer options through to `VideoRecorder`.

Recording telemetry was expanded to report enqueued vs written frames, writer FPS, queue fill against buffer size, backlog, and drops, improving visibility into recording throughput and pressure.
Turns on timing logging for multi-camera worker, recorder, and Basler backend diagnostics. Recording settings now include a `fast_encoding` flag, with `writegear_options` made more robust for missing/invalid FPS and optional low-latency FFmpeg options (`ultrafast` + `zerolatency`) for x264/x265. Recorder stats were expanded with buffer capacity awareness (`buffer_size`), derived backlog/fill-ratio properties, and richer formatted output showing queue fill and backlog.
Updates test fixtures and unit tests around recording flow changes: FakeVideoRecorder now mirrors new constructor/runtime fields, Basler fake includes one-by-one grab strategy, and GUI/controller tests validate recording-frame emission gating plus overlay recording via `_on_recording_frame_ready`. Tests also cover `RecordingSettings.writegear_options` (including fast x264 options and FPS fallback), RecordingManager writer option wiring, and richer recorder stats formatting/aggregation with backlog and queue capacity output.
@C-Achard C-Achard self-assigned this Jun 26, 2026
@C-Achard C-Achard added enhancement New feature or request camera Related to cameras and camera backends config Related to user configs, oading, saving, etc labels Jun 26, 2026
@C-Achard C-Achard added this to the Trigger config feature milestone Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

camera Related to cameras and camera backends config Related to user configs, oading, saving, etc enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant