Local realtime person detection for RTSP cameras

I only know about this API reference. Would be great if can find examples on how to utilize all the infos generated from the frigate events.

So far i’m using it to send telegram notifications and to turn on zone lights when alarm is triggered

Asking the pros here. :slightly_smiling_face:
I’m using HA to send notifications to the family when there is detection with a link to the recorded clip.
But sometimes you want the notifications to stop for say a 5min period. How would you accomplish the automation?

Edit: Using the PUSHOVER service to get my notifications.

Would you mind sharing your code for this .I want to use my own notify XMPP component not the compagnon

i send my telegrambot a command: /stop 5 (5 = 5 mins or any number to indicate the number of minutes to stop notifications)

telegrambot receives command and turn off notification automation and start the timer helper.

upon timer helper finished event, turn notification automation back on.

1 Like

Thanks for the tips… But im not using Telegram… Using Pushover for receiving push notifications.
Should have made a note in my question :slight_smile:

Here it is… Btw, using Pushover service to send notifications from HA. This is because there is a limit of 300 push every day.

service: notify.pushover
data:
  message: >-
    {{trigger.payload_json["after"]["label"]}} detekterat i kamera
    {{trigger.payload_json["after"]["camera"]}}.
  data:
    target: Note10
    url_title: Play Video
    url: >-
      https://XXX.ui.nabu.casa/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/{{trigger.payload_json["after"]["camera"]}}/clip.mp4
    attachment: >-
      /config/www/img/frigate/{{trigger.payload_json["after"]["camera"]}}_latest.jpg


Could anybody help to understand what’s the issue?
I am trying to use blakeblackshear/frigate:stable-amd64nvidia with Nvidia GPU and H265 (also tried with H264) camera stream.

Here’s what I get:

root@max-HP-Z240-SFF-Workstation:/home/max# docker run --rm --name=frigate --gpus all --runtime=nvidia -v /dev/bus                         /usb:/dev/bus/usb -v /var/frigate:/config:ro -p 5000:5000 -e RTSP_PASSWORD='037-46KE' -e NVIDIA_VISIBLE_DEVICES=al                         l -e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility blakeblackshear/frigate:stable-amd64nvidia
 * Starting nginx nginx
   ...done.
frigate.app                    INFO    : Creating directory: /media/frigate/recordings
frigate.app                    INFO    : Creating directory: /media/frigate/clips
frigate.app                    INFO    : Creating directory: /tmp/cache
frigate.app                    WARNING : Camera axis has rtmp enabled, but rtmp is not assigned to an input.
Starting migrations
peewee_migrate                 INFO    : Starting migrations
Migrate "001_create_events_table"
peewee_migrate                 INFO    : Migrate "001_create_events_table"
sql ('CREATE TABLE IF NOT EXISTS "event" ("id" VARCHAR(30) NOT NULL PRIMARY KEY, "label" VARCHAR(20) NOT NULL, "ca                         mera" VARCHAR(20) NOT NULL, "start_time" DATETIME NOT NULL, "end_time" DATETIME NOT NULL, "top_score" REAL NOT NUL                         L, "false_positive" INTEGER NOT NULL, "zones" JSON NOT NULL, "thumbnail" TEXT NOT NULL)',)
peewee_migrate                 INFO    : sql ('CREATE TABLE IF NOT EXISTS "event" ("id" VARCHAR(30) NOT NULL PRIMA                         RY KEY, "label" VARCHAR(20) NOT NULL, "camera" VARCHAR(20) NOT NULL, "start_time" DATETIME NOT NULL, "end_time" DA                         TETIME NOT NULL, "top_score" REAL NOT NULL, "false_positive" INTEGER NOT NULL, "zones" JSON NOT NULL, "thumbnail"                          TEXT NOT NULL)',)
sql ('CREATE INDEX IF NOT EXISTS "event_label" ON "event" ("label")',)
peewee_migrate                 INFO    : sql ('CREATE INDEX IF NOT EXISTS "event_label" ON "event" ("label")',)
sql ('CREATE INDEX IF NOT EXISTS "event_camera" ON "event" ("camera")',)
peewee_migrate                 INFO    : sql ('CREATE INDEX IF NOT EXISTS "event_camera" ON "event" ("camera")',)
Done 001_create_events_table
peewee_migrate                 INFO    : Done 001_create_events_table
Migrate "002_add_clip_snapshot"
peewee_migrate                 INFO    : Migrate "002_add_clip_snapshot"
add_column ('event', 'has_clip', <BooleanField: Event.has_clip>)
peewee_migrate                 INFO    : add_column ('event', 'has_clip', <BooleanField: Event.has_clip>)
add_column ('event', 'has_snapshot', <BooleanField: Event.has_snapshot>)
peewee_migrate                 INFO    : add_column ('event', 'has_snapshot', <BooleanField: Event.has_snapshot>)
Done 002_add_clip_snapshot
peewee_migrate                 INFO    : Done 002_add_clip_snapshot
frigate.mqtt                   INFO    : MQTT connected
detector.coral                 INFO    : Starting detection process: 44
frigate.app                    INFO    : Camera processor started for axis: 47
frigate.edgetpu                INFO    : Attempting to load TPU as usb
Process detector:coral:
frigate.edgetpu                INFO    : No EdgeTPU detected.
frigate.app                    INFO    : Capture process started for axis: 50
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tflite_runtime/interpreter.py", line 152, in load_delegate
    delegate = Delegate(library, options)
  File "/usr/local/lib/python3.8/dist-packages/tflite_runtime/interpreter.py", line 111, in __init__
    raise ValueError(capture.message)
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/frigate/frigate/edgetpu.py", line 124, in run_detector
    object_detector = LocalObjectDetector(tf_device=tf_device, num_threads=num_threads)
  File "/opt/frigate/frigate/edgetpu.py", line 63, in __init__
    edge_tpu_delegate = load_delegate('libedgetpu.so.1.0', device_config)
  File "/usr/local/lib/python3.8/dist-packages/tflite_runtime/interpreter.py", line 154, in load_delegate
    raise ValueError('Failed to load delegate from {}\n{}'.format(
ValueError: Failed to load delegate from libedgetpu.so.1.0

frigate.watchdog               INFO    : Detection appears to have stopped. Exiting frigate...
frigate.app                    INFO    : Stopping...
frigate.events                 INFO    : Exiting event cleanup...
frigate.events                 INFO    : Exiting event processor...
frigate.record                 INFO    : Exiting recording maintenance...
frigate.object_processing      INFO    : Exiting object processor...
frigate.watchdog               INFO    : Exiting watchdog...

My config.yml is:

mqtt:
  host: 192.168.0.3
  user: Max
  password: pass
cameras:
  axis:
    ffmpeg:
      input_args:
        - -c:v
        - hevc_cuvid
      inputs:
        - path: rtsp://root:[email protected]:554/axis-media/media.amp?streamprofile=frigate
          roles:
            - detect
    width: 1280
    height: 720
    fps: 10
objects:
  track:
    - person
    - car
    - truck

If I omit using - -c:v I get:


frigate.mqtt                   INFO    : MQTT connected
frigate.video                  INFO    : axis: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate.video                  INFO    : axis: ffmpeg process is not running. exiting capture thread...
ffmpeg.axis.detect             ERROR   : [NULL @ 0x561dae6deb80] Unable to find a suitable output format for 'hevc_cuvid'
ffmpeg.axis.detect             ERROR   : hevc_cuvid: Invalid argument
frigate.video                  INFO    : axis: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate.video                  INFO    : axis: ffmpeg process is not running. exiting capture thread...
ffmpeg.axis.detect             ERROR   : [NULL @ 0x558f285c7b80] Unable to find a suitable output format for 'hevc_cuvid'
frigate.watchdog               INFO    : Detection appears to have stopped. Exiting frigate...
ffmpeg.axis.detect             ERROR   : hevc_cuvid: Invalid argument
frigate.app                    INFO    : Stopping...
frigate.events                 INFO    : Exiting event cleanup...
frigate.events                 INFO    : Exiting event processor...
frigate.record                 INFO    : Exiting recording maintenance...
frigate.video                  INFO    : axis: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate.video                  INFO    : axis: ffmpeg process is not running. exiting capture thread...
frigate.object_processing      INFO    : Exiting object processor...
frigate.watchdog               INFO    : Exiting watchdog...
ffmpeg.axis.detect             ERROR   : [NULL @ 0x560bd81870c0] Unable to find a suitable output format for 'hevc_cuvid'
ffmpeg.axis.detect             ERROR   : hevc_cuvid: Invalid argument
frigate.video                  INFO    : axis: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate.video                  INFO    : axis: ffmpeg process is not running. exiting capture thread...
ffmpeg.axis.detect             ERROR   : [NULL @ 0x562bda0efb80] Unable to find a suitable output format for 'hevc_cuvid'
ffmpeg.axis.detect             ERROR   : hevc_cuvid: Invalid argument

While my ffmpeg -decoders | grep cuvid returns:


ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
 V..... h264_cuvid           Nvidia CUVID H264 decoder (codec h264)
 V..... hevc_cuvid           Nvidia CUVID HEVC decoder (codec hevc)
 V..... mjpeg_cuvid          Nvidia CUVID MJPEG decoder (codec mjpeg)
 V..... mpeg1_cuvid          Nvidia CUVID MPEG1VIDEO decoder (codec mpeg1video)
 V..... mpeg2_cuvid          Nvidia CUVID MPEG2VIDEO decoder (codec mpeg2video)
 V..... mpeg4_cuvid          Nvidia CUVID MPEG4 decoder (codec mpeg4)
 V..... vc1_cuvid            Nvidia CUVID VC1 decoder (codec vc1)
 V..... vp8_cuvid            Nvidia CUVID VP8 decoder (codec vp8)
 V..... vp9_cuvid            Nvidia CUVID VP9 decoder (codec vp9)

Hi, this is now a very long thread, so pardon if question has been already made.
Which hardware should I buy to connect to a NUC in order to detect person in a room (ideally I need this for 3 cameras in 3 rooms)?

can you share your code for this? currently, i’m using just a static button that has the option to mute for X minutes, but it’d be cool to make it configurable!

I don’t think your question has to do with the topic of this thread but here goes: Create a timer and add a condition to your automation to not send a notification when the timer is still running — unless you want more logic to apply this constraints on an individual basis. Start the timer in the same automation after sending the notification.

Did anybody manage to run Frigate with Nvidia GPU acceleration?

1 Like

i would recomend intel i7 any NUC with price 450usd+
if used as VM,then GPU passthrough is neccesary

just integrated GPU passthrough, through proxmox. Works perfectly

I got my GPU available from within ‘frigate container’, no need to passthrough. Is there possibility to utilize Nvidia GPU for object detection / video decoding in Frigate?
How to realize?

Trying to get starting with Frigate under HassOS (VM)… frigate.yml as follows:

mqtt:
  host: 192.168.20.4
  user: xxxx
  password: xxxxx
cameras:
  nw_eaves:
    ffmpeg:
      inputs:
        - path: rtsp://192.168.20.2:7447/xxxxxxxxx_x
          roles:
            - detect
            - rtmp
    width: 1920
    height: 1080
    fps: 15

However, on startup I get this in the logs:

* Starting nginx nginx
   ...done.
frigate.app                    INFO    : Creating directory: /tmp/cache
Starting migrations
peewee_migrate                 INFO    : Starting migrations
There is nothing to migrate
peewee_migrate                 INFO    : There is nothing to migrate
detector.coral                 INFO    : Starting detection process: 30
frigate.app                    INFO    : Camera processor started for back: 32
frigate.edgetpu                INFO    : Attempting to load TPU as usb
frigate.app                    INFO    : Capture process started for back: 34
frigate.edgetpu                INFO    : No EdgeTPU detected.
Process detector:coral:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tflite_runtime/interpreter.py", line 152, in load_delegate
    delegate = Delegate(library, options)
  File "/usr/local/lib/python3.8/dist-packages/tflite_runtime/interpreter.py", line 111, in __init__
    raise ValueError(capture.message)
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/frigate/frigate/edgetpu.py", line 124, in run_detector
    object_detector = LocalObjectDetector(tf_device=tf_device, num_threads=num_threads)
  File "/opt/frigate/frigate/edgetpu.py", line 63, in __init__
    edge_tpu_delegate = load_delegate('libedgetpu.so.1.0', device_config)
  File "/usr/local/lib/python3.8/dist-packages/tflite_runtime/interpreter.py", line 154, in load_delegate
    raise ValueError('Failed to load delegate from {}\n{}'.format(
ValueError: Failed to load delegate from libedgetpu.so.1.0
frigate.mqtt                   INFO    : MQTT connected
frigate.watchdog               INFO    : Detection appears to have stopped. Exiting frigate...
frigate.app                    INFO    : Stopping...
frigate.object_processing      INFO    : Exiting object processor...
frigate.events                 INFO    : Exiting event processor...
frigate.record                 INFO    : Exiting recording maintenance...
frigate.events                 INFO    : Exiting event cleanup...
frigate.watchdog               INFO    : Exiting watchdog...
frigate.stats                  INFO    : Exiting watchdog...
peewee.sqliteq                 INFO    : writer received shutdown request, exiting.
root                           INFO    : Waiting for detection process to exit gracefully...
/usr/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 109 leaked shared_memory objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

I’m running HassOS in a Virtualbox VM under Ubuntu Mate 20.04.2 on a repurposed desktop (i5-7500, 16GB RAM). Any thoughts?

you must define detector as mentioned in docs:

1 Like

I cant figure out what process fps means, can someone explain? Usually 0 is displayed for my cameras, but sometimes a specific camera shows fps.

I figured it out, so I answer my own question. It will show process fps when detection is enabled.

Perfect… sorted!

Added the hwaccel_args options for my CPU:

cameras:
  back:
    ffmpeg:
      hwaccel_args:
        - -hwaccel
        - vaapi
        - -hwaccel_device
        - /dev/dri/renderD128
        - -hwaccel_output_format
        - yuv420p
      inputs:
        - path: rtsp://192.168.20.2:7447/xxxx_x
          roles:
            - detect
            - rtmp
    width: 1920
    height: 1080
    fps: 15

…and broke it again:

frigate.video                  INFO    : back: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate.video                  INFO    : back: ffmpeg process is not running. exiting capture thread...
ffmpeg.back.detect             ERROR   : [AVHWDeviceContext @ 0x55ab0c2f5d80] No VA display found for device /dev/dri/renderD128.
ffmpeg.back.detect             ERROR   : Device creation failed: -22.
ffmpeg.back.detect             ERROR   : [h264 @ 0x55ab0c12cf80] No device available for decoder: device type vaapi needed for codec h264.
ffmpeg.back.detect             ERROR   : Device setup failed for decoder on input stream #0:1 : Invalid argument
frigate.video                  INFO    : back: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have different structures
frigate.video                  INFO    : back: ffmpeg sent a broken frame. memoryview assignment: lvalue and rvalue have 

Sorry for the neediness!