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
Add static FFmpeg with rockchip hardware acceleration to rk- image #8599
Conversation
✅ Deploy Preview for frigate-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I added ffmpeg presets for hw accel.
|
looks good to me |
I added the presets and updated the docs. On my system, everything runs very well. I guess this PR is ready to merge. One note and one question:
|
on your concerns:
|
Yes, h265 is perhaps easier for less technical experienced users. Thank you very much for your explanation and your review. |
Added one small change, since I forgot to update the usage info after copy pasting... |
@MarcA711 maybe I'm missing something... Am I supposed to add
as global and then use hwaccel_args: preset-rk-h264 on the camera that's 264? |
you can do it any which way, camera config overrides the global config. It can be cleaner in the config to set it globally and then only override for the cameras that don't match like you described. the rknn detector is already outlined in the docs |
I was referring to the hardware scaling of the output image that the detector uses, not rknn detector itself. How do I define the rockchip preset there? From the code I see that it uses hevc_rkmpp_encoder which is basically '-c:v hevc_rkmpp_encoder -preset {1}). what is 1? How do I specify the 264 hwaccel for detect? |
I think you are misunderstanding something, detection is run on decoded stream which is exactly what the hwaccel_args are used for |
also, the presets used in the config are a frigate specific construct and not something built in to ffmpeg |
aah ok testing the presets now and will compare cpu usage. any chance to get annke c800 / hikvision clips in the event viewer? snapshots work fine. are there settings for clips that I can fiddle with? |
I'm not sure what you mean, my hikvision works fine for recordings and snapshots |
First benchmarks... Bugs... h264 decoder has an issue:
Which results in picture like this: Regarding clips, I can get the event clips for one specific camera played inside the chrome browser (ubiquiti g4 that's due to be replaced) but for the rest of the cameras (hikvision 4k and dahua 4k), they are not available: |
The rockchip preset does not implement hardware scaling, the scaling is done in software, so high CPU usage in that scenario is to be expected. I would definitely suggest running detect on a sub stream as for the recording issue, that may not be related to this at all, more info would be needed like frigate logs, nginx logs, and browser logs |
One note since hardware scaling was mentioned here: For some reason the rga is not used when decoding and scaling an image. So, if I decode my 4k h265 video and want to resize the raw frames to 2k resolution, the VPU does the decoding part, but the scaling part has to be done on the cpu not rga. After I finish the basic Rockchip implementation here, I want to find out why the rga is not used to scale decoded frames. Maybe the maintainer of the rockchip ffmpeg fork will implement it. However, you specifically asked for hardware acceleration of frames passed to the rknpu detector. I guess this is not worth since passing the frame to ffmpeg and then to the rga is probably slower than just doing it on the cpu. But even if it is a bit faster, the detection using the npu takes at least 20ms even using the smallest models. The time it takes to scale the frame on the cpu is probably negligible vs these 20 ms. But all the information here is vague, as I have not yet familiarized myself with the subject in depth. |
@great9 As I said in my last comment, I will update the docs about transcoding using go2rtc. With that, you can use the following workaround: transcode your 4k stream using go2rtc and use hardware scaling to scale down the stream to 1080p. But only do this, if you have to use this 4k stream. As Nick said, the much better solution is to provide a substream with lower resolution. |
great, will try that too.
I had some success with https://github.com/nyanmisaka/jellyfin-ffmpeg/commits/next-rockchip-async-afbc (ffmpeg compiled with "--enable-rkrga" and "--enable-rkmpp" He has two branches he's working on. Then there's @hbiyik who implemented the rkmpp encoder / decoder to ffmpeg 4.4, 5.0, 5.1 and now ffmpeg latest. He's been sharing some thoughts here/
I was wrong about "detect". I was under the impression that the "detect" config does scaling (based on the width, height parameters) and that it's being used with the CPU / VPU so that I can tune it. |
frigate will use ffmpeg to scale the detect input stream to the |
@MarcA711 is there something you are implementing or just updating the docs to mention go2rtc config? |
@great9 thank you for the links you provided, especially the jellyfin ffmpeg fork. I didn't know this so far. This can be helpful for implementing hw scaling without encoding in ffmpeg. As I said, with hbiyiks ffmpeg fork it seems that only hw scaling is supported in combination with encoding. @NickM-27 I would like to implement presets that can be used in the go2rtc way like this: ffmpeg:rtsp://rtsp:12345678@192.168.1.123/av_stream/ch0#input=rkh264dec#video=rkh264enc |
yes, that could be done in the create_config.py frigate/docker/main/rootfs/usr/local/go2rtc/create_config.py Lines 106 to 114 in 8c7f6d4
|
Awesome, this is exactly what I need. |
you forked MPP but did not include it in the rockchip makefile? seems to be missing |
I am not sure, what you mean. I forked mpp and did the following changes:
I guess you mean that the static rockchip_mpp.a lib contains just a part of the symbols. This is true, I used a workaround to build the lib: I used ar to combine all static libs that the original CMakeLists.txt from rockchip build. I plan to update my fork in the future, to directly build build a librockchip_mpp with all symbols. However, the mpp repo contains 50+ CMake files and I have to work through all of them. I didn't have time for this so far. This is low priority for me, since the librockchip_mpp.a that I build using my workaround is basically the same as if I wrote CMake files to directly build it. So if you want to build your own:
|
@MarcA711 can you add preset for birdseye a well please? |
Birdseye already uses the preset |
oh i see. But no matter what i do i keep getting these errors [h264_rkmpp_decoder @ 0xaaab1524bee0] Failed to initialize MPP context (code = -1). |
What is the docker compose? |
@faugconti |
Solved this issue switching from mainline kernel back to 5.10.160-rockchip (which already comes with MPP) after checking the Dockerfile. |
The problem is not a missing library. Everything necessary is implemented in the rk image. I guess you were using the mainline kernel from collabora. As you can see from their status matrix, only the av1 codec is implemented so far, so this kernel supports no h264 or h265/hevc de- or encoding. |
Limitations:
I hope to add the hw accel presets this evening, so others can test this PR.