blakeblackshear / frigate

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

[Support]: ffmpeg high CPU usage since updating to beta6 #8761

Closed TyzzyT closed 9 months ago

TyzzyT commented 9 months ago

Describe the problem you are having

Since I updated from 0.13.0 beta 5 to 0.13.0 beta 6, my detection is not working anymore for one of the high-res camera's. The lower res camera is working fine.

It looks like a problem with ffmpeg. When using beta-6, the ffmpeg process is using 100.1% according to System dashboard and is having an FPS of 3.5 and after a while even lower (2.7), while I expect it to be 5 FPS. I'm using a high res stream for detection, which was working fine with beta-5. Even though CPU usage was high with beta 5 and before, it was always able to keep up with the stream speed. (~89% CPU, 5.2 FPS according to system dashboard) Also, when I look at the stream in Frigate UI the live viewing is working fine. When looking at the debug stream, it's 1 minute behind the live stream according to the timestamp. It looks like the CPU/ffmpeg is not able to keep up with the speed of the stream. I'm not sure what has changed between beta5 and beta6, but when switching back to beta-5 everything is working fine with the same config.

Version

0.13.0-614A36A

Frigate config file

mqtt:
  host: REDACTED
  user: REDACTED
  password: REDACTED

database:
  path: /config/frigate.db

# https://docs.frigate.video/configuration/detectors/
detectors:
  coral:
    type: edgetpu
    device: usb

model:
#  path: plus://REDACTED # 7-10-2023
  path: plus://REDACTED # 26-10-2023 1978 images, 7162 labels

# https://docs.frigate.video/configuration/birdseye
birdseye:
  enabled: false

# https://docs.frigate.video/configuration/index
timestamp_style:
  position: bl
  format: "%Y-%m-%d %H:%M:%S"
  effect: shadow

# https://docs.frigate.video/configuration/
ui:
  live_mode: mse
  time_format: 24hour
  date_style: full

# https://docs.frigate.video/guides/configuring_go2rtc
go2rtc:
  streams:
    # the first stream you list under go2rtc, is the stream that gets shown in HA. So start with substream, which is H264 and more compatible
    voortuin_sub:
      - rtsp://admin:REDACTED@REDACTED:554/cam/realmonitor?channel=1&subtype=1#backchannel=0
    voortuin_main:
      - rtsp://admin:REDACTED@REDACTED:554/cam/realmonitor?channel=1&subtype=0#backchannel=0
    tuindeur:
      - rtsp://REDACTED:554/live/ch00_1

# https://docs.frigate.video/configuration/cameras
cameras:
  voortuin:
    ffmpeg:
# https://docs.frigate.video/configuration/hardware_acceleration/
      hwaccel_args: preset-vaapi
      inputs:
        - path: rtsp://127.0.0.1:8554/voortuin_main?video&audio
          input_args: preset-rtsp-restream
          roles:
            - record
            - detect
            - audio
      output_args:
        record: preset-record-generic-audio-aac
    live:
      stream_name: voortuin_main
    detect:
      width: 2560
      height: 1920
      fps: 5
      max_disappeared: 50 # (50 frames = 10 seconds)
      stationary:
        interval: 50
        threshold: 10 # (10 frames = 2 seconds)
      annotation_offset: -800 # offset in milliseconds to fix bounding box on events page
# https://docs.frigate.video/configuration/record
    record:
      enabled: true
      retain:
        days: 10
        mode: all
      # sync_recordings: true # will delete recordings from DB that are not available on disk
      events:
        pre_capture: 15
        post_capture: 20
        retain:
          mode: active_objects
          default: 14
          objects:
            car: 14
# https://docs.frigate.video/configuration/snapshots
    snapshots:
      enabled: true
      clean_copy: true
      bounding_box: true
      retain:
        default: 14
      quality: 100
    motion:
      contour_area: 10 # 10 = high sensitivity, 30 = medium, 50 = low
      threshold: 30 # Increasing this value will make motion detection less sensitive and decreasing it will make motion detection more sensitive
      mask:
        - 2560,0,2560,635,1204,585,1133,723,1128,808,535,662,437,800,278,826,0,770,0,0 # air
    zones:
      voortuin_zone:
        coordinates: 0,1920,2560,1920,2189,1314,1438,1282,801,1228,0,1396
        # inertia means consecutive frames needed to consider object in zone
        inertia: 5 # (5 frames = 1 second)
        # filters of zone overwrite the filter of global en camera
        filters:
          person:
            threshold: 0.85
# https://docs.frigate.video/configuration/objects/
    objects:
      track:
        - person
        - face
        - car
        - license_plate
        - package
        - fedex
        - ups
        - amazon
        - cat
        - dog
      filters:
        person:
          min_area: 500
          max_area: 3000000
          min_ratio: 0.01
          max_ratio: 10
          min_score: 0.2
          threshold: 0.62
          mask:
            - 2560,0,2560,760,0,760,0,0 # air
        face:
          min_area: 0
          max_area: 2962500
          min_ratio: 0.2
          max_ratio: 4
          min_score: 0.5
          threshold: 0.75
        car:
          min_area: 175000
          max_area: 750000
          min_ratio: 1
          max_ratio: 3
          min_score: 0.5
          threshold: 0.7
          mask:
            - 2560,0,2560,760,0,760,0,0 # air
        license_plate:
          min_area: 1000
          max_area: 60000
          min_score: 0.5
          threshold: 0.7
          mask:
            - 2560,0,2560,760,0,760,0,0 # air
        package:
          min_area: 1000
          max_area: 3000000
          min_score: 0.4
          threshold: 0.6
        fedex:
          min_area: 1000
          max_area: 3000000
          min_score: 0.35
          threshold: 0.5
        ups:
          min_area: 1000
          max_area: 3000000
          min_score: 0.35
          threshold: 0.5
        amazon:
          min_area: 1000
          max_area: 3000000
          min_score: 0.35
          threshold: 0.5
        cat:
          min_area: 1000
          max_area: 60000
          min_ratio: 0.2
          max_ratio: 5
          min_score: 0.3
          threshold: 0.75
          mask:
            - 2560,0,2560,760,0,760,0,0 # air
        dog:
          min_area: 3000
          max_area: 75000
          min_ratio: 0.2
          max_ratio: 5
          min_score: 0.3
          threshold: 0.7
          mask:
            - 2560,0,2560,760,0,760,0,0 # air
# https://deploy-preview-6262--frigate-docs.netlify.app/configuration/audio_detectors
    audio:
      enabled: true
      # max_not_heard: 30
      min_volume: 200 # 200 high sensitivity, 500 medium, 1000 low
      # https://github.com/blakeblackshear/frigate/blob/dev/audio-labelmap.txt
      listen:
        - bark
        - cat
        - scream
        - speech
        - yell
        - laughter
        - whistling
      filters:
        bark:
          threshold: 0.9
        cat:
          threshold: 0.9
        speech:
          threshold: 0.85
        scream:
          threshold: 0.9
        yell:
          threshold: 0.9
        laughter:
          threshold: 0.9
        whistling:
          threshold: 0.9
    mqtt:
      bounding_box: false
      height: 500
      quality: 100
      required_zones:
        - voortuin_zone
    ui:
      order: 1
      dashboard: true

  tuindeur:
    ffmpeg:
# https://docs.frigate.video/configuration/hardware_acceleration/
      hwaccel_args: preset-vaapi
      inputs:
        - path: rtsp://127.0.0.1:8554/tuindeur
          input_args: preset-rtsp-restream-low-latency
          roles:
            - record
            - detect
      output_args:
        record: preset-record-generic
    detect:
      width: 1280
      height: 720
      fps: 5
      max_disappeared: 150 # 150 frames = 30 seconds
      annotation_offset: -400 # offset in milliseconds to fix bounding box on events page
# https://docs.frigate.video/configuration/record
    record:
      enabled: true
      retain:
        days: 7
        mode: motion
      # sync_recordings: true # will delete recordings from DB that are not available on disk
      events:
        pre_capture: 5
        post_capture: 10
        retain:
          mode: active_objects
          default: 7
# https://docs.frigate.video/configuration/snapshots
    snapshots:
      enabled: true
      clean_copy: true
      bounding_box: true
      retain:
        default: 7
      quality: 100
    motion:
      contour_area: 20 # 10 = high sensitivity, 30 = medium, 50 = low
      threshold: 40 # Increasing this value will make motion detection less sensitive and decreasing it will make motion detection more sensitive
      mask:
        - 489,46,913,21,914,50,1280,50,1280,0,0,0,0,194 # clock
# https://docs.frigate.video/configuration/objects/
    objects:
      track:
        - person
        - face
        - package
      filters:
        person:
          mask:
            - 489,46,913,21,914,50,1280,50,1280,0,0,0,0,194 # clock
          min_area: 20000
          max_area: 250000
          min_ratio: 0.1
          max_ratio: 7
          min_score: 0.7
          threshold: 0.9
        face:
          min_area: 100
          max_area: 250000
          min_ratio: 0.2
          max_ratio: 4
          min_score: 0.6
          threshold: 0.8
        package:
          mask:
            - 0,720,257,720,256,515,0,519
          min_area: 100
          max_area: 250000
          min_score: 0.6
          threshold: 0.8
    mqtt:
      bounding_box: false
      height: 500
      quality: 100
    ui:
      order: 2
      dashboard: true

Relevant log output

I couldn't find anything relevant

FFprobe output from your camera

Stream 0:
Return Code: 0

Video:

Codec: H.265 / HEVC (High Efficiency Video Coding)
Resolution: 2560x1920
FPS: 5/1

Audio:

Codec: AAC (Advanced Audio Coding)

Frigate stats

No response

Operating system

HassOS

Install method

HassOS Addon

Coral version

USB

Network connection

Wired

Camera make and model

Amcrest AD410

Any other information that may be helpful

Frigate is running within HA OS on a Dell Thin Client, with Intel J5005 CPU (4 core, 1.5 GHz) ewruiewhjurjwioadeiwjirowaf

NickM-27 commented 9 months ago

I would suggest trying the i965 driver instead of iHD

environment_vars:
  LIBVA_DRIVER_NAME: i965
TyzzyT commented 9 months ago

That makes a huge difference. CPU usage is down to 16.6% and ffmpeg is able to keep up with the stream. Thanks Nick!