(Zmeventnotification add on is used for edgetpu stuff.)
Important things to note. Streams are recorded at 30fps,but motion detection runs at only 5fps as I found it better for slow moving objects. Also be prepared for the motion detection to run horribly until you tune it in, but although many more user friendly software packages exist I recommend zoneminder, because no other give so much control over motion detection parameters. I have one camera that looks at a 100m long field with multiple bushes and trees moving in the wind. It needs to be less sensitive for nearby stuff(bottom of the frame) and a lot more for far away. It has to exclude rain, snow, switches to IR etc. Only ZM allows me to tweak it properly and now that I did it runs with no false positives for days.
Basically I stream from RTSP cameras into GStreamer. I have GStreamer constantly convert to MPEG-TS(A wonderful format because the fixed size chunks make stream streaming easy) and output on a named pipe, plus output the keyframes to ramdisk files.
The TS stream I output via a web socket and use a JS player to decode that(See kaithem/data/modules/Beholder for the player code).
But I also output the video to files in the ramdisk continually and keep the last few segments. When record is triggered, I copy all the existing segments over(To catch things before record started), start copying any new ones and start creating an HLS playlist file. When you go to play a file in the web UI, I use an HLS player directly.
This allows playback while a session is still being recorded, and future metadata stuff in the file, and lets me use .ts for everything.
Keyframes go into a motion algorithm that uses PIL to perform an erosion operation and remove small bits of noise, taking into account real motion will be connected pixels. If motion is seen, tflite-runtime runs the Efficientdet model. This is probably the weakest part of the system, since I only look at keyframes and the model is not very accurate I occasionally miss things.
The results get postprocessed because sometimes the model sees things that aren't there. Definitely could use better modeling.
The motion estimator value is exposed as a tag point for other automation triggers in realtime.
I'm using Amcrest at the moment but they have some big ethical problems last I heard, so I'd probably go with TP Link Tapo if they still have RTSP next time.