Local realtime person detection for RTSP cameras

I will eventually make this available as a hassio addon. It seems simple enough. I am not sure if it will run in HassOS. At the moment it does not support any kind of hardware accelerated decoding in ffmpeg.

1 Like

Thanks a lot, I will be aware of the thread to know if there is progress on the addon, I am working on hassio in docker with ubuntu, but I repeat, my knowledge is very low. Right now I am using doods addon with a Google Coral.
Thanks again

Is anyone successfully using any of the output arguments? Frigate works with both cameras without any output arguments.
I have tried with two camera feeds (one Reolink 410 and one ESP32 Cam) which I need to rotate 90 degrees and Iā€™ve tried using -vf "transpose=1" but Iā€™m getting errors:

Creating a new 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://192.168.1.78:8554/mjpeg/1 -vf "transpose=1" pipe:
Creating a new capture thread...
Starting a new capture thread...
ffmpeg didnt return a frame. something is wrong. exiting capture thread...
last frame is more than 5 minutes old, restarting camera capture...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Waiting for the capture thread to exit...
Creating a new ffmpeg process...

Iā€™ve tried both -vf "transpose=1" and -vf transpose=1 but they both give the same error. I even tried just -vf by itself.

Iā€™ve also tried just an empty array for output_args (output_args: []) and Iā€™m still getting a loop of:

Creating a new 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://192.168.1.78:8554/mjpeg/1 pipe:
Creating a new capture thread...
Starting a new capture thread...
ffmpeg didnt return a frame. something is wrong. exiting capture thread...
last frame is more than 5 minutes old, restarting camera capture...
Terminating the existing ffmpeg process...
Waiting for ffmpeg to exit gracefully...
Waiting for the capture thread to exit...
Creating a new ffmpeg process...

If I do a basic ffmpeg command on the same machine, I get an output file that has been rotated correctly:

ffmpeg -i rtsp://192.168.1.78:8554/mjpeg/1 -vf "transpose=1" -ss 00:00:0.0 -t 10 out1.mov

Specifying output args will replace the defaults and you need most of the defaults for it to function. If you want to customize, start by copying the defaults and adding what you want. The only optional arg in the defaults is mpdecimate.

1 Like

Thanks, the defaults for me seem to be -vf mpdecimate -f rawvideo -pix_fmt rgb24, is that correct?

If I add them in as output_args then I still get the ffmpeg didnt return a frame. error, but if I remove the output args, I can see the default frigate ffmpeg command is identical to mine when using output args:

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://192.168.1.78:8554/mjpeg/1 -vf mpdecimate -f rawvideo -pix_fmt rgb24 pipe:

Hereā€™s my camera config just for reference:

cameras:
  driveway:
    ffmpeg:
      input: rtsp://192.168.1.78:8554/mjpeg/1
      output_args:
        - -vf mpdecimate -f rawvideo -pix_fmt rgb24

Each argument has to be a separate item in the array. You canā€™t combine them all into a single line like that. Look at the default config.

1 Like

Ah my bad, of course! Thank you.

Got rotation working now with the below incase itā€™s useful for anyone else:

      output_args:
        - -vf
        - mpdecimate,rotate=PI/2
        - -f
        - rawvideo
        - -pix_fmt
        - rgb24

I just noticed that the new coral libraries from Google are compatible with tensorflow lite now. This means frigate can run inference on the CPU or a Coral once I update. The Coral wonā€™t be required anymore, but I think you would be crazy not to use one. At least that would allow more people to try it out without buying a Coral.

4 Likes

If youā€™re on Ubuntu/intel, it shouldnā€™t be very hard to get going. Try to follow the directions on the install page to the letterā€¦ Most of your work will be in doing the config file, but that doesnā€™t require any OS level skills.

I donā€™t have much knowledge of docker either and the routes are different for hass.io it all adds up :slight_smile:

In the complement that I am using I have noticed that the coral models are not the best, in my case if it is night, it does not even recognize a person. I have read something about a tensorflow model converter for the tensorflowlite, does anyone know anything about it?

1 Like

Where do you find this output?

That was a screeenshot from mqtt explorer app on my Mac.

When I was running full fat tensorflow, I got much better results from faster_rcnn_inception_v2_coco then I got from any of the mobilenet models. But that was at a framerate of 1 frame per 10 seconds, so I really had to make it countā€¦ With the 5fps itā€™s less of an issue, but Iā€™d still like to have a way to go back to that model, it worked really well.

Thats I read about faster_rcnn_Inception_v2_coco, but im using Google coral and that model is not uvaiable

I know, me too :frowning:

Thatā€™s because I was asking before if someone read about the tensorflowlite converter

You can run this command in a terminal:

sudo docker logs --timestamps <name of container>

Output looks like this:

2020-01-01T11:12:18.953921908Z Creating a new capture thread...
2020-01-01T11:12:18.954276783Z Starting a new capture thread...
2020-01-01T11:12:18.956126143Z Capture process for cars: 49
2020-01-01T11:12:18.972700299Z  * Serving Flask app "detect_objects" (lazy loading)
2020-01-01T11:12:18.972744707Z  * Environment: production
2020-01-01T11:12:18.972765581Z    WARNING: This is a development server. Do not use it in a production deployment.
2020-01-01T11:12:18.972786220Z    Use a production WSGI server instead.
2020-01-01T11:12:18.972805813Z  * Debug mode: off
2020-01-01T11:12:18.974573197Z  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
2020-01-01T11:51:47.132819399Z queue full. moving on
1 Like

It doesnā€™t seem that my mask is being taken into consideration. Is there a way for me to verify one way within frigate? Also, I have seen some examples on this thread where the mask appears to be at the region level; however, the example config and code comments appear that the mask is at the video feed resolution. Itā€™s the later of the two, correct (video feed)?

Thanks for the tip on motioneye, I will have to integrate this, as I have been going to far worse extremes trying to get the video.

There are currently two things I am mostly trying to accomplish, one retain a rolling history of alerts (in my iOS app) and two, be able to click on any of them for a video of the event from motion ON to OFF.

For my set-up I am not actually using the HA app at all, but rather my own iOS app I developed specifically for using frigate. The app connects to my back-end service using HA-proxy, Node-red and of course, frigate. These services are all hosts on 2 rpi4s each with a coral. Node red is actively listening to each mqtt topic for each camera feed (7 feeds) and when motion is detected, it sends the url of the bestperson.jpg to my phone via push notification, and the ios app retrieves the image. Works quite well, but I havenā€™t coded out the solution of image storage, I donā€™t really just want to save the push images since if you are without reception, any images attempted to be pushed at that time are lost. So I think I will likely rather write some modifications to frigate to md5hash bestperson on motion alert and store it in something like Amazon s3, and have the ios app just get all of its images from there outside of the push process.

For video, I have a small api that will listen to an RTSP stream (and with Hikvision you can set a ā€œstart timeā€ rather than live for playback.) So the motion on time is passed to the API which listens to the RTSP stream and re-encodes it as an MPEG stream. The url for the MPEG stream is passed to the phone as part of the push, and can be replayed when clicked on (prototype works, but not fully coded out.)

Just wanted to share a bit of how I have been working with frigate. Having short 5-10 frame gif bursts for push notifications would be a great add as well at somepoint - sometimes the camera image shot for bestperson.jpg is a bad angle, etc.