Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FFmpeg presets for Rockchip boards #1203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarcA711
Copy link

see #979

  • This is based on this ffmpeg fork from nyanmisaka. If you use other ffmpeg forks with rockchip hardware support, these presets will likely not work.
  • I provide up to date static builds. You can just download the binary and execute is using ./ffmpeg .... No need to install any libraries or dependencies. You need to run linux with up to date kernel drivers though. I recommend ubuntu-rockchip if your board is supported.
  • supports transcoding and rescaling
  • I added :force_original_aspect_ratio=0 to the scale command to allow rescaling. No other preset does this afaik, but I know that some frigate users want to change their aspect ratio
  • Rockchip hardware supports lots of other filters. I hope to add them as well if I have some time.

@MarcA711
Copy link
Author

@AlexxIT I know you are not able to test these changes. Is there some way we can still implement them?

@AlexxIT
Copy link
Owner

AlexxIT commented Jun 26, 2024

I'm busy for the next two weeks

@bugui2007
Copy link

bugui2007 commented Jul 29, 2024

Hello all,
@MarcA711, Im using a Orange Pi 5 Plus, and I set the following configuration over go2rtc-ffmpeg config section.

go2rtc:
  ffmpeg:
    input: -fflags nobuffer -flags low_delay -timeout 5000000 -i {input}
    h264/rk: -vf scale_rkrga=w={XXX}:h={XXX}:force_original_aspect_ratio=0 -c:v h264_rkmpp -g 50 -bf 0 -profile:v high -level:v 4.1 -an -vf "transpose=1,transpose=1" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`
    h265/rk: -vf scale_rkrga=w={XXX}:h={XXX}:force_original_aspect_ratio=0 -c:v hevc_rkmpp -g 50 -bf 0 -profile:v main -level:v 5.1 -an -vf "transpose=1,transpose=1" -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}`
    h264/rkmpp: -c:v h264_rkmpp -g 50 -bf 0 -profile:v high -level:v 4.1
    h265/rkmpp: -c:v hevc_rkmpp -g 50 -bf 0 -profile:v main -level:v 5.1

Even with this I didnt note any inprovement on decoding or encoding on hw for go2rtc...but frigate is using rkrga without problems.

Every 1.0s: cat /sys/kernel/debug/rkrga/load                                                                                                                                                                 osiris: Mon Jul 29 18:50:58 2024

num of scheduler = 3
================= load ==================
scheduler[0]: rga3
         load = 0%
-----------------------------------
scheduler[1]: rga3
         load = 0%
-----------------------------------
scheduler[2]: rga2
         load = 2%
-----------------------------------
         process 8: pid = 36993, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:85
54/FrenteIzquierda_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:
         process 9: pid = 37058, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:85
54/Cocina_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:
         process 10: pid = 37048, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:8
554/Altillo_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:
         process 12: pid = 36999, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:8
554/Frente_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:
         process 13: pid = 37035, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:8
554/Living_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:
         process 14: pid = 37010, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:8
554/FrenteDerecha_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:
         process 15: pid = 344434, name: ffmpeg -hide_banner -loglevel warning -threads 2 -hwaccel rkmpp -hwaccel_output_format drm_prime -user_agent FFmpeg Frigate/0.14.0-a4eb435 -rtsp_transport tcp -timeout 5000000 -i rtsp://127.0.0.1:
8554/Patio_sub -r 5 -vf scale_rkrga=w=640:h=480:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p -threads 2 -f rawvideo -pix_fmt yuv420p pipe:

Is there any way to force Go2RTC to use HW for decoding and encoding ? How can I debug it?

Another comment:
On the commit #1154 file internal/ffmpeg/hardware/hardware_unix.go @skrashevichskrashevich is using "h264_rkmpp_encoder" and "hevc_rkmpp_encoder" instead "h264_rkmpp" and "hevc_rkmpp", that you propose in your commit in this issue.

Best regards,
Thanks
Hernan

@MarcA711
Copy link
Author

Hey @bugui2007,

do you have a section like:

go2rtc:
  streams:

You are just defining some presets. Do you use them when defining your streams? Do you see any video from go2rtc?

If you do this correctly, you force go2rtc to use hw accel. It won't fallback to software. Either it works and uses hardware or it will crash. You can use ps -ef | grep ffmpeg. This will show all ffmpeg processes and the options. For example this process uses hw accel (can be seen from the bold parts):

ffmpeg -hide_banner -allowed_media_types video+audio -fflags nobuffer -flags low_delay -timeout 5000000 -rtsp_flags prefer_tcp -hwaccel rkmpp -hwaccel_output_format drm_prime -afbc rga -i rtsp://xxx -c:v h264_rkmpp -g 50 -bf 0 -an -rtsp_transport tcp -f rtsp rtsp://xxx

h264_rkmpp_encoder and hevc_rkmpp_encoder where old optione from this ffmpeg fork: https://github.com/hbiyik/FFmpeg. This newer fork: https://github.com/nyanmisaka/ffmpeg-rockchip uses h264_rkmpp and hevc_rkmpp. The newer fork is the one that frigate uses.

Btw. you can use the exec command to start ffmpeg with custom commands. You don't need to mess with the presets:

go2rtc:
  streams:
    MyCam: exec:ffmpeg -hide_banner -allowed_media_types video+audio -fflags
      nobuffer -flags low_delay -timeout 5000000 -rtsp_flags prefer_tcp -hwaccel rkmpp
      -hwaccel_output_format drm_prime -afbc rga -i rtsp://xxx
      -c:v h264_rkmpp -g 50 -bf 0 -an -rtsp_transport tcp -f rtsp {{output}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants