frigate icon indicating copy to clipboard operation
frigate copied to clipboard

[Support]: ffmpeg retry delay

Open brickman7713 opened this issue 1 year ago • 8 comments

Describe the problem you are having

I am running Frigate in Docker with 5 cameras that stream consistently, but I would also like to record video from my Ring doorbell when it sees motion. I have set up RTSP streaming from the doorbell using the Ring-MQTT with Video Streaming addon in HomeAssistant, and I have it streaming to a server running an RTSP proxy. I would stream the video directly from the doorbell to Frigate, but the doorbell battery would die within a couple of hours, so to save battery I have HomeAssistant start the RTSP proxy when Ring.com tells HA that it sees motion. Everything is working, but there is a 10-15 second delay from the time the RTSP proxy starts to the time the Frigate picks up the stream. So my question... is there any way to decrease the retry time that Frigate will try connecting to a camera? I assume this will lead to more server resources being used by Frigate, but my server is only using about 50% ram and CPU currently so I don't think it will affect me. I included the startup logs from Docker, and 4 cycles of Frigate trying to connect to the doorbell (which wasn't streaming at the time). Also included my config general and Doorbell camera config.

Version

0.11.1-2EADA21

Frigate config file

#General Config
logger:
  default: error

mqtt:
  host: redacted 
  user: redacted 
  password: "redacted"

objects:
  track:
    - person
    - cat

ffmpeg:
  output_args:
    detect: -f rawvideo -pix_fmt yuv420p
    record: -f segment -segment_time 60 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c copy -an
    rtmp: -c copy -f flv

birdseye:
  enabled: True
  width: 1920
  height: 1080
  quality: 8
  mode: continuous

timestamp_style:
  position: "tl"
  format: "%m/%d/%Y %H:%M:%S"
  color:
    red: 255
    green: 255
    blue: 255
  thickness: 2
  effect: "solid"

#Camera configs
cameras:

#Doorbell
  Doorbell:
    ffmpeg:
      inputs:
        - path: rtsp://100.122.121.18:8555/proxied
          roles:
            - detect
            - rtmp
            - record
    rtmp:
      enabled: False
    detect:
      enabled: True
      width: 1920
      height: 1080
      fps: 10
    record:
      enabled: True
      expire_interval: 60
      retain:
        days: 2
        mode: all
    ui:
      order: 50

Relevant log output

frigate  | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
frigate  | [s6-init] ensuring user provided files have correct perms...exited 0.
frigate  | [fix-attrs.d] applying ownership & permissions fixes...
frigate  | [fix-attrs.d] done.
frigate  | [cont-init.d] executing container initialization scripts...
frigate  | [cont-init.d] done.
frigate  | [services.d] starting services
frigate  | [services.d] done.
frigate  | [2022-11-20 19:41:54] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
frigate  | Starting migrations
frigate  | [2022-11-20 19:41:54] peewee_migrate                 INFO    : Starting migrations
frigate  | There is nothing to migrate
frigate  | [2022-11-20 19:41:54] peewee_migrate                 INFO    : There is nothing to migrate
frigate  | [2022-11-20 19:41:55] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:41:55] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...
frigate  | [2022-11-20 19:42:15] watchdog.Doorbell              ERROR   : Ffmpeg process crashed unexpectedly for Doorbell.
frigate  | [2022-11-20 19:42:15] watchdog.Doorbell              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
frigate  | [2022-11-20 19:42:15] ffmpeg.Doorbell.detect         ERROR   : [tcp @ 0x55e336d650c0] Connection to tcp://100.122.121.18:8555?timeout=5000000 failed: Connection refused
frigate  | [2022-11-20 19:42:15] ffmpeg.Doorbell.detect         ERROR   : rtsp://100.122.121.18:8555/proxied: Connection refused
frigate  | [2022-11-20 19:42:15] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:42:15] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...
frigate  | [2022-11-20 19:42:25] watchdog.Doorbell              ERROR   : Ffmpeg process crashed unexpectedly for Doorbell.
frigate  | [2022-11-20 19:42:25] watchdog.Doorbell              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
frigate  | [2022-11-20 19:42:25] ffmpeg.Doorbell.detect         ERROR   : [tcp @ 0x5559ace650c0] Connection to tcp://100.122.121.18:8555?timeout=5000000 failed: Connection refused
frigate  | [2022-11-20 19:42:25] ffmpeg.Doorbell.detect         ERROR   : rtsp://100.122.121.18:8555/proxied: Connection refused
frigate  | [2022-11-20 19:42:25] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:42:25] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...
frigate  | [2022-11-20 19:42:35] watchdog.Doorbell              ERROR   : Ffmpeg process crashed unexpectedly for Doorbell.
frigate  | [2022-11-20 19:42:35] watchdog.Doorbell              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
frigate  | [2022-11-20 19:42:35] ffmpeg.Doorbell.detect         ERROR   : [tcp @ 0x5632e04250c0] Connection to tcp://100.122.121.18:8555?timeout=5000000 failed: Connection refused
frigate  | [2022-11-20 19:42:35] ffmpeg.Doorbell.detect         ERROR   : rtsp://100.122.121.18:8555/proxied: Connection refused
frigate  | [2022-11-20 19:42:35] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:42:35] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...
frigate  | [2022-11-20 19:42:45] watchdog.Doorbell              ERROR   : Ffmpeg process crashed unexpectedly for Doorbell.
frigate  | [2022-11-20 19:42:45] watchdog.Doorbell              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
frigate  | [2022-11-20 19:42:45] ffmpeg.Doorbell.detect         ERROR   : [tcp @ 0x5628236290c0] Connection to tcp://100.122.121.18:8555?timeout=5000000 failed: Connection refused
frigate  | [2022-11-20 19:42:45] ffmpeg.Doorbell.detect         ERROR   : rtsp://100.122.121.18:8555/proxied: Connection refused
frigate  | [2022-11-20 19:42:45] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:42:45] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...
frigate  | [2022-11-20 19:42:55] watchdog.Doorbell              ERROR   : Ffmpeg process crashed unexpectedly for Doorbell.
frigate  | [2022-11-20 19:42:55] watchdog.Doorbell              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
frigate  | [2022-11-20 19:42:55] ffmpeg.Doorbell.detect         ERROR   : [tcp @ 0x557bb46520c0] Connection to tcp://100.122.121.18:8555?timeout=5000000 failed: Connection refused
frigate  | [2022-11-20 19:42:55] ffmpeg.Doorbell.detect         ERROR   : rtsp://100.122.121.18:8555/proxied: Connection refused
frigate  | [2022-11-20 19:42:55] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:42:55] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...
frigate  | [2022-11-20 19:43:05] watchdog.Doorbell              ERROR   : Ffmpeg process crashed unexpectedly for Doorbell.
frigate  | [2022-11-20 19:43:05] watchdog.Doorbell              ERROR   : The following ffmpeg logs include the last 100 lines prior to exit.
frigate  | [2022-11-20 19:43:05] ffmpeg.Doorbell.detect         ERROR   : [tcp @ 0x55dcaa8c40c0] Connection to tcp://100.122.121.18:8555?timeout=5000000 failed: Connection refused
frigate  | [2022-11-20 19:43:05] ffmpeg.Doorbell.detect         ERROR   : rtsp://100.122.121.18:8555/proxied: Connection refused
frigate  | [2022-11-20 19:43:05] frigate.video                  ERROR   : Doorbell: Unable to read frames from ffmpeg process.
frigate  | [2022-11-20 19:43:05] frigate.video                  ERROR   : Doorbell: ffmpeg process is not running. exiting capture thread...

FFprobe output from your camera

Don't think this is needed, but I can include it if told otherwise.

Frigate stats

No response

Operating system

Debian

Install method

Docker Compose

Coral version

CPU (no coral)

Network connection

Mixed

Camera make and model

Ring Doorbell Gen 2

Any other information that may be helpful

No response

brickman7713 avatar Nov 21 '22 00:11 brickman7713

Frigate isn't meant to be used with cameras that don't support 24/7 RTSP. This is not a supported use case.

A requested feature https://github.com/blakeblackshear/frigate/issues/1911 may make this more doable, but in general I (personally) don't think battery cameras are going to be officially supported.

Similarly, the ring MQTT docs also say that it isn't meant to be used with frigate and other nvrs:

!!!! Important note regarding camera support !!!! The ring-mqtt project does not turn Ring cameras into 24x7/continuous streaming CCTV cameras. Ring cameras are designed to work with Ring cloud servers for on-demand streaming based on detected events (motion/ding) or interactive viewing, even when using ring-mqtt, all streaming still goes through Ring cloud servers and is not local. Attempting to leverage this project for continuous streaming is not a supported use case and attempts to do so will almost certainly end in disappointment, this includes use with NVR tools like Frigate, Zoneminder or others and there are significant functional side effects to doing so, most notably loss of motion/ding events while streaming (Ring cameras only send alerts when they are not actively streaming/recording). While you are of course welcome to use this project however you like, questions about use of such tools, or issues opened about these tools, will be locked and deleted.

NickM-27 avatar Nov 21 '22 01:11 NickM-27

Thanks for the quick response! And yeah I should have mentioned, I know these aren't meant to work together and I'm not expecting this to be a 100% full proof system. I guess my main goal of this thread is to figure out if Frigate determines the time between connection retries, or if that is done in the ffmpeg proccess?

brickman7713 avatar Nov 21 '22 01:11 brickman7713

It's done here https://github.com/blakeblackshear/frigate/blob/dev/frigate/video.py#L127

The delay is mostly going to be ffmpeg waiting for a stream from the source. There's not much delay between ffmpeg fail and starting it again.

NickM-27 avatar Nov 21 '22 01:11 NickM-27

On line 240 of that file I see time.sleep(10), so I forked the project and changed that to time.sleep(1), but there is still 10 seconds between every log results. Searching through the repository I found there is also a time.sleep(10) in the watchdog.py file, which I figured must be it, but that also did not change the fact that there is a 10 second delay between each error.

brickman7713 avatar Nov 21 '22 22:11 brickman7713

The wait here also adds 10 second delay https://github.com/blakeblackshear/frigate/blob/dev/frigate/video.py#L241

NickM-27 avatar Nov 22 '22 14:11 NickM-27

I noticed that too and changed it to 1 second but it also did not affect the delay between errors. These are the changes I have made.

frigate/video.py

...
 time.sleep(1)
        while not self.stop_event.wait(1):
...

frigate/watchdog.py

...
def run(self) -> None:
        time.sleep(1)
        while not self.stop_event.wait(1):
...

brickman7713 avatar Nov 22 '22 22:11 brickman7713

@brickman7713 confirmed it working on my end. Now I get errors every second if no motion is detected on the camera.

fliespl avatar Dec 05 '22 13:12 fliespl

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jan 05 '23 00:01 github-actions[bot]

Any updates on this?

Can a Ring Doorbell (battery) be used just to detect motion and record those clips?

b24home avatar Mar 18 '24 16:03 b24home