Local realtime person detection for RTSP cameras

i have this cpu for my virtual frigate:

olaf@ub20-frigate:~$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Silver 4110 CPU @ 2.10GHz

and it seems to have no “Quicksync” capabilities but according to the docs the family is CPU < 10 but the Optimisation-Settings throws errors in my ffmepg. so i use the settings CPU > 10 without errors:

ffmpeg:
  hwaccel_args:
    - -hwaccel
    - qsv
    - -qsv_device
    - /dev/dri/renderD128

i use this settings on another frigate and CPU, which should have Quicksync and its CPU< 6 without error.

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz

But in both cases i am not sure if ffmpeg hardware-settings are used at all.
How to check?

Anyone using this with Ezviz C6N? Something strange happens, the cameras byu itself it changes the resolution, making the stream unreliable.

Any hint on to fix the resolution? IS more of a camera problerm, but can’t find solution

Just noticed lots of these in my logs, anything to worry about ?

21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'web_port' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'detectors' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'save_clips' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'mqtt' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'ffmpeg' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'cameras' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'objects' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'web_port' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'detectors' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)
21-08-22 04:28:02 WARNING (MainThread) [supervisor.addons.options] Option 'save_clips' does not exist in the schema for Frigate NVR (ccab4aaf_frigate)

For some reason Frigate is acting inconsistently. This morning I noticed that the CPU usage of my server dropped off, the usage fell right around 2am. I assumed that it was Frigate since I’ve been having weird CPU usage issues with it. I went in an restarted the docker container for it and CPU usage cranked up to 80% and sat there. The docker and system were pretty much left alone all day yesterday but you can see that the system regularly sits at a load of ~5, 40% CPU usage until this morning.

15min load:
image

CPU percentage:
image

On further inspection it seems to be a single ffmpeg that consumes an order of magnitude more processing power than all the others. I tried turning off the detection for that camera and it doesn’t change. I tried restarting the docker container a few times and that one camera rlc-520-1 always consumes 500-700% CPU (this is because of top’s multi-core/multi-threading reporting), this is why my overall CPU usage is going to 80% in the HA chart. Take a look at my top output:

top - 07:23:44 up 30 days, 23:48,  2 users,  load average: 15.86, 15.27, 13.20
Tasks: 473 total,   5 running, 468 sleeping,   0 stopped,   0 zombie
%Cpu0  : 17.5 us,  7.7 sy, 56.2 ni, 18.2 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu1  : 12.7 us,  7.9 sy, 62.3 ni, 16.8 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu2  : 14.4 us,  8.9 sy, 57.7 ni, 18.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  : 16.6 us, 10.8 sy, 51.7 ni, 20.6 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu4  : 14.8 us,  9.4 sy, 56.0 ni, 19.5 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu5  : 13.6 us,  6.8 sy, 61.7 ni, 18.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  : 15.8 us,  7.9 sy, 55.5 ni, 20.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  : 24.1 us, 10.2 sy, 38.8 ni, 13.3 id,  0.0 wa,  0.0 hi, 13.6 si,  0.0 st
%Cpu8  : 17.0 us, 13.6 sy, 51.7 ni, 17.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu9  : 19.7 us, 12.4 sy, 48.2 ni, 19.4 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu10 : 15.7 us,  8.0 sy, 55.9 ni, 20.1 id,  0.0 wa,  0.0 hi,  0.3 si,  0.0 st
%Cpu11 : 19.3 us, 10.7 sy, 49.7 ni, 19.3 id,  0.0 wa,  0.0 hi,  1.0 si,  0.0 st
MiB Mem : 128803.2 total,  10534.3 free,   7460.0 used, 110808.8 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used. 119924.9 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
2083338 root      20   0 5565688 250436 106636 R 615.2   0.2  10:46.56 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-520-1/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/front_door-%Y%m%d%H%M%S.m+
2083355 root      20   0 5563552 244164 107052 S  34.3   0.2   0:39.29 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-3/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/east_yard-%Y%m%d%H%M%S.mp+
2083216 root      20   0 2777808 135292  38632 S  29.7   0.1   0:19.36 python3 -u -m frigate
2083359 root      20   0 5462424 206092 106096 S  29.7   0.2   0:32.05 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-1/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/back_yard-%Y%m%d%H%M%S.mp+
2083366 root      20   0 5462032 204332 106024 S  28.7   0.2   0:32.93 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-2/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/out_the_back-%Y%m%d%H%M%S+
2083346 root      20   0 5563540 245608 106804 S  24.8   0.2   0:30.69 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-4/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/west_yard-%Y%m%d%H%M%S.mp+
2083368 root      20   0 5562608 246228 107264 S  24.1   0.2   0:29.00 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-511-1/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/garage-%Y%m%d%H%M%S.mp4 -+
2083377 root      20   0 5562340 243296 106668 S  22.4   0.2   0:26.32 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-e1-zoom-1/bcs/channel0_sub.bcs?channel=0&stream=1&user=uname_pword&password=uname_pword -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:a copy /tmp/cache/storage_room-%Y%m%d%H+
2083323 root      20   0 2171100  97352  13704 S  13.9   0.1   0:05.46 frigate.process:storage_room
2083339 root      20   0 5435936 167336 128660 S   9.9   0.1   0:13.07 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-3/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083354 root      20   0 5433648 162952 127216 S   9.9   0.1   0:12.16 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-2/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083333 root      20   0 5431348 162048 128892 S   9.6   0.1   0:11.83 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-4/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083328 root      20   0 5431396 161772 128616 R   9.2   0.1   0:11.92 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-520-1/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083345 root      20   0 5433552 164236 127312 S   9.2   0.1   0:12.12 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-410-1/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083358 root      20   0 5431396 160708 128112 R   9.2   0.1   0:11.91 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-511-1/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083360 root      20   0 1629708  96168   5072 S   8.9   0.1   0:10.69 python3 -u -m frigate
2083369 root      20   0 5435144 165648 128904 R   8.9   0.1   0:11.52 ffmpeg -hide_banner -loglevel warning -hwaccel cuda -c:v h264_cuvid -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts -fflags +discardcorrupt -use_wallclock_as_timestamps 1 -i rtmp://rlc-e1-zoom-1/bcs/channel0_main.bcs?channel=0&stream=0&user=uname_pword&password=uname_pword -r 8 -f rawvideo -pix_fmt yuv420p pipe:
2083324 root      20   0 1629708  96212   5136 S   8.6   0.1   0:10.64 python3 -u -m frigate
2083327 root      20   0 1629708  96028   4944 S   8.6   0.1   0:10.51 python3 -u -m frigate
2083331 root      20   0 1629708  96092   5016 S   8.6   0.1   0:10.75 python3 -u -m frigate
2083351 root      20   0 1629708  96208   5136 S   8.6   0.1   0:10.70 python3 -u -m frigate
2083335 root      20   0 1627136  95632   5008 S   8.3   0.1   0:10.23 python3 -u -m frigate
2083340 root      20   0 1627136  95788   5136 S   7.9   0.1   0:10.24 python3 -u -m frigate
   1355 root      20   0 3033148  48160  24460 S   5.9   0.0   3170:36 /usr/bin/containerd

I tried turning up the logging using:

logger:
  default: debug

but the output from the docker log doesn’t shed any light on this issue. As you can see I’m using the nvidia docker and I can see these processes in my nvidia-smi output. Any ideas?

P.S. That stream rlc-520-1 is of my front door which is completely static right now and probably has been for the last several hours. No shadows, no trees blowing in the wind, no people ringing the doorbell. So high CPU usage on that stream doesn’t add up.

UPDATE

My lovely wife wanted to try to help me solve the issue so I was explaining it to her and showing her some of the details. While doing that I noticed that I could watch the live stream for all cameras from the Frigate interface which meant that the camera’s streams were working. However, from Home Assistant all the cameras worked except for the Front Door (rlc-520-1). I think this means that Frigate’s re-broadcast stream for that camera was broken. I tried unplugging the PoE cord for it, didn’t help. I tried restating the docker container again didn’t help. I even recreated the container and that didn’t help either. :dizzy_face:

Defeated, I was interested in seeing how much wattage it was consuming so I pulled up the Sense monitor and stopped the docker to see it in the “off” state (clicking “stop” in portainer). ~100W of additional power was consumed by the CPU crunching that camera (house consumption went from ~1550W to ~1450W). I let it sit “off” for about a minute, then clicked “start” from portainer. Frigate came up and the problem was gone. Now I can see all camera’s streams from HA again and all ffmpeg threads are consuming between 20-30% CPU.

Every time I had previously tried to restart the docker container (probably 5-6 times this morning), I hit the portainer “restart” button. This time, I instead clicked the “stop” button and waited about a minute, then clicked the “start” button and now it’s back to normal (15min load of ~4-5). I wish I could understand why the container is so inconsistent. :face_with_raised_eyebrow:

Did you ever get hw acceleration working with your APU?

Yep, I got it working. Details are here.

1 Like

Hi everyone, just installed this addon, and am loving its’ features. I’m running this off Hass Supervised on a Pi and was wondering if it was possible to have the clips saved onto a network share instead of the Sdcard.

Thanks!

I have previously used RTMP role on my cameras into Home Assistant. I no longer use the role as i found the stream very laggy compared to a direct connection via the Camera Integration. However camera entities are still in Home Assistant but dont work and i get the following error in the HA log:

Logger: homeassistant.components.stream.worker
Source: components/stream/worker.py:323
Integration: Stream (documentation, issues)
First occurred: 21 August 2021, 21:19:13 (322 occurrences)
Last logged: 9:58:50

Error opening stream rtmp://192.168.1.10/live/dining_room
Error opening stream rtmp://192.168.1.10/live/bedroom

I have a Supervised installed on Debian 10 also installed frigate as add-on, currently everything seems working fine. In my system i have a 256gb ssd and a 2TB hdd, the default media folder is in 256gb ssd since i have HA installed in there, i mounted the 2TB hdd to /mnt/storage so how do i set Friget to record the clips into my 2TB hdd instead of the default location?

• list USB devices
‘$ lsusb

• get UUID of the USB disk
$ blkid

• check if the mount destination is empty folder, if not remove it
$ ls -la /usr/share/hassio/media/frigate
$ rm -rf /usr/share/hassio/media/frigate
$ mkdir /usr/share/hassio/media/frigate

• edit fstab with new USB disk
$ nano /etc/fstab
• Add new line at the end to mount the USB disk for Frigate
UUID=d3527b9e-c3ea-4ac7-8565-a252aec20f5e /usr/share/hassio/media/frigate ext4 defaults  0   2
• Save and close the file by pressing Ctrl+x and confirm by Y and Enter

• Manually start the mount
$ mount -a

• Verify mount
$ mount | grep frigate

I’m using


automation:
  - alias: Notify of events
    trigger:
      platform: mqtt
      topic: frigate/events
    action:
      - service: notify.telegram_full
        data_template:
          message: 'A {{trigger.payload_json["after"]["label"]}} was detected.'
          data:
            photo:
              # this url should work for addon users
              - url: 'http://ccab4aaf-frigate:5000/api/events/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg'
                caption: 'A {{trigger.payload_json["after"]["label"]}} was detected on {{ trigger.payload_json["after"]["camera"] }} camera'

But find while someone is being detected, I’m getting multiple notifications, is there a way to limit this to one notifications then wait a while before checking again.

Thank you.

I add a delay to end of automation to prevent retrigger with xx seconds

1 Like

@blakeblackshear how can I tell which is the latest version from https://registry.hub.docker.com/v1/repositories/blakeblackshear/frigate/tags

on this page, Release 0.9.0 by blakeblackshear · Pull Request #825 · blakeblackshear/frigate · GitHub
29de723 seems to be the latest and is found at the first link but the first link shows beta1 and beta2

How did you get on with the method provided by palito?

Hey! I’m looking into installing frigate. I like to install my software in containers, using LXD on Debian, similar concept to Proxmox. I’m a bit surprised how come we still need to use docker in an LXC container. I haven’t found any resources to install frigate on bare metal linux. Is it possible?

I have the following setup, and this is working. I only want to rotate the camera image 90 degrees, how do I do this?

cameras:
  camera_front:
    ffmpeg:
      inputs:
        - path: rtsp://xxxx:xxxxx@XXXX:554/Streaming/Channels/102?transportmode=unicast&profile=Profile_1
          roles:
            - detect
            - rtmp
        - path: rtsp://xxxx:xxxxx@XXXX:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1
          roles:
            - clips
    width: 640
    height: 480
    fps: 5
    objects:
      track:
        - person
        - car
        - bycicle
        - dog
        - cat

Recent issue with an example. See the output_args for detect: ESP32Cam encoding for Mobile Playback gone wrong · Issue #1604 · blakeblackshear/frigate · GitHub

0.9.0 Release Candidate 1 is now available in the Beta addon. Note that the v2.0.0 pre-release version of the integration must also be used. Release 0.9.0 Release Candidate 1 · blakeblackshear/frigate · GitHub

Questions/Discussion will be more actively monitored here: 0.9.0 Release · Discussion #1502 · blakeblackshear/frigate · GitHub

3 Likes

Hey @rpress how is frigate setup without docker going? Can you share some tips how you managed the installation? I get lost in the docker files…

Finally got eveything works, just wondering is it possible to activate or deactivate the detection base on schedule? For example i only want the detection to work during 12am to morning 7am.