blakeblackshear / frigate

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

[HW Accel Support]: High ffmpeg CPU usage using intel hw accel unless intel_gpu_top is running #6566

Closed reef-actor closed 1 year ago

reef-actor commented 1 year ago

Describe the problem you are having

I am using hwaccel_args: preset-vaapi on an intel J5005 cpu. The ffmpeg takes uses 15% cpu. However if I run the intel_gpu_top tool the cpu usage for the ffmpeg process immediately drops to around 5% (gpu top shows 5% use of the video engine). Higher cpu usage returns on closing the tool.

I am unsure if this is just an artifact in the measurement or does it suggest hw acceleration is not being properly used unless the tool is open?

Version

0.12.0-DA3E197

Frigate config file

# yaml-language-server: $schema=http://home:5000/api/config/schema

mqtt:
  host: home

ffmpeg:
  hwaccel_args: preset-vaapi

rtmp:
  enabled: false

snapshots:
  enabled: true
  clean_copy: true
  bounding_box: false
  crop: false

detectors:
  ov:
    type: openvino
    device: AUTO
    model:
      path: /openvino-model/ssdlite_mobilenet_v2.xml

model:
  width: 300
  height: 300
  input_tensor: nhwc
  input_pixel_format: bgr
  labelmap_path: /openvino-model/coco_91cl_bkgr.txt

cameras:
  drive:
    ffmpeg:
      inputs:
        - path: rtsp://cam/ch0_0.h264

    motion:
      mask:
        - 0,0,0,353,1920,129,1920,0

    detect:
      width: 1920
      height: 1080
      fps: 5

    mqtt:
      timestamp: false
      bounding_box: false
      crop: true
      quality: 85
      height: 500

docker-compose file or Docker CLI command

frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:stable
    shm_size: "128mb" # update for your cameras based on calculation above
    devices:
      - /dev/dri/renderD128
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./frigate/config.yml:/config/config.yml
      - ./frigate/media:/media/frigate
      - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
        target: /tmp/cache
        tmpfs:
          size: 1000000
    ports:
      - "5000:5000"
      - "1935:1935" # RTMP feeds

    environment:
      FRIGATE_RTSP_PASSWORD: "password"
      LIBVA_DRIVER_NAME: "i965"

Relevant log output

N/A

FFprobe output from your camera

ffprobe version 4.3.6-0+deb11u1 Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, rtsp, from 'rtsp://cam/ch0_0.h264':
  Metadata:
    title           : Session streamed by "rRTSPServer"
    comment         : ch0_0.h264
  Duration: N/A, start: 0.033333, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080, 30 fps, 30 tbr, 90k tbn, 180k tbc

Operating system

Debian

Install method

Docker Compose

Network connection

Wired

Camera make and model

YI Outdoor 1080p (9CUS)

Any other information that may be helpful

No response

NickM-27 commented 1 year ago

This is most likely a bug in the top output or the way top is being read, intel_gpu_top won't affect how much the CPU is working.

andre-pt commented 1 year ago

just a theory: the cpu percentage can increase due to the cpu scaling (cpu governor). if when idling with frigate running, the CPU might be running at let's say 800MHz, but when you run intel-gpu-top, it might increase to 1500MHz and then reduce the %, however it will draw more power.

you can check which governor is active:

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

you can try to set it to performance and check if the same happens

reef-actor commented 1 year ago

Thanks @NickM-27 @andre-pt , I suspect what I was seeing was indeed the cpu scaling impacting the percentages. Interestingly my ffmpeg usage is now about 8% after a reboot (first in >1yr) without the intel tool running 🤷