Local realtime person detection for RTSP cameras

@surge919

No, this is passing already connected and detected USB device to container.

Create a separate “.sh” file. E.g. startup.sh. Add below lines into it as per your USB Devices. And then schedule newly created script to execute at every startup. This shall load the USB drivers for different USB devices.

# Below 2 lines shall load USB serial derivers to kernal. This shall help to load the correct drivers if non block devices (harddisk) are connected on USB. Ex. Z wave stick.
#sudo insmod /lib/modules/usbserial.ko
#sudo insmod /lib/modules/ftdi_sio.ko


# below lines shall be added on DSM 7 to load conbee II and Opto Meter probes
/sbin/modprobe usbserial
/sbin/modprobe ftdi_sio
/sbin/modprobe cdc-acm

Hope this helps.

I have been running Frigate on a docker container for a while now with success. I recently decided to install HAOS on my bare metal and run the add-on. I can’t seem to get HA to see the USB accelerator. I see some people were having this problem before, anybody know what the issue is? Do you need to manually install the packages for the accelerator to work?

detectors:
  coral:
    type: edgetpu
    device: usb:0

ffmpeg:
  hwaccel_args:
    - -c:v
    - h264_cuvid

mqtt:
 ...

cameras:
  gate:
    ffmpeg:
      inputs:
        - path: rtsp://XXX:[email protected]:554/Streaming/Channels/1/
          roles:
            - detect
    detect:
      width: 3840
      height: 2160
      fps: 12

I’ve been seeing frequent (every few second) crashes from cameras that have been working flawlessly for ages now, something like this:


[2022-01-10 14:43:34] frigate.app INFO : Starting Frigate (0.9.4-26ae608)
Starting migrations
[2022-01-10 14:43:34] peewee_migrate INFO : Starting migrations
There is nothing to migrate
[2022-01-10 14:43:34] peewee_migrate INFO : There is nothing to migrate
[2022-01-10 14:43:34] frigate.mqtt INFO : MQTT connected
[2022-01-10 14:43:34] detector.coral INFO : Starting detection process: 225
[2022-01-10 14:43:34] frigate.app INFO : Starting Frigate (0.9.4-26ae608)
Starting migrations
[2022-01-10 14:43:34] peewee_migrate INFO : Starting migrations
There is nothing to migrate
[2022-01-10 14:43:34] peewee_migrate INFO : There is nothing to migrate
[2022-01-10 14:43:34] frigate.mqtt INFO : MQTT connected
[2022-01-10 14:43:34] detector.coral INFO : Starting detection process: 225
[2022-01-10 14:43:34] frigate.app INFO : Output process started: 226
[2022-01-10 14:43:34] ws4py INFO : Using epoll
[2022-01-10 14:43:34] frigate.app INFO : Camera processor started for gate: 232
[2022-01-10 14:43:34] frigate.edgetpu INFO : Attempting to load TPU as usb:0
[2022-01-10 14:43:34] frigate.app INFO : Output process started: 226
[2022-01-10 14:43:34] ws4py INFO : Using epoll
[2022-01-10 14:43:34] frigate.app INFO : Camera processor started for gate: 232
[2022-01-10 14:43:34] frigate.edgetpu INFO : Attempting to load TPU as usb:0
[2022-01-10 14:43:34] frigate.app INFO : Capture process started for gate: 242
[2022-01-10 14:43:36] frigate.edgetpu INFO : TPU found
[2022-01-10 14:43:34] ws4py INFO : Using epoll
[2022-01-10 14:43:37] frigate.video INFO : gate: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
[2022-01-10 14:43:37] frigate.video INFO : gate: ffmpeg process is not running. exiting capture thread...
[2022-01-10 14:43:38] ws4py INFO : Managing websocket [Local => 127.0.0.1:8082 | Remote => 127.0.0.1:59200]
[2022-01-10 14:43:38] ws4py INFO : Managing websocket [Local => 127.0.0.1:8082 | Remote => 127.0.0.1:59200]
[2022-01-10 14:43:54] watchdog.gate ERROR : FFMPEG process crashed unexpectedly for gate.

[2022-01-10 14:43:54] watchdog.gate ERROR : The following ffmpeg logs include the last 100 lines prior to exit.

[2022-01-10 14:43:54] watchdog.gate ERROR : You may have invalid args defined for this camera.

[2022-01-10 14:43:54] ffmpeg.gate.detect ERROR : [rtsp @ 0x561c0a423980] DTS discontinuity in stream 1: packet 6 with DTS 147764323295526, packet 7 with DTS 147764323314068

[2022-01-10 14:43:54] ffmpeg.gate.detect ERROR : av_interleaved_write_frame(): Connection reset by peer

[2022-01-10 14:43:54] ffmpeg.gate.detect ERROR : [flv @ 0x561c0a42b700] Failed to update header with correct duration.

[2022-01-10 14:43:54] ffmpeg.gate.detect ERROR : [flv @ 0x561c0a42b700] Failed to update header with correct filesize.

[2022-01-10 14:43:54] ffmpeg.gate.detect ERROR : Error writing trailer of rtmp://127.0.0.1/live/gate: Connection reset by peer

[2022-01-10 14:43:54] ws4py INFO : Terminating websocket [Local => 127.0.0.1:8082 | Remote => 127.0.0.1:59200]
[2022-01-10 14:43:55] ws4py INFO : Managing websocket [Local => 127.0.0.1:5002 | Remote => 127.0.0.1:58152]
[2022-01-10 14:43:55] ws4py INFO : Managing websocket [Local => 127.0.0.1:8082 | Remote => 127.0.0.1:59236]
[2022-01-10 14:43:57] frigate.video INFO : gate: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
[2022-01-10 14:43:57] frigate.video INFO : gate: ffmpeg process is not running. exiting capture thread...
[2022-01-10 14:43:57] frigate.video INFO : gate: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
[2022-01-10 14:43:57] frigate.video INFO : gate: ffmpeg process is not running. exiting capture thread...
[2022-01-10 14:43:57] ws4py INFO : Terminating websocket [Local => 127.0.0.1:8082 | Remote => 127.0.0.1:59236]
[2022-01-10 14:44:04] watchdog.gate ERROR : FFMPEG process crashed unexpectedly for gate.

[2022-01-10 14:44:04] watchdog.gate ERROR : The following ffmpeg logs include the last 100 lines prior to exit.

[2022-01-10 14:44:04] watchdog.gate ERROR : You may have invalid args defined for this camera.

[2022-01-10 14:44:04] ffmpeg.gate.detect ERROR : av_interleaved_write_frame(): Connection reset by peer

[2022-01-10 14:44:04] ffmpeg.gate.detect ERROR : [flv @ 0x559386bbd700] Failed to update header with correct duration.

[2022-01-10 14:44:04] ffmpeg.gate.detect ERROR : [flv @ 0x559386bbd700] Failed to update header with correct filesize.

[2022-01-10 14:44:04] ffmpeg.gate.detect ERROR : Error writing trailer of rtmp://127.0.0.1/live/gate: Connection reset by peer

[2022-01-10 14:44:07] frigate.video INFO : gate: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
[2022-01-10 14:44:07] frigate.video INFO : gate: ffmpeg process is not running. exiting capture thread...
[2022-01-10 14:44:14] watchdog.gate ERROR : FFMPEG process crashed unexpectedly for gate.

[2022-01-10 14:44:14] watchdog.gate ERROR : The following ffmpeg logs include the last 100 lines prior to exit.

[2022-01-10 14:44:14] watchdog.gate ERROR : You may have invalid args defined for this camera.

[2022-01-10 14:44:14] ffmpeg.gate.detect ERROR : av_interleaved_write_frame(): Connection reset by peer

[2022-01-10 14:44:14] ffmpeg.gate.detect ERROR : [flv @ 0x55c082f33700] Failed to update header with correct duration.

[2022-01-10 14:44:14] ffmpeg.gate.detect ERROR : [flv @ 0x55c082f33700] Failed to update header with correct filesize.

[2022-01-10 14:44:14] ffmpeg.gate.detect ERROR : Error writing trailer of rtmp://127.0.0.1/live/gate: Connection reset by peer

[2022-01-10 14:44:16] frigate.video INFO : gate: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
[2022-01-10 14:44:16] frigate.video INFO : gate: ffmpeg process is not running. exiting capture thread...

I’ve stripped the config back to barebones (as above, with just one camera), but I’m still seeing frequent crashes. The camera feed config is correct (resolution and FPS), so unsure what’s wrong.

If you just updated to 0.9.4, then this is probably because rtmp is being enabled by default. High resolutions like this often cause rtmp to fail.

That’s a very high resolution and frame rate. Unless you are tracking very small fast objects, you will be better off with a lower resolution and frame rate.

Hi,

I started to experience issues with the camera stream, I added the same camera with 2 different streams to test different resolutions; but both of them are failing,
Any ideas/suggestions?

frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : [h264 @ 0x55a8bad040] decode_slice_header error
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : [h264 @ 0x55a8bad040] no frame!
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : [h264 @ 0x55a8bad040] non-existing PPS 0 referenced
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   :     Last message repeated 1 times
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : [h264 @ 0x55a8bad040] decode_slice_header error
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : [h264 @ 0x55a8bad040] no frame!
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : Guessed Channel Layout for Input Stream #0.1 : mono
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : Could not write header for output file #0 (incorrect codec parameters ?): No space left on device
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera1.record          ERROR   : 
frigate_camera_tpu | [2022-01-12 08:22:00] watchdog.camera1               INFO    : Terminating the existing ffmpeg process...
frigate_camera_tpu | [2022-01-12 08:22:00] watchdog.camera1               INFO    : Waiting for ffmpeg to exit gracefully...
frigate_camera_tpu | [2022-01-12 08:22:01] frigate.video                  INFO    : camera2: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate_camera_tpu | [2022-01-12 08:22:01] frigate.video                  INFO    : camera2: ffmpeg process is not running. exiting capture thread...
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera2.detect          ERROR   : [h264 @ 0x555f7ef180] decode_slice_header error
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera2.detect          ERROR   : [h264 @ 0x555f7ef180] no frame!
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera2.detect          ERROR   : Guessed Channel Layout for Input Stream #0.1 : mono
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera2.detect          ERROR   : Could not write header for output file #0 (incorrect codec parameters ?): No space left on device
frigate_camera_tpu | [2022-01-12 08:22:00] ffmpeg.camera2.detect          ERROR   : 

regards

Good people of this thread, who didn’t vote on this Feature Request, please vote on regards of the mount of NAS to HA.
If we will have big vote numbers, we will be seen. Thank you for your time.

@Morphy What NUC are you using?

Also, in general, is there a good way to identify what mini PCs would have a free M.2 pcie slot that would work with Coral. I’ve been searching for days and am struggling to find a solution.

Thanks!

what’s the camera configs

the usb has to be mounted as a volume, I used a modded compose of this build and it works sweet, hoping this will be added to official builds

Hello,

i have problem frigate when i install and i connect the camera it work fine but when i add two camera it show green sold for both ?
like this:

first camera is:
https://www.amazon.com/gp/product/B094Y2F4GT/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1

secound camera is:

can you help me ?

thank you

Will need to see your config. Normaly an issue with resolution H and W

Open the feeds in VLC player to check stream specs.

Anyone running on Synology use hardware acceleration? What is the benefit?

Ds220+ With j4025 intel. Running in docker

I’m using coral usb and seems to be running well.

Is hardware acceleration possible or a benefit?

Hello,
i check stream specs fist camera is 1280x960
secound camera is 1920x1080
i change them but still green sold ?

Are they both H264 streams

one yes and the another one no see:
camera1
camera2

Is it the bottom feed that causes the issue?

Try w 1920 h 1088

** ahh it’s MJPEG feed. That’s the issue I think, need to search for args to make it compatible?

what yo mean by args to make it compatible ?

I try w 1920 h 1088 but not working

1 Like

thank you
it work with me now
for first camera i add this

input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1

done

for secound camera i add
for MJPEG feed camera i add this

      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1
      output_args:
        record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
        rtmp: -c:v libx264 -an -f flv

and in role i add -rtmp

work for me

thank you very much