blakeblackshear / frigate

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

Feature request: Rockchip media acceleration opportunity #12462

Open ShyneTurtle opened 3 months ago

ShyneTurtle commented 3 months ago

I'm currently setting up Frigate on a RK3588 NAS, and i've come accross an FFMPEG instance ran by frigate that didn't use the internal media processing hardware (very high cpu usage compared other video processing tasks running on the machine). I suggest using MPP and RGA to transcode and scale respectively, see: https://github.com/nyanmisaka/ffmpeg-rockchip/wiki/Video-Transcode (i belive this is the FFMPEG fork used by the rockchip version of frigate).

I would love to contribute this myself but i'm not familiar enough with the codebase ^^'

Code subject to change: https://github.com/blakeblackshear/frigate/blob/a4eb435f1a9f64cde8a84357ea186de9072364d8/frigate/output/camera.py#L32-L57 and: https://github.com/blakeblackshear/frigate/blob/5c90f7dce7b24069ecfaeedb4be3f4892f380963/frigate/output/birdseye.py#L135-L160

Version: blakeblackshear/frigate:0.14.0-beta4-rk

hawkeye217 commented 3 months ago

CC @MarcA711

ShyneTurtle commented 3 months ago

(I might add that while i run the official build i checked Marc's fork and theses lines are the same so the issue might also be present)

MarcA711 commented 3 months ago

@ShyneTurtle thank you for this suggestion. We should probably add HW acceleration for this as well.

@hawkeye217 @NickM-27 is there already some implementation for hw specific FFmpeg presets? For Birdseye there are presets, but it seems they aren't used: https://github.com/blakeblackshear/frigate/blob/5c90f7dce7b24069ecfaeedb4be3f4892f380963/frigate/ffmpeg_presets.py#L105-L117

NickM-27 commented 3 months ago

The birdseye presets are used https://github.com/blakeblackshear/frigate/blob/5c90f7dce7b24069ecfaeedb4be3f4892f380963/docker/main/rootfs/usr/local/go2rtc/create_config.py#L12

github-actions[bot] commented 2 months 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.

ShyneTurtle commented 2 months ago

This is annoying

MarcA711 commented 2 months ago

Sorry, I have this in mind but I didn't have time so far. I am currently very busy.

ShyneTurtle commented 2 months ago

Sorry, I have this in mind but I didn't have time so far. I am currently very busy.

Oh i was complaining about the bot, take your time bud ^^

a2nt commented 1 month ago

Looks like FFMpeg at the latest build ghcr.io/blakeblackshear/frigate:c17524b-rk doesn't support rkmpp anymore

MarcA711 commented 1 month ago

@a2nt Could you explain what you mean? I haven't tested this version yet, but it should use the same FFmpeg as before. Do you see any errors? What os are you using and what version (uname -a)?

NickM-27 commented 1 month ago

Yeah this is likely something with my PR, I will fix that.

a2nt commented 1 month ago

@a2nt Could you explain what you mean? I haven't tested this version yet, but it should use the same FFmpeg as before. Do you see any errors? What os are you using and what version (uname -a)?

well it's kinda simple ffmpeg is missing rkmpp

frigate  | 2024-09-17 13:31:10.295008656  [2024-09-17 13:31:10] ffmpeg.camera_1.detect         ERROR   : [vist#0:0/h264 @ 0xaaaad1f75c10] Unrecognized hwaccel: rkmpp.
frigate  | 2024-09-17 13:31:10.295387524  [2024-09-17 13:31:10] ffmpeg.camera_1.detect         ERROR   : [vist#0:0/h264 @ 0xaaaad1f75c10] Supported hwaccels: cuda drm opencl vulkan 

so following config doesn't work any more:

ffmpeg:
  hwaccel_args: preset-rk-h264 # or preset-rk-h265
  output_args:
    record: preset-record-generic-audio-aac # preset-record-generic-audio-copy

ghcr.io/blakeblackshear/frigate:6bf2708-rk still has this issue

NickM-27 commented 1 month ago

go to frigate/api/stats and paste a couple of the ffmpeg commands

a2nt commented 1 month ago

frigate/api/stats

{"cameras":{"camera_0":{"audio_dBFS":-40.7056,"audio_rms":302.1125,"camera_fps":0.0,"capture_pid":461,"detection_enabled":true,"detection_fps":0.0,"ffmpeg_pid":675,"pid":441,"process_fps":0.0,"skipped_fps":0.0},"camera_1":{"audio_dBFS":-56.2039,"audio_rms":50.729,"camera_fps":0.0,"capture_pid":482,"detection_enabled":true,"detection_fps":0.0,"ffmpeg_pid":676,"pid":443,"process_fps":0.0,"skipped_fps":0.0},"camera_2":{"audio_dBFS":-35.4331,"audio_rms":554.3671,"camera_fps":0.0,"capture_pid":499,"detection_enabled":true,"detection_fps":0.0,"ffmpeg_pid":679,"pid":445,"process_fps":0.0,"skipped_fps":0.0},"camera_3":{"audio_dBFS":-45.1974,"audio_rms":180.1268,"camera_fps":0.0,"capture_pid":503,"detection_enabled":true,"detection_fps":0.0,"ffmpeg_pid":678,"pid":452,"process_fps":0.0,"skipped_fps":0.0}},"cpu_usages":{"1":{"cmdline":"/package/admin/s6/command/s6-svscan -d4 -- /run/service","cpu":"0.0","cpu_average":"0","mem":"0.0"},"113":{"cmdline":"/usr/local/go2rtc/bin/go2rtc -config=/dev/shm/go2rtc.yaml","cpu":"8.9","cpu_average":"6","mem":"0.4"},"124":{"cmdline":"bash ./run.user chroma","cpu":"0.0","cpu_average":"0","mem":"0.0"},"136":{"cmdline":"bash ./run.user go2rtc-healthcheck","cpu":"0.0","cpu_average":"0","mem":"0.0"},"142":{"cmdline":"python3 -u -m frigate","cpu":"2.3","cpu_average":"13","mem":"3.9"},"15":{"cmdline":"s6-supervise s6-linux-init-shutdownd","cpu":"0.0","cpu_average":"0","mem":"0.0"},"152":{"cmdline":"nginx: master process nginx","cpu":"0.0","cpu_average":"0","mem":"0.2"},"16":{"cmdline":"/package/admin/s6-linux-init/command/s6-linux-init-shutdownd -c /run/s6/basedir -g 3000 -C -B","cpu":"0.0","cpu_average":"0","mem":"0.0"},"170":{"cmdline":"sleep 9999","cpu":"0.0","cpu_average":"0","mem":"0.0"},"181":{"cmdline":"nginx: worker process","cpu":"0.0","cpu_average":"0","mem":"0.1"},"182":{"cmdline":"nginx: worker process","cpu":"0.0","cpu_average":"0","mem":"0.1"},"183":{"cmdline":"nginx: worker process","cpu":"0.0","cpu_average":"0","mem":"0.1"},"184":{"cmdline":"nginx: worker process","cpu":"0.0","cpu_average":"0","mem":"0.1"},"185":{"cmdline":"nginx: cache manager process","cpu":"0.0","cpu_average":"0","mem":"0.1"},"186":{"cmdline":"nginx: cache loader process","cpu":"0.0","cpu_average":"0","mem":"0.1"},"24":{"cmdline":"s6-supervise chroma-log","cpu":"0.0","cpu_average":"0","mem":"0.0"},"25":{"cmdline":"s6-supervise nginx","cpu":"0.0","cpu_average":"0","mem":"0.0"},"26":{"cmdline":"s6-supervise certsync-log","cpu":"0.0","cpu_average":"0","mem":"0.0"},"27":{"cmdline":"s6-supervise frigate-log","cpu":"0.0","cpu_average":"0","mem":"0.0"},"28":{"cmdline":"s6-supervise chroma","cpu":"0.0","cpu_average":"0","mem":"0.0"},"29":{"cmdline":"s6-supervise certsync","cpu":"0.0","cpu_average":"0","mem":"0.0"},"30":{"cmdline":"s6-supervise s6rc-fdholder","cpu":"0.0","cpu_average":"0","mem":"0.0"},"31":{"cmdline":"s6-supervise s6rc-oneshot-runner","cpu":"0.0","cpu_average":"0","mem":"0.0"},"318":{"cmdline":"bash ./run.user certsync","cpu":"0.0","cpu_average":"0","mem":"0.0"},"32":{"cmdline":"s6-supervise nginx-log","cpu":"0.0","cpu_average":"0","mem":"0.0"},"33":{"cmdline":"s6-supervise frigate","cpu":"0.0","cpu_average":"0","mem":"0.0"},"34":{"cmdline":"s6-supervise go2rtc-healthcheck","cpu":"0.0","cpu_average":"0","mem":"0.0"},"345":{"cmdline":"sleep 60","cpu":"0.0","cpu_average":"0","mem":"0.0"},"35":{"cmdline":"s6-supervise go2rtc-log","cpu":"0.0","cpu_average":"0","mem":"0.0"},"36":{"cmdline":"s6-supervise go2rtc","cpu":"0.0","cpu_average":"0","mem":"0.0"},"376":{"cmdline":"frigate.logger ","cpu":"0.1","cpu_average":"0","mem":"1.9"},"378":{"cmdline":"frigate.recording_manager","cpu":"1.3","cpu_average":"0","mem":"2.2"},"387":{"cmdline":"frigate.review_segment_manager","cpu":"0.1","cpu_average":"0","mem":"2.2"},"407":{"cmdline":"/usr/bin/python3 -c from multiprocessing.resource_tracker import main;main(62)","cpu":"0.0","cpu_average":"0","mem":"0.1"},"408":{"cmdline":"frigate.detector.rknn","cpu":"0.0","cpu_average":"0","mem":"3.0"},"410":{"cmdline":"frigate.output ","cpu":"0.2","cpu_average":"0","mem":"2.4"},"415":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -threads 1 -f rawvideo -pix_fmt yuv420p -video_size 2880x1616 -i pipe: -threads 1 -f mpegts -s 1924x1080 -codec:v mpeg1video -q 1 -bf 0 pipe:","cpu":"0.0","cpu_average":"0","mem":"0.2"},"423":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -threads 1 -f rawvideo -pix_fmt yuv420p -video_size 2880x1616 -i pipe: -threads 1 -f mpegts -s 1924x1080 -codec:v mpeg1video -q 1 -bf 0 pipe:","cpu":"0.0","cpu_average":"0","mem":"0.2"},"441":{"cmdline":"frigate.process:camera_0","cpu":"0.1","cpu_average":"0","mem":"2.6"},"442":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -threads 1 -f rawvideo -pix_fmt yuv420p -video_size 2880x1616 -i pipe: -threads 1 -f mpegts -s 1924x1080 -codec:v mpeg1video -q 1 -bf 0 pipe:","cpu":"0.0","cpu_average":"0","mem":"0.2"},"443":{"cmdline":"frigate.process:camera_1","cpu":"0.0","cpu_average":"0","mem":"2.6"},"445":{"cmdline":"frigate.process:camera_2","cpu":"0.0","cpu_average":"0","mem":"2.6"},"452":{"cmdline":"frigate.process:camera_3","cpu":"0.0","cpu_average":"0","mem":"2.6"},"458":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -threads 1 -f rawvideo -pix_fmt yuv420p -video_size 2880x1616 -i pipe: -threads 1 -f mpegts -s 1924x1080 -codec:v mpeg1video -q 1 -bf 0 pipe:","cpu":"0.0","cpu_average":"0","mem":"0.2"},"461":{"cmdline":"frigate.capture:camera_0","cpu":"0.3","cpu_average":"0","mem":"2.6"},"47":{"cmdline":"/package/admin/s6-2.11.3.2/command/s6-fdholderd -1 -i data/rules","cpu":"0.0","cpu_average":"0","mem":"0.0"},"48":{"cmdline":"/package/admin/s6/command/s6-ipcserverd -1 -- /package/admin/s6/command/s6-ipcserver-access -v0 -E -l0 -i data/rules -- /package/admin/s6/command/s6-sudod -t 30000 -- /package/admin/s6-rc/command/s6-rc-oneshot-run -l ../.. --","cpu":"0.0","cpu_average":"0","mem":"0.0"},"482":{"cmdline":"frigate.capture:camera_1","cpu":"0.2","cpu_average":"0","mem":"2.6"},"487":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -threads 1 -f rawvideo -pix_fmt yuv420p -video_size 2880x1616 -i pipe: -threads 1 -f mpegts -s 2880x1616 -codec:v mpeg1video -q 1 -bf 0 pipe:","cpu":"0.0","cpu_average":"0","mem":"0.2"},"499":{"cmdline":"frigate.capture:camera_2","cpu":"0.2","cpu_average":"0","mem":"2.6"},"503":{"cmdline":"frigate.capture:camera_3","cpu":"0.2","cpu_average":"0","mem":"2.6"},"506":{"cmdline":"frigate.audio_manager","cpu":"5.7","cpu_average":"4","mem":"3.1"},"532":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -vn -threads 1 -hide_banner -loglevel warning -threads 2 -user_agent FFmpeg Frigate/0.15.0-6bf2708 -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://127.0.0.1:8554/camera_0 -threads 1 -f s16le -ar 16000 -ac 1 -y pipe:","cpu":"1.1","cpu_average":"0","mem":"0.3"},"541":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -vn -threads 1 -hide_banner -loglevel warning -threads 2 -user_agent FFmpeg Frigate/0.15.0-6bf2708 -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://127.0.0.1:8554/camera_1 -threads 1 -f s16le -ar 16000 -ac 1 -y pipe:","cpu":"0.7","cpu_average":"0","mem":"0.3"},"550":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -vn -threads 1 -hide_banner -loglevel warning -threads 2 -user_agent FFmpeg Frigate/0.15.0-6bf2708 -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://127.0.0.1:8554/camera_2 -threads 1 -f s16le -ar 16000 -ac 1 -y pipe:","cpu":"0.8","cpu_average":"0","mem":"0.3"},"564":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -vn -threads 1 -hide_banner -loglevel warning -threads 2 -user_agent FFmpeg Frigate/0.15.0-6bf2708 -avoid_negative_ts make_zero -fflags +genpts+discardcorrupt -rtsp_transport tcp -timeout 5000000 -use_wallclock_as_timestamps 1 -i rtsp://127.0.0.1:8554/camera_3 -threads 1 -f s16le -ar 16000 -ac 1 -y pipe:","cpu":"0.8","cpu_average":"0","mem":"0.3"},"565":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/camera_3?audio -c:a aac -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/812492e8ee59028ffc65f5c9bc229266","cpu":"6.1","cpu_average":"4","mem":"0.2"},"582":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/camera_2?audio -c:a aac -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/633bef5802a6851d0ca63272e0e75e2c","cpu":"5.8","cpu_average":"4","mem":"0.2"},"594":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/camera_1?audio -c:a aac -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/9b874ddd2ed27a93383e5cd574f84154","cpu":"6.0","cpu_average":"4","mem":"0.2"},"597":{"cmdline":"/usr/lib/ffmpeg/6.0/bin/ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/camera_0?audio -c:a aac -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/1d3c7980cbd14f596828ec70aa8da4a0","cpu":"6.2","cpu_average":"4","mem":"0.2"},"661":{"cmdline":"sleep 30s","cpu":"0.0","cpu_average":"0","mem":"0.0"},"89":{"cmdline":"s6-log -b -- T 1 n0 s10000000 T /dev/shm/logs/go2rtc","cpu":"0.0","cpu_average":"0","mem":"0.0"},"90":{"cmdline":"s6-log -b -- T 1 n0 s10000000 T /dev/shm/logs/nginx","cpu":"0.0","cpu_average":"0","mem":"0.0"},"93":{"cmdline":"s6-log -b -- T 1 n0 s10000000 T /dev/shm/logs/frigate","cpu":"0.0","cpu_average":"0","mem":"0.0"},"95":{"cmdline":"s6-log -b -- T 1 n0 s10000000 T /dev/shm/logs/certsync","cpu":"0.0","cpu_average":"0","mem":"0.0"},"97":{"cmdline":"s6-log -b -- T 1 n0 s10000000 T /dev/shm/logs/chroma","cpu":"0.0","cpu_average":"0","mem":"0.0"},"frigate.full_system":{"cpu":"0.0","mem":"21.7"}},"detection_fps":0.0,"detectors":{"rknn":{"detection_start":0.0,"inference_speed":10.0,"pid":408}},"processes":{"audio_detector":{"pid":506},"go2rtc":{"pid":113},"logger":{"pid":376},"recording":{"pid":378},"review_segment":{"pid":387}},"service":{"last_updated":1726576102,"latest_version":"0.14.1","storage":{"/dev/shm":{"free":510.9,"mount_type":"tmpfs","total":512.0,"used":1.1},"/media/frigate/clips":{"free":81485.6,"mount_type":"btrfs","total":95367.0,"used":11866.2},"/media/frigate/recordings":{"free":81485.6,"mount_type":"btrfs","total":95367.0,"used":11866.2},"/tmp/cache":{"free":2048.0,"mount_type":"tmpfs","total":2048.0,"used":0.0}},"temperatures":{},"uptime":25,"version":"0.15.0-6bf2708"}}

a2nt commented 1 month ago

go to frigate/api/stats and paste a couple of the ffmpeg commands

Actually weird question it can be checked easily.

Older version 0.14 supports rkmpp:

docker exec -it frigate bash
root@127:/opt/frigate# ffmpeg -hide_banner -hwaccels
Hardware acceleration methods:
cuda
drm
opencl
vulkan
rkmpp

while 0.15-0 does not:

root@127:/opt/frigate# /usr/lib/ffmpeg/6.0/bin/ffmpeg -hide_banner -hwaccels
Hardware acceleration methods:
cuda
drm
opencl
vulkan
NickM-27 commented 1 month ago

if you set the path to "ffmpeg" it will work. But the question is why which is not finding ffmpeg.

It would be really helpful if you could run

python3
import shutil
shutil.which("ffmpeg")
a2nt commented 1 month ago

hmm it shows nothing image

if you set the path to "ffmpeg" it will work. But the question is why which is not finding ffmpeg.

It would be really helpful if you could run

python3
import shutil
shutil.which("ffmpeg")
NickM-27 commented 1 month ago

oh that's my fault, I made an incorrect assumption, will fix in a PR

a2nt commented 1 month ago

if you set the path to "ffmpeg" it will work. But the question is why which is not finding ffmpeg.

It would be really helpful if you could run

python3
import shutil
shutil.which("ffmpeg")

looks like need to add /usr/lib/ffmpeg to $PATH or link ffmpeg to /usr/bin or smth like that image