blakeblackshear / frigate

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

[Config Support]: ffmpeg still runs a decode + fps + scale stream even though detect is disabled #4093

Closed bitnimble closed 2 years ago

bitnimble commented 2 years ago

Describe the problem you are having

I'm currently planning on using Frigate just for recording at night, no detection for now. As far as I can tell from the docs, the RTMP and record streams simply remux the existing h264 stream without any processing.

However, ffmpeg is still running with ~20% CPU usage (on an i3), and I suspect because it has the -r 5 -s 1280x720 command line args attached. My camera has a 15fps 1080p stream.

Is this intended? Since I have detect disabled, there's no reason for this low fps, scaled stream to be running at all? If intended, is there any way to reduce my CPU usage further then? I don't care about motion or object detection at all right now.

Version

0.11.1-2EADA21

Frigate config file

mqtt:
  host: localhost
  user: <redacted>
  password: <redacted>

ffmpeg: # I've tried both with and without this -- it does actually help since that scaling stream exists, but ideally I shouldn't need it at all because no decoding should be happening
  hwaccel_args: -c:v h264_cuvid

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

detect:
  enabled: False

birdseye:
  enabled: False

cameras:
  tapo_c200_living_room:
    ffmpeg:
      inputs:
        - path: rtsp://redacted:redacted@192.168.1.82/stream1
          roles:
            - record
            - rtmp

Relevant log output

FFmpeg full command line args:

ffmpeg -hide_banner -loglevel warning -c:v h264_cuvid -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://redacted:redacted@192.168.1.82/stream1 -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c copy -an /tmp/cache/tapo_c200_living_room-%Y%m%d%H%M%S.mp4 -c copy -f flv rtmp://127.0.0.1/live/tapo_c200_living_room -r 5 -s 1280x720 -f rawvideo -pix_fmt yuv420p pipe:

Frigate logs

[2022-10-15 17:59:55] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
Starting migrations
[2022-10-15 17:59:55] peewee_migrate                 INFO    : Starting migrations
There is nothing to migrate
[2022-10-15 17:59:55] peewee_migrate                 INFO    : There is nothing to migrate
[2022-10-15 17:59:55] frigate.mqtt                   INFO    : Turning off recordings for tapo_c200_living_room via mqtt
[2022-10-15 17:59:55] detector.cpu                   INFO    : Starting detection process: 216
[2022-10-15 17:59:55] frigate.edgetpu                WARNING : CPU detectors are not recommended and should only be used for testing or for trial purposes.
[2022-10-15 17:59:55] frigate.app                    INFO    : Output process started: 218
[2022-10-15 17:59:55] ws4py                          INFO    : Using epoll
[2022-10-15 17:59:55] frigate.app                    INFO    : Camera processor started for tapo_c200_living_room: 222
[2022-10-15 17:59:55] frigate.app                    INFO    : Capture process started for tapo_c200_living_room: 223
[2022-10-15 17:59:55] ws4py                          INFO    : Using epoll

Frigate stats

{
  "detection_fps": 0.0,
  "detectors": {
    "cpu": {
      "detection_start": 0.0,
      "inference_speed": 10.0,
      "pid": 217
    }
  },
  "service": {
    "latest_version": "0.11.1",
    "storage": {
      "/dev/shm": {
        "free": 65.4,
        "mount_type": "tmpfs",
        "total": 67.1,
        "used": 1.7
      },
      "/media/frigate/clips": {
        "free": 11399867.7,
        "mount_type": "zfs",
        "total": 11399868.7,
        "used": 1.0
      },
      "/media/frigate/recordings": {
        "free": 11399867.7,
        "mount_type": "zfs",
        "total": 11399868.7,
        "used": 1.0
      },
      "/tmp/cache": {
        "free": 999.2,
        "mount_type": "tmpfs",
        "total": 1000.0,
        "used": 0.8
      }
    },
    "temperatures": {},
    "uptime": 12133,
    "version": "0.11.1-2eada21"
  },
  "tapo_c200_living_room": {
    "camera_fps": 5.0,
    "capture_pid": 222,
    "detection_fps": 0.0,
    "pid": 221,
    "process_fps": 5.0,
    "skipped_fps": 0.0
  }
}

Operating system

Other Linux

Install method

Docker Compose

Coral version

CPU (no coral)

Any other information that may be helpful

No response

bitnimble commented 2 years ago

I added width, height and fps config options to the detect section:

detect:
  width: 1920
  height: 1080
  fps: 15
  enabled: False

and yep, it changes to -r 15 -s 1920x1080 -- so those options are definitely coming from the detect config, even though detect is disabled.

Although unfortunately it looks like ffmpeg doesn't care that the res + fps is the same as the incoming stream, the CPU usage is the same, 20-30% :'(

edit: actually, it looks like the CPU usage went up, lmao, I guess because a 1080p output is more intensive even though it shouldn't be encoding...

I'll try to confirm which arguments are causing the high cpu usage, it's entirely possible that it's not the fps + scale at all, and just the remux alone is heavy.

bitnimble commented 2 years ago

It looks like the detect stream is created because of these lines: https://github.com/blakeblackshear/frigate/blob/7c60753ab0a376efdbd834d3cd3900cc029e5158/frigate/config.py#L583-L585

Is it mandatory that record/rtmp/detect streams all run? I did notice that the ffmpeg process is guarded by a "detect" role check: https://github.com/blakeblackshear/frigate/blob/7c60753ab0a376efdbd834d3cd3900cc029e5158/frigate/config.py#L615

... but at the same time, it seems like the detect role is required: https://github.com/blakeblackshear/frigate/blob/7c60753ab0a376efdbd834d3cd3900cc029e5158/frigate/config.py#L435-L436

Surely I can't be the only one that wants to use Frigate for recording + rtmp, etc without needing detection? If that's the case, do you know if there would be any issues with me just commenting those lines out on my instance? Are there other areas of the code that require / expect the detect stream to be running?

bitnimble commented 2 years ago

ah, I just stumbled upon https://github.com/blakeblackshear/frigate/issues/1911#issuecomment-1153218796 :) Glad to see that it's something already known, probably can close this ticket if it seems like a duplicate of that request.

blakeblackshear commented 2 years ago

This is a duplicate. Currently frigate does not function without at least one stream being decoded since the live view and the rest of the UI depend on it. Some have set the detect stream to a solid black small frame to minimize CPU load. That's what you will see in the UI, but recordings will work.

bitnimble commented 2 years ago

Perfect, thanks for the confirmation. Would be lovely to have this option supported first-class in the future but this workaround is good enough for me :)

For future readers, you can get the 2x2 black square video here: https://github.com/blakeblackshear/frigate/issues/1911#issuecomment-1182952523

vivekkairi commented 6 months ago

Hey @bitnimble

Can you share the config after the black.mp4 change? I need to record without detect but can't seem to get it working