Spaces:
Runtime error
Runtime error
Commit History
-
perf(stream): drift-free pacer + reader pacing for true 25 fps smoothness
Three fixes layered to eliminate the "smooth → freeze → burst" cycle caused by upstream HLS segment-burst delivery: 1. Drift-free pacer scheduler The pacer now anchors every tick at an absolute monotonic target (start + N*period) with a ~2 ms busy-wait tail. time.sleep() on macOS overshoots by ~3-5 ms because the kernel timer tick is coarse, which was silently drifting the pacer to ~22.7 fps even when work was only 4 ms. Effective pacer rate is now 25.0 fps measured. 2. Reader pacing at HLS_FPS stream_reader.cap.read() was draining ffmpeg's HLS demuxer as fast as it could decode, dumping a full ~50-frame segment into the ring in ~100 ms. The ring's drop-oldest semantics then threw away ~47 % of every burst, producing temporal discontinuities visible downstream as fast-forward bursts followed by frozen frames. Pacing cap.read() at HLS_FPS lets TCP / ffmpeg backpressure smooth the source delivery; the ring now stays at length 1-2 and source fra…abc7cb8 -
feat: real-time CCTV YOLO analytics with bbox-baked HLS
Per-camera worker decoupled into four stages: - capture (StreamReader): decodes upstream HLS, tags frames with capture timestamp, pushes to a bounded ring (drop-oldest) - pace: monotonic-clock thread ticks at HLS_FPS, pops the next frame from the ring, annotates with the detection that was current at that capture time (bbox stays glued to the visible frame even with ring delay) - encode: ffmpeg in true CFR (-r N -fps_mode cfr), libx264 or videotoolbox; segments split on exact second boundaries - inference: YOLO + ByteTrack on its own thread at TARGET_INFER_FPS; never blocks the capture / pace / encode chain Detection coords scaled from source space (e.g. 1920x1080) to output space (e.g. 1280x720) before annotation. Persistent state in a single cctv_session_metrics row per camera (UPSERT each tick, started_at frozen across reconnects). Realtime WS pushes analytics + geo-tagged detections with per-camera coverage polygon. Embed-ready: any client drops <video src=playlist.m3u…40e0b51