Files
Heimdall/skills/video-recording/SKILL.md
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

8.3 KiB
Raw Blame History

name, description
name description
video-recording Implement and validate Heimdall Agent video segments, central recording storage, access checks, ranges, and retention.

Heimdall video recording

Recording is opt-in per camera (RecordingEnabled, default false). Agent capture is a separate FFmpeg process and only runs while the assigned camera's RTSP stream is already active. Keep RTSP values out of logs, command strings printed to logs, and failure responses.

  • Bound segment duration, size, and Agent spool usage through validated AgentOptions; preserve incomplete uploads for retry and make completed segment identifiers stable across retries.
  • Keep continuous recording (RecordingEnabled) and event-triggered recording (EventRecordingEnabled) as separate per-camera opt-ins. Event mode watches the same active Agent stream, durably records detection trigger windows under the Agent state directory with owner-only permissions, starts FFmpeg on the event, and stops 30 seconds after the latest event by default (Agent:RecordingEventPostRollSeconds, validated from 5 to 300 seconds). It does not record pre-roll. Disabling event mode, disabling/removing the camera assignment, or stopping its stream clears pending trigger windows and stops the process.
  • Map the primary video stream and optional first audio stream into MP4 segments. Copy compatible video without re-encoding and encode optional audio as AAC at a bounded 128 kbit/s so common RTSP audio codecs are playable in browsers; feeds without audio must still record successfully. Keep privacy/operator consent in the per-camera recording opt-in.
  • Upload only MP4 content from the Agent API-key boundary. Validate camera assignment at the API and application boundaries. Persist metadata through IApplicationDbContext and use IRecordingStorage as the Application port.
  • Capture storage destination at upload time. Downloads must check camera access before opening the stored object. Implement byte ranges in the storage adapter rather than downloading whole objects for partial playback.
  • Central quota is configured with RECORDING_STORAGE_QUOTA_MAX_BYTES in Compose (application key Recordings:StorageQuota:MaxBytes, default 1 TiB). Options are validated on startup; a segment that would exceed the aggregate persisted recording bytes receives HTTP 507 and its uploaded object is removed. The PostgreSQL advisory transaction lock makes the aggregate check atomic across simultaneous Agent uploads; upload bytes finish before acquiring the short metadata lock. Give each upload attempt a unique object key below its recording ID so a racing idempotent retry cannot overwrite the winning segment; remove the losing attempt's object even when both use the same camera.
  • The CameraDetail recording list/player uses the authorized API client for metadata and same-origin /api/recordings/{id}/content URLs for browser Range requests. Keep the export link on that authorized endpoint and never render an arbitrary storage URL.
  • Preserve the existing recording retention policy and storage-final orphan sweep. Ensure recording rows are removed only after object deletion succeeds; do not guess destinations for legacy rows without provenance.
  • Add PostgreSQL tests for migration, metadata/idempotency, quota concurrency/cleanup, camera access, range translation, and retention semantics when touching those paths. Agent tests should cover bounded argument construction, defaults, and spool/config behavior.
  • AgentRecordingServiceTests.UploadFailureKeepsSegmentAndRetryUsesSameRecordingIdentity seeds a manifest and MP4 into a temporary spool, returns 503 then 204 from a mock Central, and proves the segment remains through failure, reuses the same idempotency URL/API-key boundary, and is deleted only after success.
  • For acceptance, install an EXIT cleanup trap before build/start, then build Central and Agent from this changed source with unique image tags in a disposable Compose project. Publish a synthetic RTSP stream containing H.264 video and AAC-compatible audio through MediaMTX; register and assign the Agent, enable recording, and prove a segment reaches Central through the live Agent RTSP loop. Verify ffprobe sees video and audio in a downloaded segment, scoped listing/range download, and unauthorized denial. Remove only that Compose project, confirm its containers/volumes/network are gone, and remove/verify every recipe-built local image tag.
  • For quota acceptance, set RECORDING_STORAGE_QUOTA_MAX_BYTES to a small positive value such as 32, build Central from source, and probe /healthz plus /api/auth/bootstrap-status to prove startup validation. Run the PostgreSQL API test with concurrent uploads to prove the 507 boundary, idempotent retry, unique keys, and cleanup of over-quota/duplicate objects. Tear down the named Compose project and verify zero containers, volumes, and networks.
  • Run RecordingEventAssociationTests against PostgreSQL: upload a segment and verify that only same-camera events in the half-open interval [timestamp, timestamp + duration) receive its recording ID; events at either outside boundary remain unlinked. This confirms relational translation and event/recording association without claiming event-triggered capture.
  • Event recording is an independent opt-in from continuous recording. Central sends event_recording_enabled in the per-Agent camera configuration; the Agent persists one atomic marker per camera before attempting the HTTP event outbox write, so outbox capacity or delivery cannot suppress capture. Each qualifying event refreshes the configured post-roll (5–300 seconds, default 30). Motion, person, vehicle, unknown-person, face, and plate events can refresh that window. The Agent starts FFmpeg only while the camera stream is active and the marker remains live. Clear markers when event recording is disabled, the camera is disabled, or assignment is removed. The marker is bounded to one file per camera and survives Agent restart.
  • For event-triggered acceptance, enable only EventRecordingEnabled through CameraDetail/API, use an assigned Agent and active synthetic RTSP stream, and prove the Agent starts capture and uploads a segment. Verify event association for both event-first and recording-first arrival. Restart the Agent during an active window and prove capture resumes from the marker; disable the toggle and prove uploads stop after configuration settles. Keep real-camera codec and timing validation separate.
  • For each recording recipe, record project-unique tags for locally built Central, Agent, or helper images and remove/verify those exact tags after Compose teardown in the same EXIT trap, including on build/assertion failure. Retain shared PostgreSQL/MediaMTX base images, preserve test exit status, report cleanup failures, and never use --rmi all or image prune. Follow skills/compose-disposable-recipe/SKILL.md.
  • Do not reuse an app/helper tag built by a different acceptance recipe. Build this recipe's changed source under fresh project-unique tags; record local image tags: none only for genuinely upstream-only test containers. Every run note must list the exact local tags as absent, or explicitly state no local images were built.

On 5 November 2026, disposable Compose project hmd-event-e2e-1793899172-25617 built Central and Agent from this source with locked .NET 10 restore. The actual Agent registered from the generated site token, consumed an animated H.264/AAC RTSP stream, emitted MotionDetected, uploaded an event-only segment while continuous recording remained off, and Central associated the event with that recording. Restarting the Agent while the post-roll marker was active produced another segment; disabling event recording through the API left the recording count stable after configuration settled. PostgreSQL event-first and recording-first association tests both pass. The focused RecordingTriggerStoreTests passed 3/3 in SDK Compose project hmd-trigger-unit-1793899683-6893. Cleanup traps removed exact local tags heimdall:hmd-event-e2e-1793899172-25617-central and heimdall-agent:hmd-event-e2e-1793899172-25617-agent, verified both absent, and confirmed zero project containers, volumes, and networks; the unit-test recipe built no local images and also left zero project resources. Synthetic motion thresholds were lowered for deterministic event generation. Real-camera codecs/timing remain unvalidated.