Local realtime person detection for RTSP cameras

I did get this working, however if the camera stream is wrong, frigate seems to get stuck somewhere and won’t respond if you query it on port 5000. When I got that part working everything seemed to be happy. It might be nice to spit out some more debugging information. I don’t think I saw anything that explicitly said there was problems with the stream. Maybe I missed something though. Thanks for the awesome project!

1 Like

Does anyone else have frigate running inside of a VirtualBox Ubuntu VM with a Coral attached? It works but I noticed 2 behaviors:

  • When it is running using a coral, eventually my Virtual Machine freezes up bringing down everything with it, including HASSIO. When I run frigate without a coral attached, it appears to run just fine.

  • When I am using a coral and I restart the frigate docker container container, the virtualbox VM loses control of the coral forcing me to “re-attach” it before it can use it again.

I need to do some more investigation on these issues, I like the solution when frigate is up and running with the coral however currently for me it is giving me some stability issues.

I just wanted to see if anyone saw anything similar.

In case anyone migrates to an Intel NUC10 (I moved my Frigate LXC on Proxmox from NUC8 to NUC10), then it looks like you’ll need to build your own VAAPI drivers.

I followed https://github.com/intel/media-driver/wiki/How-to-build-and-use-media-driver%3F and was able to get ffmpeg hardware acceleration working again on the new machine.

//TB

You should be able to just download it if you running Ubuntu without having to compile.

Hello, which pci-e USB Controllers are you using?

@blakeblackshear, has anyone suggested some sort of REST API or endpoint in Frigate where one could turn on/off detection for a certain camera? Was thinking about how that would be useful for my setup for use in a few HA automations. Maybe it’s something that’s already on your mental roadmap?

@hawkeye217,

This may not work in your instance, but I solve this problem with an mqtt/node-red/home-assistant/blueIris setup.

  • frigate pings an alert via MQTT
  • node-red listens for these alerts on MQTT, then checks if the alert should really run based on a number of rules
  • if the alert should really ‘fire’, node-red will drop a new mqtt message from Blue Iris to trigger an alert for the camera

Basically, there is a home-assistant input_boolean to toggle certain camera alerting off/on that I toggle via the home-assistant interface when I want to temporarily disable a camera.

There are a lot more components and complexities to make this happen, but it is a possible approach you could explore.

Love the implementation, it’s similar to what I do now just with some YAML in HA. I was thinking of actually disabling detection in Frigate somehow (to save CPU cycles) for a particular camera at certain times of the day.

Yes. It would be easy to add an API endpoint and/or a MQTT topic for it. Looks like there is a related ticket already: https://github.com/blakeblackshear/frigate/issues/16

I can look at adding that for the next release.

2 Likes

Awesome. Either an endpoint or MQTT topic would work well for me - whatever would be easiest for you to implement. Thanks @blakeblackshear!

Hello Blake,
I just want to say thank you for this great work. I installed Frigate incl. a Coral device about a week ago and it is running really fine with 3 cams at the moment. I’m using it with a Node-Red flow that saves some snapshots to disk if Frigate sends a person detection event via MQTT (but only if my custom node-red based alarm system is enabled). Works really fantastic so far. It’s real fun to see the bounding box tracking you while walking around in the garden :wink:
Only very few false positives at night, when insects are flying right in front of the camera lense.

So again: Thanks a lot @blakeblackshear for this great peace of software that makes real time object detection usable without the need for any cloud service and at reasonable costs!

Hi all,

I think this is awesome and would like to try it. I have questions that might have been answered already but I was not able to find the answers in this monster thread.

  • Can I attach a Coral device to a Pi 4?
  • Has anybody running this with success on a Pi 4?

Thank you!

@blakeblackshear Any hope to use a better model with the Coral usb key? The actual is not very good in detecting small person shapes and, using a low threshold, it reports many false positives.

Thanks for your great job!

There is a thread on github about it. It’s not easy as the Coral is limited to Tensorflow Lite models (generally mobile ones), but he’s looking at what options there are.

It doesn’t work out of the box on a RPi4. You have to make some modifications and you also loose hardware acceleration for decoding the video stream. Also, if you are running hass.io, you can’t configure the shm-size yet. It works, just not that well. There is an issue on github for building a RPi compatible version. If you are looking to buy hardware, the cheapest board that works well is the Atomic Pi.

1 Like

I just updated frigate from a very old version to blakeblackshear/frigate:stable, also updated the yaml structure. But now facing the errors below, they mainly occur when a person enters the camera. With the old version everything worked like a charm.

30-6-2020 13:42:13On connect called
30-6-2020 13:42:13ffprobe -v panic -show_error -show_streams -of json "rtsp://192.168.178.***:***/***"
30-6-2020 13:42:13Starting detection process: 25
30-6-2020 13:42:17{'streams': [{'index': 0, 'codec_name': 'aac', 'codec_long_name': 'AAC (Advanced Audio Coding)', 'profile': 'LC', 'codec_type': 'audio', 'codec_time_base': '1/11025', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'sample_fmt': 'fltp', 'sample_rate': '11025', 'channels': 1, 'channel_layout': 'mono', 'bits_per_sample': 0, 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/11025', 'start_pts': 1356, 'start_time': '0.122993', 'disposition': {'default': 0, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}}, {'index': 1, 'codec_name': 'h264', 'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10', 'profile': 'Main', 'codec_type': 'video', 'codec_time_base': '1/30', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'width': 640, 'height': 360, 'coded_width': 640, 'coded_height': 360, 'has_b_frames': 0, 'sample_aspect_ratio': '189:190', 'display_aspect_ratio': '168:95', 'pix_fmt': 'yuvj420p', 'level': 30, 'color_range': 'pc', 'color_space': 'bt709', 'color_transfer': 'bt709', 'color_primaries': 'bt709', 'chroma_location': 'left', 'field_order': 'progressive', 'refs': 1, 'is_avc': 'false', 'nal_length_size': '0', 'r_frame_rate': '15/1', 'avg_frame_rate': '15/1', 'time_base': '1/90000', 'start_pts': 41970, 'start_time': '0.466333', 'bits_per_raw_sample': '8', 'disposition': {'default': 0, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}}]}
30-6-2020 13:42:17Creating ffmpeg process...
30-6-2020 13:42:17ffmpeg -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://192.168.178.230:7447/5e819480e4b02db23c364b00_2 -f rawvideo -pix_fmt rgb24 pipe:
30-6-2020 13:42:17ffprobe -v panic -show_error -show_streams -of json "rtsp://192.168.178.***:***/***"
30-6-2020 13:42:20{'streams': [{'index': 0, 'codec_name': 'aac', 'codec_long_name': 'AAC (Advanced Audio Coding)', 'profile': 'LC', 'codec_type': 'audio', 'codec_time_base': '1/48000', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'sample_fmt': 'fltp', 'sample_rate': '48000', 'channels': 1, 'channel_layout': 'mono', 'bits_per_sample': 0, 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/48000', 'start_pts': 0, 'start_time': '0.000000', 'disposition': {'default': 0, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}}, {'index': 1, 'codec_name': 'h264', 'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10', 'profile': 'Main', 'codec_type': 'video', 'codec_time_base': '1/30', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'width': 640, 'height': 360, 'coded_width': 640, 'coded_height': 360, 'has_b_frames': 0, 'sample_aspect_ratio': '1:1', 'display_aspect_ratio': '16:9', 'pix_fmt': 'yuvj420p', 'level': 30, 'color_range': 'pc', 'color_space': 'bt709', 'color_transfer': 'bt709', 'color_primaries': 'bt709', 'chroma_location': 'left', 'field_order': 'progressive', 'refs': 1, 'is_avc': 'false', 'nal_length_size': '0', 'r_frame_rate': '15/1', 'avg_frame_rate': '15/1', 'time_base': '1/90000', 'start_pts': 48000, 'start_time': '0.533333', 'bits_per_raw_sample': '8', 'disposition': {'default': 0, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}}]}
30-6-2020 13:42:20Creating ffmpeg process...
30-6-2020 13:42:20ffmpeg -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://192.168.178.230:7447/5e8194f1e4b02db23c364b03_2 -f rawvideo -pix_fmt rgb24 pipe:
30-6-2020 13:42:20Camera_process started for frontdoor: 42
30-6-2020 13:42:20Camera_process started for garden: 43
30-6-2020 13:42:20Starting process for garden: 43
30-6-2020 13:42:20Starting process for frontdoor: 42
30-6-2020 13:42:20 * Serving Flask app "detect_objects" (lazy loading)
30-6-2020 13:42:20 * Environment: production
30-6-2020 13:42:20   WARNING: This is a development server. Do not use it in a production deployment.
30-6-2020 13:42:20   Use a production WSGI server instead.
30-6-2020 13:42:20 * Debug mode: off
30-6-2020 13:42:50Detection appears to be stuck. Restarting detection process
30-6-2020 13:42:50Waiting for detection process to exit gracefully...
30-6-2020 13:42:50Starting detection process: 68
30-6-2020 13:44:31Detection appears to be stuck. Restarting detection process
30-6-2020 13:44:31Waiting for detection process to exit gracefully...
30-6-2020 13:44:31Starting detection process: 95
30-6-2020 13:45:11Detection appears to be stuck. Restarting detection process
30-6-2020 13:45:11Waiting for detection process to exit gracefully...
30-6-2020 13:45:11Starting detection process: 111

Did you update your shm-size parameter? Can you post the command or compose file you use to run the container?

When I do a docker inspect it gives me "ShmSize": 1073741824.

version: '2'
services:
  frigate:
    image: blakeblackshear/frigate:stable
    privileged: true
    shm_size: '1g'
    volumes:
      - /var/lib/docker/volumes/frigate:/config:ro
      - /dev/bus/usb:/dev/bus/usb
    ports:
      - ${PORT}:5000
    restart: always
    environment:
      TZ: ${TZ}

Should I update to a non-stable release?

Are you sure another container isn’t using the Coral too? Maybe try stopping the container and unplugging the coral. Everyone seems to be running stable without issues at this point.

revisiting using UDP again.

When I choose UDP, the image is very distorted. I can post a video clip if you’d like.
Should we be able to use UDP instead of TCP?
Is there anything special required?