io.BufferedReader.read(n) is documented to return "up to" n bytes, and
a subprocess pipe will return a short read whenever the producer closes
the pipe mid-frame — even on a blocking pipe. The existing assignment
frame_buffer[:] = ffmpeg_process.stdout.read(frame_size)
then raises ValueError on the slice assignment, and the surrounding
``except`` only breaks out of the capture loop when ``poll()`` reports
the process has already exited. If ffmpeg is still alive (e.g. an RTSP
source that dropped a chunk and recovered), the loop hits ``continue``
and the next read picks up data from the middle of the next frame,
putting capture out of sync with frame boundaries until the watchdog
later forces a restart.
Read into the pre-allocated buffer in a loop and treat any short read
as the end of the stream, so the watchdog can respawn ffmpeg from a
clean state rather than continuing at the wrong offset. As a side
effect, ``readinto`` writes directly into the shared-memory frame
buffer, avoiding the per-frame Python ``bytes`` allocation and copy
that the previous slice assignment performed.
* Smarter Regions
* Formatting
* Cleanup
* Fix motion region checking logic
* Add database table and migration for regions
* Update region grid on startup
* Revert init delay change
* Fix mypy
* Move object related functions to util
* Remove unused
* Fix tests
* Remove log
* Update the region daily at 2
* Fix logic
* Formatting
* Initialize grid before starting processing frames
* Move back to creating grid in main process
* Formatting
* Fixes
* Formating
* Fix region check
* Accept all but true
* Use regions grid for startup scan
* Add clarifying comment
* Fix new grid requests
* Add tests
* Delete stale region grids from DB
* refactor existing motion detector
* implement and use cnt bgsub
* pass fps to motion detector
* create a simplified motion detector
* lightning detection
* update default motion config
* lint imports
* use estimated boxes for regions
* use improved motion detector
* update test
* use a different strategy for clustering motion and object boxes
* increase alpha during calibration
* simplify object consolidation
* add some reasonable constraints to the estimated box
* adjust cluster boundary to 10%
* refactor
* add disabled debug code
* fix variable scope