blakeblackshear / frigate

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

[Config Support]: High CPU usage with just recording enabled #6954

Closed hs82h closed 1 year ago

hs82h commented 1 year ago

Describe the problem you are having

I have Frigate running for some time and it runs fine. Now I got time I want to finetune it some more.

I noticed it uses quite a lot of cpu for an i7 processor. To test some things I disabled all except recording, because that's my highest prio. Still, the cpu didn't lower. I got 3 Foscam camera's with video resolution 1920x1080.

Is this cpu usage normal for just recording or can I change some config settings?

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 302198 root      20   0 1676944 115572  32624 S  48.3   0.5   0:03.51 ffmpeg
 301948 root      20   0 1677124 119812  32100 S  40.1   0.5   0:10.61 ffmpeg
 301944 root      20   0 1677876 119924  32120 S  37.7   0.5   0:10.67 ffmpeg
intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  454/ 454 MHz;   0% RC6;  0.97/ 3.99 W;      328 irqs/s

      IMC reads:     2450 MiB/s
     IMC writes:     1706 MiB/s

         ENGINES     BUSY                                                                                                                       MI_SEMA MI_WAIT
       Render/3D    8.02% |█████████▎                                                                                                         |      0%      0%
         Blitter    0.00% |                                                                                                                   |      0%      0%
           Video    5.56% |██████▌                                                                                                            |      0%      0%
    VideoEnhance    0.00% |                                                                                                                   |      0%      0%
intel-gpu-top: Intel Kabylake (Gen9) @ /dev/dri/card0 -  415/ 416 MHz;   0% RC6;  0.95/ 3.98 W;      318 irqs/s

      IMC reads:     2369 MiB/s
     IMC writes:     1657 MiB/s

         ENGINES     BUSY                                                                                                                       MI_SEMA MI_WAIT
       Render/3D    8.02% |█████████▎                                                                                                         |      0%      0%
         Blitter    0.00% |                                                                                                                   |      0%      0%
           Video    5.85% |██████▊                                                                                                            |      0%      0%
    VideoEnhance    0.00% |                                                                                                                   |      0%      0%

Version

0.11.1-2eada21

Frigate config file

database:
  path: /db/frigate.db

mqtt:
  host: u1.lan
  user: mosquitto
  password: ###

detectors:
  coral:
    type: edgetpu
    device: pci

ffmpeg:
  hwaccel_args: -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format yuv420p
  output_args:
    record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v copy -c:a aac

birdseye:
  enabled: False

detect:
  enabled: False

record:
  enabled: True
  retain:
    days: 10
    mode: all

cameras:
  d2ep:
    ffmpeg:
      inputs:
        - path: rtsp://view:###@192.168.20.13:88/videoMain
          roles:
            - record
  #          - rtmp

  fi9900p:
    ffmpeg:
      inputs:
        - path: rtsp://view:###@192.168.20.12:88/videoMain
          roles:
            - record
  #          - rtmp

  c2:
    ffmpeg:
      inputs:
        - path: rtsp://view:###@192.168.20.11:88/videoMain
          roles:
            - record
  #          - rtmp

Relevant log output

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[2023-06-29 15:56:29] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
Starting migrations
[2023-06-29 15:56:29] peewee_migrate                 INFO    : Starting migrations
There is nothing to migrate
[2023-06-29 15:56:29] peewee_migrate                 INFO    : There is nothing to migrate
[2023-06-29 15:56:29] detector.coral                 INFO    : Starting detection process: 223
[2023-06-29 15:56:29] frigate.app                    INFO    : Output process started: 224
[2023-06-29 15:56:29] ws4py                          INFO    : Using epoll
[2023-06-29 15:56:29] frigate.app                    INFO    : Camera processor started for d2ep: 230
[2023-06-29 15:56:29] frigate.app                    INFO    : Camera processor started for fi9900p: 234
[2023-06-29 15:56:29] frigate.app                    INFO    : Camera processor started for c2: 236
[2023-06-29 15:56:29] frigate.mqtt                   INFO    : Turning off recordings for c2 via mqtt
[2023-06-29 15:56:29] frigate.app                    INFO    : Capture process started for d2ep: 237
[2023-06-29 15:56:29] frigate.app                    INFO    : Capture process started for fi9900p: 245
[2023-06-29 15:56:29] frigate.edgetpu                INFO    : Attempting to load TPU as pci
[2023-06-29 15:56:29] frigate.app                    INFO    : Capture process started for c2: 258
[2023-06-29 15:56:29] frigate.edgetpu                INFO    : TPU found
[2023-06-29 15:56:29] ws4py                          INFO    : Using epoll
[2023-06-29 15:57:06] ws4py                          INFO    : Managing websocket [Local => 127.0.0.1:5002 | Remote => 127.0.0.1:40250]

Frigate stats

{"c2":{"camera_fps":5.1,"capture_pid":258,"detection_fps":0.0,"pid":236,"process_fps":5.1,"skipped_fps":0.0},"d2ep":{"camera_fps":5.0,"capture_pid":237,"detection_fps":0.0,"pid":230,"process_fps":5.0,"skipped_fps":0.0},"detection_fps":0.0,"detectors":{"coral":{"detection_start":0.0,"inference_speed":10.0,"pid":223}},"fi9900p":{"camera_fps":5.1,"capture_pid":245,"detection_fps":0.0,"pid":234,"process_fps":5.1,"skipped_fps":0.0},"service":{"latest_version":"0.12.1","storage":{"/dev/shm":{"free":129.5,"mount_type":"tmpfs","total":134.2,"used":4.7},"/media/frigate/clips":{"free":108346.3,"mount_type":"ext4","total":243885.9,"used":123076.4},"/media/frigate/recordings":{"free":108346.3,"mount_type":"ext4","total":243885.9,"used":123076.4},"/tmp/cache":{"free":997.1,"mount_type":"tmpfs","total":1000.0,"used":2.9}},"temperatures":{"apex_0":51.05},"uptime":59,"version":"0.11.1-2eada21"}}

Operating system

Other Linux

Install method

Docker Compose

Coral version

M.2

Any other information that may be helpful

No response

NickM-27 commented 1 year ago

Frigate will always run the detection stream, even if you disable object detection it still decodes the stream and that is what is using CPU, not recording.

This means that your config is currently taking the 1080p stream from your camera and resizing it down to 720p all on the CPU, which will naturally use a lot of CPU.

I would definitely suggest using preset-vaapi for hwaccel_args instead of manual args which will reduce the CPU usage considerably.

hs82h commented 1 year ago

Wow, you are fast! :)

Thanks, I will take a look into it and let know the result.

hs82h commented 1 year ago

I changed my config.yml:

ffmpeg:
  hwaccel_args: preset-vaapi

Unfortunately all my cams give a green screen. I also tried changing my docker compose file with the i965 var, but no luck either.

    environment:
      LIBVA_DRIVER_NAME: "i965"

my host vainfo:

error: XDG_RUNTIME_DIR not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.14.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_14
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.14 (libva 2.12.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 22.3.1 ()
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD

I can't run vainfo in my container...

docker exec -it frigate vainfo
OCI runtime exec failed: exec failed: unable to start container process: exec: "vainfo": executable file not found in $PATH: unknown

Not sure what this means...

NickM-27 commented 1 year ago

Sorry I just realized you are running 0.11 which is also an outdated version of frigate, I'd suggest using that config after updating to 0.12

hs82h commented 1 year ago

I upgraded to 0.12. I didn't notice the repository changed...

All is working now and cpu is about 4% per cam, so I happy this is solved.

Thanks very much!