blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
19.2k stars 1.76k forks source link

[Config Support]: RPi4 High CPU Usage #7918

Closed hatmeh80 closed 1 year ago

hatmeh80 commented 1 year ago

Describe the problem you are having

RPI4 93% CPU usage with detection off ? Any help why is this ?

Screenshot 2023-09-22 at 8 30 18 PM Screenshot 2023-09-22 at 8 31 13 PM Screenshot 2023-09-22 at 8 30 59 PM

P.S : Had 4 dahuha cameras one died, replaced it with hikvision then noticed the high cpu usage, dont know if this is related I disabled the new camera and it went down to 78%

I guess i have something wrong in the config ?

Version

0.12.1-367D724

Frigate config file

mqtt:
  host: 192.168.100.237
  user: mqttbroker
  password: *******
cameras:
  frontdoor:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/frontdoor
          roles:
            - detect
    detect:
      width: 1280
      height: 720

  camera2:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/camera2
          roles:
            - detect
    detect:
      width: 1280
      height: 720

  camera4:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/camera4
          roles:
            - detect
    detect:
          width: 1280
          height: 720

go2rtc:
  streams:
    frontdoor: rtsp://admin:Rori1411!@192.168.100.49:554/user=admin_password=******_channel=1_stream=0.sdp
    camera2: rtsp://admin:Rori1411!@192.168.100.49:554/user=admin_password=******_channel=2_stream=0.sdp
    camera4: rtsp://admin:Rori1411!@192.168.100.49:554/user=admin_password=******_channel=4_stream=0.sdp

snapshots:
  # Optional: Enable writing jpg snapshot to /media/frigate/clips (default: shown below)
  # This value can be set via MQTT and will be updated in startup based on retained value
  enabled: True
  # Optional: print a timestamp on the snapshots (default: shown below)
  timestamp: False
  # Optional: draw bounding box on the snapshots (default: shown below)
  bounding_box: True
  # Optional: crop the snapshot (default: shown below)
  crop: False
  # Optional: Restrict snapshots to objects that entered any of the listed zones (default: no required zones)
  required_zones: []
  # Optional: Camera override for retention settings (default: global values)
  retain:
    # Required: Default retention days (default: shown below)
    default: 10
    # Optional: Per object retention days
    objects:
      person: 15

motion:
  threshold: 20

Relevant log output

2023-09-22 17:41:42.564239386  [INFO] Starting Frigate...
2023-09-22 17:41:50.247712287  [2023-09-22 20:41:50] frigate.app                    INFO    : Starting Frigate (0.12.1-367d724)
2023-09-22 17:41:50.345337373  [2023-09-22 20:41:50] frigate.app                    INFO    : Creating directory: /tmp/cache
2023-09-22 17:41:50.354156636  [2023-09-22 20:41:50] peewee_migrate                 INFO    : Starting migrations
2023-09-22 17:41:50.377063395  [2023-09-22 20:41:50] peewee_migrate                 INFO    : There is nothing to migrate
2023-09-22 17:41:50.473690244  [2023-09-22 20:41:50] detector.cpu                   INFO    : Starting detection process: 299
2023-09-22 17:41:50.475626145  [2023-09-22 20:41:50] frigate.app                    INFO    : Output process started: 301
2023-09-22 17:41:50.541810035  [2023-09-22 20:41:50] frigate.app                    INFO    : Camera processor started for frontdoor: 305
2023-09-22 17:41:50.565479425  [2023-09-22 20:41:50] frigate.app                    INFO    : Camera processor started for camera2: 306
2023-09-22 17:41:50.584302499  [2023-09-22 20:41:50] frigate.app                    INFO    : Camera processor started for camera4: 308
2023-09-22 17:41:50.628718919  [2023-09-22 20:41:50] frigate.app                    INFO    : Capture process started for frontdoor: 309
2023-09-22 17:41:50.667345081  [2023-09-22 20:41:50] frigate.app                    INFO    : Capture process started for camera2: 313
2023-09-22 17:41:50.697916815  [2023-09-22 20:41:50] frigate.detectors              WARNING : CPU detectors are not recommended and should only be used for testing or for trial purposes.
2023-09-22 17:41:50.703920846  [2023-09-22 20:41:50] frigate.app                    INFO    : Capture process started for camera4: 315

Frigate stats

No response

Operating system

HassOS

Install method

HassOS Addon

Coral version

CPU (no coral)

Any other information that may be helpful

No response

NickM-27 commented 1 year ago

RPI4 93% CPU usage with detection off ? Any help why is this ?

because you are not using hardware acceleration and it is taxing the rpi to use the CPU to decode 4 streams

hatmeh80 commented 1 year ago

But i disabled the detecion in the UI

Screenshot 2023-09-22 at 8 53 37 PM
hatmeh80 commented 1 year ago

is there any where else to disable detection ?

NickM-27 commented 1 year ago

does not matter, the stream will always be decoded even when object detection is disabled. it is used for things like motion detection, camera snapshot api, etc.

hatmeh80 commented 1 year ago

Got it, ordered a coral and should be delivered in a couple of days. Will it help lowering the cpu usage ?

NickM-27 commented 1 year ago

it will not help with lowering the CPU usage that you see right now, you need to use hwaccel https://docs.frigate.video/configuration/hardware_acceleration#raspberry-pi-34

hatmeh80 commented 1 year ago

Should i add this to each stream in the frigate.yml ?

ffmpeg: hwaccel_args: preset-rpi-64-h264

NickM-27 commented 1 year ago

or you can just set it globally

hatmeh80 commented 1 year ago

Lol , Noob here , no idea how to set it globaly :)

NickM-27 commented 1 year ago

it just means not indented, you could do it like this

mqtt:
  host: 192.168.100.237
  user: mqttbroker
  password: *******

ffmpeg:
  hwaccel_args: preset-rpi-64-h264

cameras:
  frontdoor:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/frontdoor
          roles:
            - detect
    detect:
      width: 1280
      height: 720

  camera2:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/camera2
          roles:
            - detect
    detect:
      width: 1280
      height: 720

  camera4:
    ffmpeg:
      inputs:
        - path: rtsp://127.0.0.1:8554/camera4
          roles:
            - detect
    detect:
          width: 1280
          height: 720

go2rtc:
  streams:
    frontdoor: rtsp://admin:Rori1411!@192.168.100.49:554/user=admin_password=******_channel=1_stream=0.sdp
    camera2: rtsp://admin:Rori1411!@192.168.100.49:554/user=admin_password=******_channel=2_stream=0.sdp
    camera4: rtsp://admin:Rori1411!@192.168.100.49:554/user=admin_password=******_channel=4_stream=0.sdp

snapshots:
  # Optional: Enable writing jpg snapshot to /media/frigate/clips (default: shown below)
  # This value can be set via MQTT and will be updated in startup based on retained value
  enabled: True
  # Optional: print a timestamp on the snapshots (default: shown below)
  timestamp: False
  # Optional: draw bounding box on the snapshots (default: shown below)
  bounding_box: True
  # Optional: crop the snapshot (default: shown below)
  crop: False
  # Optional: Restrict snapshots to objects that entered any of the listed zones (default: no required zones)
  required_zones: []
  # Optional: Camera override for retention settings (default: global values)
  retain:
    # Required: Default retention days (default: shown below)
    default: 10
    # Optional: Per object retention days
    objects:
      person: 15

motion:
  threshold: 20
hatmeh80 commented 1 year ago

Got it, will try now

hatmeh80 commented 1 year ago

No luck , still at 95% , question does this choice in friaget card affect the cpu ?

Screenshot 2023-09-22 at 9 11 05 PM
NickM-27 commented 1 year ago

Not substantially. What are the resolutions of your cameras streams?

hatmeh80 commented 1 year ago
detect:
      width: 1280
      height: 720

This is the only place i find resolution relevant config

NickM-27 commented 1 year ago

No, I'm asking what the actual resolution of your camera streams are. You can use the ffprobe button in the frigate system page

hatmeh80 commented 1 year ago

its a 2MP dahua camera connected to a DVR

Screenshot 2023-09-22 at 9 17 35 PM
NickM-27 commented 1 year ago

It's recommended to use substreams. Right now you are telling the pi to scale down the main stream to 1280x720 which uses a lot of CPU.

hatmeh80 commented 1 year ago

So , what should i do exactly ? Use the lower stream and remove the below detect option ?

detect: width: 1280 height: 720

NickM-27 commented 1 year ago

use the sub stream and set

detect:
  width: 
  height:

to the actual resolution of that stream

hatmeh80 commented 1 year ago

Sorry for these noob question , how can i know the resolution of my 2MP camera ?

NickM-27 commented 1 year ago

I am not sure how when using a DVR

NickM-27 commented 1 year ago

other than using ffprobe, not sure why it gave you an error

hatmeh80 commented 1 year ago

hmm ok let me investigate

hatmeh80 commented 1 year ago

opened the substream in VLC and got this info , should i use this ?

detect:

Screenshot 2023-09-22 at 9 38 27 PM

width: 352 height: 288

Or Should i use :

detect: width: 288 height: 352

NickM-27 commented 1 year ago

for that camera it would be

detect:
  width: 352
  height: 288

I'd check each camera to see what it is. Also worth seeing if it supports a sub stream with resolution that is higher than that (usually see 640x480)

hatmeh80 commented 1 year ago

ok let me try

hatmeh80 commented 1 year ago

Dude , you are a genius ! cameras playing and CPU at 12%

The quality is not so great, what can i do to enhance it ?

NickM-27 commented 1 year ago

Increase the sub stream resolution on the DVR (if possible) or get cameras that work directly over IP and support better sub streams.

github-actions[bot] commented 1 year ago

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.