Local realtime person detection for RTSP cameras

it runs at 15 during day and drops to 10 in night mode.
Would there be an issue having it at 15 when it drops to 10?

What is your take_frame set to?

I would set it to 10 then. Frigate will try and prevent the fps from dropping below that number by skipping frames. My take_frame is 1.

It recovers but there are a bunch of restarts.
Iā€™m tracking the PID and the bottom shows every time it changes due to a restart.
You can also see the restart as a dip on the top graph

Hi Blake

Iā€™ve come across a small problem on 0.5.1-rc1 and 0.5.1-rc2.

I have a number of Reolink cameras using the RTMP stream (as it seems more robust than RTSP on these cameras). Frigate does not restart the stream when these are rebooted/disconnected. Nothing additional comes up in the log (loglevel info). The debug stream and the debug stats FPS remain stuck at what they were prior to the disconnection.

The RTSP stream works as expected - the stream is restarted successfully. This was not a problem on 0.4.0 and prior.

Many thanks :slight_smile:

Can you try with just one camera? Curious if having multiple is making yours restart more frequently than mine.

Can you compare the ffmpeg command from the logs between 0.4.0 and 0.5.1-rc2? It is the same version of ffmpeg.

Iā€™ve removed the second camera from the config and itā€™s still restarting.
I donā€™t know if this is related, but itā€™s constantly showing the bounding boxes on a neighborā€™s car.

https://youtu.be/TiFxUdMQ46w. (I cropped it to just show the car)

btwā€¦ it doesnā€™t happen consistently. also, itā€™s currently raining here so maybe the rain is messing with the image. There are 2 other cars in view but they arenā€™t getting the bounding boxes.

Thanks. Please see below. I set the ā€˜frontā€™ camera to use RTSP and the ā€˜sideā€™ camera to use RTMP. Both are the same camera model. On 0.4.0-beta, both streams are recovered upon rebooting each camera. On 0.5.1-rc2 the RTSP stream is recovered but not the RTMP. The ffmpeg commands are the same except the force frame rate and mpdecimate switches.

Edit - the problem is that the ffmpeg process does not timeout and exit for a broken RTMP stream. Unlike the RTSP feed which terminates with e.g. rtsp://xxx:[email protected]:554/h264Preview_01_sub: Connection timed out. Iā€™ve tried adding various timeout options on the ffmpeg argument , but no luck yet.

------------------------------------------------------------
0.4.0-beta :-

2020-03-15T17:13:54.880758506Z Creating a new ffmpeg process...
2020-03-15T17:13:54.882203033Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -r 6 -use_wallclock_as_timestamps 1 -i rtsp://username:[email protected]:554/h264Preview_01_sub -vf mpdecimate -f rawvideo -pix_fmt rgb24 pipe:
2020-03-15T17:13:54.921524924Z Creating a new capture thread...
2020-03-15T17:13:54.922578866Z Starting a new capture thread...
2020-03-15T17:13:54.924156167Z Capture process for front: 82

]2020-03-15T17:13:54.969923669Z Creating a new ffmpeg process...
2020-03-15T17:13:54.970223422Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -r 6 -use_wallclock_as_timestamps 1 -i rtmp://x.x.x.82:1935/bcs/channel0_sub.bcs?channel=0&stream=0&user=username&password=password -vf mpdecimate -f rawvideo -pix_fmt rgb24 pipe:
2020-03-15T17:13:54.992137350Z Creating a new capture thread...
2020-03-15T17:13:54.992818873Z Starting a new capture thread...
2020-03-15T17:13:55.009097081Z Capture process for side: 91

2020-03-15T17:13:55.056336238Z  * Serving Flask app "detect_objects" (lazy loading)
2020-03-15T17:13:55.056651695Z  * Environment: production
2020-03-15T17:13:55.057134481Z    WARNING: This is a development server. Do not use it in a production deployment.
2020-03-15T17:13:55.057626138Z    Use a production WSGI server instead.
2020-03-15T17:13:55.058326828Z  * Debug mode: off
2020-03-15T17:13:55.061878571Z  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

2020-03-15T17:17:37.403808549Z front: ffmpeg didnt return a frame. something is wrong. exiting capture thread...
2020-03-15T17:22:15.389650799Z front: last frame is more than 5 minutes old, restarting camera capture...
2020-03-15T17:22:15.389805315Z Terminating the existing ffmpeg process...
2020-03-15T17:22:15.389879481Z Waiting for ffmpeg to exit gracefully...
2020-03-15T17:22:15.391192313Z Waiting for the capture thread to exit...

2020-03-15T17:22:15.393260430Z Creating a new ffmpeg process...
2020-03-15T17:22:15.393507278Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -r 6 -use_wallclock_as_timestamps 1 -i rtsp://username:[email protected]:554/h264Preview_01_sub -vf mpdecimate -f rawvideo -pix_fmt rgb24 pipe:
2020-03-15T17:22:15.468660959Z Creating a new capture thread...
2020-03-15T17:22:15.470781705Z Starting a new capture thread...


2020-03-15T17:30:45.925994100Z side: last frame is more than 5 minutes old, restarting camera capture...
2020-03-15T17:30:45.926374389Z Terminating the existing ffmpeg process...
2020-03-15T17:30:45.927147116Z Waiting for ffmpeg to exit gracefully...
2020-03-15T17:31:15.928242536Z FFmpeg didnt exit. Force killing...
2020-03-15T17:31:15.935217560Z side: ffmpeg didnt return a frame. something is wrong. exiting capture thread...
2020-03-15T17:31:15.935924658Z Waiting for the capture thread to exit...

2020-03-15T17:31:15.936442057Z Creating a new ffmpeg process...
2020-03-15T17:31:15.936611313Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -r 6 -use_wallclock_as_timestamps 1 -i rtmp://x.x.x.82:1935/bcs/channel0_sub.bcs?channel=0&stream=0&user=username&password=password -vf mpdecimate -f rawvideo -pix_fmt rgb24 pipe:
2020-03-15T17:31:15.977229310Z Creating a new capture thread...
2020-03-15T17:31:15.977714264Z Starting a new capture thread...

0.5.1-rc2 :-

2020-03-15T16:49:42.353938299Z Creating ffmpeg process...
2020-03-15T16:49:42.354685876Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -use_wallclock_as_timestamps 1 -i rtsp://username:[email protected]:554/h264Preview_01_sub -f rawvideo -pix_fmt rgb24 pipe:

2020-03-15T16:49:42.403176515Z Creating ffmpeg process...
2020-03-15T16:49:42.403289271Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -use_wallclock_as_timestamps 1 -i rtmp://x.x.x.82:1935/bcs/channel0_sub.bcs?channel=0&stream=0&user=username&password=password -f rawvideo -pix_fmt rgb24 pipe:

2020-03-15T16:49:42.507673228Z Camera_process started for front: 35
2020-03-15T16:49:42.517695890Z Camera_process started for side: 36
2020-03-15T16:49:42.526465467Z Starting process for front: 35
2020-03-15T16:49:42.532271068Z Starting process for side: 36

2020-03-15T16:49:42.623337876Z  * Serving Flask app "detect_objects" (lazy loading)
2020-03-15T16:49:42.634687474Z  * Environment: production
2020-03-15T16:49:42.635039411Z    WARNING: Do not use the development server in a production environment.
2020-03-15T16:49:42.635313886Z    Use a production WSGI server instead.
2020-03-15T16:49:42.635385829Z  * Debug mode: off

2020-03-15T16:55:47.214532560Z front: ffmpeg didnt return a frame. something is wrong.
2020-03-15T16:55:47.215343766Z front: ffmpeg process is not running. exiting capture thread...
2020-03-15T16:55:52.923874257Z Creating ffmpeg process...
2020-03-15T16:55:52.924109882Z ffmpeg -hide_banner -loglevel panic -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -vsync drop -use_wallclock_as_timestamps 1 -i rtsp://username:[email protected]:554/h264Preview_01_sub -f rawvideo -pix_fmt rgb24 pipe:

Hereā€™s a view from the past hour.
Itā€™s restarting every few minutes

The constant detection is expected. Once it sees an object, it keeps tracking it until it disappears. There was probably some motion that triggered it to look where the car being detected is. The other cars are probably in areas that havenā€™t been checked due to a lack of motion or the scores are low enough that it lost track.

Interesting. I would try setting these values in your input parameters: https://stackoverflow.com/questions/52021958/how-to-stop-ffmpeg-from-running-if-connection-to-input-stream-is-lost/52299137

Looks like the 0.4.0 version would drop out for 5 minutes before reconnecting. Getting ffmpeg to exit would be a better solution.

I would try removing the driveway camera from frigate and running the ffmpeg command manually in the container while sending output to /dev/null. See if it logs anything that explains why it exits so frequently.

I tried the timeout switch yesterday but it had no effect, and it seems stimeout is only supported for RTSP. Iā€™m using the RTSP stream instead now and so far have not had any issues with artifacts (which is what led me to switch to RTMP in the first place) , so hopefully all will be good :slight_smile:

Hi, can you share your config.yml for reolink and rtmp ? im getting when i use rtmp instead of rtsp
ffmpeg didnt return a frame. something is wrong. exiting capture thread...

@mr-onion figured out that i was running an old version - and now rtsp is working :slight_smile: but if you use rtmp and still want to share your config, i would be grateful

Hi, glad you got RTSP working :slight_smile:

Here is what I was using for RTMP

rtmp://x.x.x.x:1935/bcs/channel0_sub.bcs?channel=0&stream=0&user=admin&password={FRIGATE_RTSP_PASSWORD}

Also this is what I am using for the default ffmpeg arguments - not too different from the default.

ffmpeg:
#   global_args:
#     - -hide_banner
#     - -loglevel
#     - info
#   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
2 Likes

Hello,
The event based detection with MQTT on a topic ā€œfrigate/camera1/personā€ is awesome.
With Node Red I can now listen and post a snapshot to telegram for alerting purpose. (This takes about 5secs - really cool)

Next I would like to trigger a video recording of the camera stream based on this mqtt event:
When frigate/camera1/person returns ā€œONā€ and then ā€œOFFā€ when no one there.

Is there a way I can act on this to start a recording via either NodeRed, HomeAssistant, ffmpeg?

  1. With ideally an async process so I can tell it when to start and when to stop.
    HomeAssistant ā€œcamera.recordā€ service requires a ā€œdurationā€ defined in seconds, so not ideal.
  2. With ideally an option to ā€œrecord in the pastā€ (5 or 10sec)
    Like described here: #1753 (Delay output for X seconds) ā€“ FFmpeg

Iā€™m still searching how to do this - but if anyone has some good ideas :slight_smile:

Edit:
Actually there is a good idea in this thread already - I will give a try:

Running 0.5.0 I see that the ffmpeg streams (for all cameras) occasionally drop and get restarted. Is this anything to be concerned about, or normal behavior?

		
2020-03-16 16:51:06	
2020-03-16T20:51:06.095952155Z stdout F 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://<redacted>@basement:554/h264Preview_01_sub -f rawvideo -pix_fmt rgb24 pipe:
2020-03-16 16:51:06	
2020-03-16T20:51:06.095732291Z stdout F Creating ffmpeg process...
2020-03-16 16:51:06	
2020-03-16T20:51:06.09552383Z stdout F Waiting for ffmpeg to exit gracefully...
2020-03-16 16:51:06	
2020-03-16T20:51:06.09531242Z stdout F Terminating the existing ffmpeg process...
2020-03-16 16:51:06	
2020-03-16T20:51:06.095114715Z stdout F basement: ffmpeg_process exited unexpectedly with 0
2020-03-16 16:51:06	
2020-03-16T20:51:06.094767056Z stdout F basement: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.068432183Z stdout F 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://view:view1234@front:554/cam/realmonitor?channel=1&subtype=1 -f rawvideo -pix_fmt rgb24 pipe:
2020-03-16 16:51:06	
2020-03-16T20:51:06.068236983Z stdout F Creating ffmpeg process...
2020-03-16 16:51:06	
2020-03-16T20:51:06.068031864Z stdout F Waiting for ffmpeg to exit gracefully...
2020-03-16 16:51:06	
2020-03-16T20:51:06.067822155Z stdout F Terminating the existing ffmpeg process...
2020-03-16 16:51:06	
2020-03-16T20:51:06.067630661Z stdout F front: ffmpeg_process exited unexpectedly with 0
2020-03-16 16:51:06	
2020-03-16T20:51:06.067153168Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.067141119Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.067129373Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.067116331Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.067104626Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.067092754Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.0670809Z stdout F front: ffmpeg_process is still running but didnt return any bytes
2020-03-16 16:51:06	
2020-03-16T20:51:06.0670691Z stdout F front: ffmpeg_process is still running but didnt return any bytes

I made some changes for 0.5.1 that seem to have reduced the number of restarts.

1 Like

Once itā€™s restarted, it can run for hours or sometimes just a few minutes, but once it gets into the weird state, it gradually ramps up and is restarted more often.

When it does break down, the following pattern is in the logs

Latest error before restarting

3:07pm

frame= 6386 fps= 14 q=-0.0 size=38794950kB time=00:07:05.73 bitrate=746496.0kbits/s speed=0.9598x
frame= 7028 fps= 14 q=-0.0 size=42652575kB time=00:07:48.06 bitrate=746496.0kbits/s speed=0.957x
frame= 7670 fps= 14 q=-0.0 size=46595250kB time=00:08:31.33 bitrate=7433272.3kbits/s speed=0.998x
frame=11778 fps= 20 q=-0.0 size=103033944kB time=00:09:48.35 bitrate=1433272.3kbits/s speed=0.998x
[h264 @ 0x5623c9bd2a40] error while decoding MB 113 25, bytestream -81433272.3kbits/s speed=0.998x
No more output streams to write to, finishing.e=00:09:03.06 bitrate=746496.0kbits/s speed=0.878x      496.0kbits/s speed=0.957x
2020-03-15T19:07:59.820611130Z frame= 8146 fps= 13 q=-0.0 Lsize=49486950kB time=00:09:03.06 bitrate=746496.0kbits/s speed=0.878x
2020-03-15T19:07:59.820937408Z video:49486950kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
2020-03-15T19:07:59.821058454Z Input file #0 (rtsp://user:[email protected]/live):
2020-03-15T19:07:59.830539119Z driveway: ffmpeg didnt return a frame. something is wrong.
2020-03-15T19:07:59.830997494Z driveway: ffmpeg process is not running. exiting capture threadā€¦


3:18pm

frame=18593 fps= 20 q=-0.0 size=162651564kBtime=00:04:56.60 bitrate=746496.0kbits/s speed=0.962x
frame=19475 fps= 20 q=-0.0 size=170367300kB time=00:16:13.75 bitrate=1433272.3kbits/s speed=0.999x
No more output streams to write to, finishing.e=00:05:44.73 bitrate=746496.0kbits/s speed=0.809x
2020-03-15T19:15:09.241523282Z frame= 5171 fps= 12 q=-0.0 Lsize=31413825kB time=00:05:44.73 bitrate=746496.0kbits/s speed=0.809x
2020-03-15T19:15:09.241736941Z video:31413825kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
2020-03-15T19:15:09.241829558Z Input file #0 (rtsp://user:[email protected]/live):
2020-03-15T19:15:09.241906790Z   Input stream #0:0 (video): 5179 packets read (55855167 bytes); 5171 frames decoded;
2020-03-15T19:15:09.241988613Z   Input stream #0:1 (audio): 2274 packets read (2425600 bytes);
2020-03-15T19:15:09.242055323Z   Total: 7453 packets (58280767 bytes) demuxed
2020-03-15T19:15:09.242119423Z Output file #0 (pipe:):
2020-03-15T19:15:13.119097638Z driveway: ffmpeg didnt return a frame. something is wrong.
2020-03-15T19:15:13.119863296Z driveway: ffmpeg process is not running. exiting capture thread...
2020-03-15T19:15:20.411964751Z Creating ffmpeg process...


4:35pm

[h264 @ 0x55cd52221ce0] error while decoding MB 68 16, bytestream -7=1433272.3kbits/s speed=0.886x
No more output streams to write to, finishing.e=00:00:51.33 bitrate=746496.0kbits/s speed=0.486x      33272.3kbits/s speed=0.886x
2020-03-15T20:35:55.107274375Z frame=  770 fps=7.3 q=-0.0 Lsize= 4677750kB time=00:00:51.33 bitrate=746496.0kbits/s speed=0.486x
2020-03-15T20:35:55.107436181Z video:4677750kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
2020-03-15T20:35:55.107530440Z Input file #0 (rtsp://user:[email protected]/live):
2020-03-15T20:35:55.107614815Z   Input stream #0:0 (video): 778 packets read (8565834 bytes); 770 frames decoded;
2020-03-15T20:35:55.107687857Z   Input stream #0:1 (audio): 363 packets read (387200 bytes);
2020-03-15T20:35:55.107874657Z   Total: 1141 packets (8953034 bytes) demuxed
2020-03-15T20:35:55.107947289Z Output file #0 (pipe:):
2020-03-15T20:35:55.108008064Z   Output stream #0:0 (video): 770 frames encoded; 770 packets muxed (4790016000 bytes);
2020-03-15T20:35:55.108073424Z   Total: 770 packets (4790016000 bytes) muxed
2020-03-15T20:35:55.118329529Z driveway: ffmpeg didnt return a frame. something is wrong.
2020-03-15T20:35:55.118565588Z driveway: ffmpeg didnt return a frame. something is wrong.
2020-03-15T20:35:55.118658687Z driveway: ffmpeg process is not running. exiting capture thread...
2020-03-15T20:35:57.864950332Z Creating ffmpeg process...