Local realtime person detection for RTSP cameras

Okay, so I just ran it with the command line so it definitely had the shm-size parameter, but it still only lasted about 12 hours before freezing all the cameras simultaneously. Tail of log below, command I used to run it below that. Let me know if there’s anything else I can try before I roll back.

Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://uname:pw@ip::554/Sms=3.unicast -f rawvideo -pix_fmt rgb24 pipe:
front: ffmpeg_process didnt return any bytes
front: ffmpeg_process exited unexpectedly with 1
Letting front rest for 0 seconds before restarting...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://uname:pw@ip::554/Sms=2.unicast -f rawvideo -pix_fmt rgb24 pipe:
back: ffmpeg_process didnt return any bytes
back: ffmpeg_process exited unexpectedly with 0
Letting back rest for 0 seconds before restarting...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://uname:pw@ip::554/Sms=4.unicast -f rawvideo -pix_fmt rgb24 pipe:
right: ffmpeg_process didnt return any bytes
right: ffmpeg_process exited unexpectedly with 1
Letting right rest for 0 seconds before restarting...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://uname:pw@ip:554/Sms=1.unicast -f rawvideo -pix_fmt rgb24 pipe:
docker run --rm --privileged --shm-size=768m -v /dev/bus/usb:/dev/bus/usb -v /volume1/docker/frigate/config:/config:ro -v /etc/localtime:/etc/localtime:ro -v /volume1/docker/frigate/storage:/storage -p5000:5000 -e FRIGATE_MQTT_PASSWORD='PASS' -e FRIGATE_RTSP_PASSWORD='PASS' -e FRIGATE_RTSP_PASSWORD_RIGHT='PASS' -e FRIGATE_RTSP_PASSWORD_LEFT='PASS' -e FRIGATE_RTSP_PASSWORD_FRONT='PASS' -e FRIGATE_RTSP_PASSWORD_BACK='PASS' -e PYTHONPATH='/usr/local/lib/python3.5/dist-packages/tensorflow/models/research:/usr/local/lib/python3.5/dist-packages/tensorflow/models/research/slim' blakeblackshear/frigate:0.5.1-rc1 &

Has anyone gotten this right on Unraid yet with a 0.5.0 build or higher?
I worried about shm-size, but I also want to update.

@blakeblackshear. Have you had any time to look into the issues with this?
I created an automation that restarts my container when issues are detected and it’s restarts several times a day. It’s a band-aid but I can’t find any version that works consistently.

Okay, so I have had it running a couple days now, it seems like running it from the command line and setting the shm-size to 1g has potentially fixed the issue. I also switched back to the camera streams rather than the synology stream (opposite of what worked under 0.2). Fingers crossed.

So I’ve been running 0.51-1 for the last couple days now and I have to say that the ability to catch absolutely everything is amazing in this version! Nothing gets past it! This is just above my .77 threshold and 4000 min size, and only legs but it caught it! Amazing! I would have had to configure the old version specifically for this to get this. This really meets the dreams I’ve had for recognition since I first started playing with the hass tensorflow component a year ago, but it’s the first time I’ve seen it. Thanks for a great component, Blake!

2 Likes

Hi mories, thank you very much for your efforts with the add on. I was wondering is there a way to overcome the 64MB limit on the shm-size?

Thanks again

How to use Coral USB Accelerator?

I have installed the Edge TPU runtime:

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install libedgetpu1-std

What’s next?

No need to install anything. Just plugin the Coral into USB and run the container as described on the GitHub page for Frigate.

2 Likes

It looks like my Coral is not working.
Does Coral need USB 3.0?

CPU is almost fully loaded (Xeon i3):

I use 2 Dahua cam with resolution 3072x1728.

My config.yml
web_port: 5000

mqtt:
  host: 10.0.0.100
  topic_prefix: frigate
  # client_id: frigate # Optional -- set to override default client id of 'frigate' if running multiple instances
  user: user
  #################
  ## Environment variables that begin with 'FRIGATE_' may be referenced in {}.
  password: '123'
  #################
  # password: password # Optional

#################
# Default ffmpeg args. Optional and can be overwritten per camera.
# Should work with most RTSP cameras that send h264 video
# Built from the properties below with:
# "ffmpeg" + global_args + input_args + "-i" + input + output_args
#################
#ffmpeg:
#  global_args:
#    - -hide_banner
#    - -loglevel
#    - panic
#  hwaccel_args: []
#  input_args:
#    - -avoid_negative_ts
#    - make_zero
#    - -fflags
#    - nobuffer
#    - -flags
#    - low_delay
#    - -strict
#    - experimental
#    - -fflags
#    - +genpts+discardcorrupt
#    - -vsync
#    - drop
#    - -rtsp_transport
#    - tcp
#    - -stimeout
#    - '5000000'
#    - -use_wallclock_as_timestamps
#    - '1'
#  output_args:
#    - -f
#    - rawvideo
#    - -pix_fmt
#    - rgb24

####################
# Global object configuration. Applies to all cameras
# unless overridden at the camera levels.
# Keys must be valid labels. By default, the model uses coco (https://dl.google.com/coral/canned_models/coco_labels.txt).
# All labels from the model are reported over MQTT. These values are used to filter out false positives.
# min_area (optional): minimum width*height of the bounding box for the detected person
# max_area (optional): maximum width*height of the bounding box for the detected person
# threshold (optional): The minimum decimal percentage (50% hit = 0.5) for the confidence from tensorflow
####################
objects:
  track:
    - person
    - car
    - truck
  filters:
    person:
      min_area: 1000
      max_area: 500000
      threshold: 0.5

cameras:
  hall:
    ffmpeg:
      ################
      # Source passed to ffmpeg after the -i parameter. Supports anything compatible with OpenCV and FFmpeg.
      # Environment variables that begin with 'FRIGATE_' may be referenced in {}
      ################
      input: rtsp://admin:[email protected]:554/cam/realmonitor?channel=5&subtype=0
      #################
      # These values will override default values for just this camera
      #################
      # global_args: []
      # hwaccel_args: []
      # input_args: []
      # output_args: []
    
    ################
    ## Optionally specify the resolution of the video feed. Frigate will try to auto detect if not specified
    ################
    #height: 1920
    #width: 1080

    ################
    ## Optional mask. Must be the same aspect ratio as your video feed.
    ## 
    ## The mask works by looking at the bottom center of the bounding box for the detected
    ## person in the image. If that pixel in the mask is a black pixel, it ignores it as a
    ## false positive. In my mask, the grass and driveway visible from my backdoor camera 
    ## are white. The garage doors, sky, and trees (anywhere it would be impossible for a 
    ## person to stand) are black.
    ## 
    ## Masked areas are also ignored for motion detection.
    ################
    # mask: back-mask.bmp

    ################
    # Allows you to limit the framerate within frigate for cameras that do not support
    # custom framerates. A value of 1 tells frigate to look at every frame, 2 every 2nd frame, 
    # 3 every 3rd frame, etc.
    ################
    take_frame: 1

    ################
    # The expected framerate for the camera. Frigate will try and ensure it maintains this framerate
    # by dropping frames as necessary. Setting this lower than the actual framerate will allow frigate
    # to process every frame at the expense of realtime processing.
    ################
    fps: 5

    ################
    # Configuration for the snapshots in the debug view and mqtt
    ################
    snapshots:
      show_timestamp: True

    ################
    # Camera level object config. This config is merged with the global config above.
    ################
    objects:
      track:
        - person
      filters:
        person:
          min_area: 1000
          max_area: 500000
          threshold: 0.5

  outdoor2:
    ffmpeg:
      ################
      # Source passed to ffmpeg after the -i parameter. Supports anything compatible with OpenCV and FFmpeg.
      # Environment variables that begin with 'FRIGATE_' may be referenced in {}
      ################
      input: rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0
      #################
      # These values will override default values for just this camera
      #################
      # global_args: []
      # hwaccel_args: []
      # input_args: []
      # output_args: []
    
    ################
    ## Optionally specify the resolution of the video feed. Frigate will try to auto detect if not specified
    ################
    # height: 1280
    # width: 720

    ################
    ## Optional mask. Must be the same aspect ratio as your video feed.
    ## 
    ## The mask works by looking at the bottom center of the bounding box for the detected
    ## person in the image. If that pixel in the mask is a black pixel, it ignores it as a
    ## false positive. In my mask, the grass and driveway visible from my backdoor camera 
    ## are white. The garage doors, sky, and trees (anywhere it would be impossible for a 
    ## person to stand) are black.
    ## 
    ## Masked areas are also ignored for motion detection.
    ################
    # mask: back-mask.bmp

    ################
    # Allows you to limit the framerate within frigate for cameras that do not support
    # custom framerates. A value of 1 tells frigate to look at every frame, 2 every 2nd frame, 
    # 3 every 3rd frame, etc.
    ################
    take_frame: 1

    ################
    # The expected framerate for the camera. Frigate will try and ensure it maintains this framerate
    # by dropping frames as necessary. Setting this lower than the actual framerate will allow frigate
    # to process every frame at the expense of realtime processing.
    ################
    fps: 5

    ################
    # Configuration for the snapshots in the debug view and mqtt
    ################
    snapshots:
      show_timestamp: True

    ################
    # Camera level object config. This config is merged with the global config above.
    ################
    objects:
      track:
        - person
      filters:
        person:
          min_area: 500
          max_area: 10000
          threshold: 0.5

What is your framerate at that resolution? It will also help to use hardware acceleration to decode the video if possible. Unless you are trying to detect very small objects that are far away, I would suggest using a lower resolution sub stream. The models are trained on 300x300 images, so you don’t get better accuracy with higher resolution streams.

2 Likes

If you’re running an older machine you may have issues as Tensorflow needs some newer CPU abilities. I tried running on a 2011 Mac mini and failed, had to move to a new synology.

1 Like

Was that a question for me? I run 4 fps. Can’t get hardware acceleratoion working on the synology, but would love to hear from someone who did. CPU usage doesn’t seem that bad, but sometimes it does give up on making the green detection box earlier than I’d like. Would be nice to configure that in future versions.

What’s the best way to avoid this?

use the minimum size option. No human should be that small.

What do you recommend I set it to?

look for an image with an actual person in the area you want to monitor and start with that.

Something smaller than that… Other option would be to take the size of the false positives you get and make it bigger than that. For you, you could start at 7000-8000 on that camera and see how things go.

So with 1g, it lasted 4 days before freezing in the same way, so I suspect it’s somehow chewing up the memory until it runs out. Here’s the log tail and the run command.

back: ffmpeg_process didnt return any bytes
back: ffmpeg_process exited unexpectedly with 0
Letting back rest for 0 seconds before restarting...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffe                                                                                                             r -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync dr                                                                                                             op -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp:                                                                                                             //uname:pw@ip:554/Streaming/channels/1 -f rawvideo -pix_fmt r                                                                                                             gb24 pipe:
left: ffmpeg_process didnt return any bytes
left: ffmpeg_process exited unexpectedly with 0
Letting left rest for 0 seconds before restarting...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffe                                                                                                             r -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync dr                                                                                                             op -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp:                                                                                                             //uname:pw@ip:554/Streaming/channels/1 -f rawvideo -pix_fmt r                                                                                                             gb24 pipe:
back: ffmpeg_process exited unexpectedly with 0
Letting back rest for 0 seconds before restarting...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Creating ffmpeg process...
ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffe                                                                                                             r -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync dr                                                                                                             op -rtsp_transport tcp -stimeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp:                                                                                                             //uname:pw@ip:554/Streaming/channels/1 -f rawvideo -pix_fmt r                                                                                                             gb24 pipe:
docker run --rm --privileged --shm-size=1g -v /dev/bus/usb:/dev/bus/usb -v /volume1/docker/frigate/config:/config:ro -v /etc/localtime:/etc/localtime:ro -v /volume1/docker/frigate/storage:/storage -p 4000:4000 -e FRIGATE_MQTT_PASSWORD='my_password' -e FRIGATE_RTSP_PASSWORD='PooPoo22' -e FRIGATE_RTSP_PASSWORD_RIGHT='my_password' -e FRIGATE_RTSP_PASSWORD_LEFT='my_password' -e FRIGATE_RTSP_PASSWORD_FRONT='my_password' -e FRIGATE_RTSP_PASSWORD_BACK='my_password' -e PYTHONPATH='/usr/local/lib/python3.5/dist-packages/tensorflow/models/research:/usr/local/lib/python3.5/dist-packages/tensorflow/models/research/slim' blakeblackshear/frigate:0.5.1-rc1 &

Ok thanks, I went with 10000 and must be too large so I’ll drop down to 7 and see how that goes.

I’m notices that all my cameras eventually stop using the coral and go to cpu, anyone had that?

As i understand it, 0.5.x use CPU to detect rought motion area and create dynamic regions.
then it runs object detection with coral against it

When motion is detected, coral should be activated