-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Add Raspberry Pi 4 and 5 V4L2 Stateless HEVC Hardware Acceleration with FFmpeg #27453
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
base: 4.x
Are you sure you want to change the base?
Conversation
update switch return "" for encoders.
@MELSunny Thanks a lot for the contribution. Sounds very interesting. Do you know about Pi4 and previous generations? Are they supported too with the same API? Pi4 and Pi3 have at least h264 decoder and encoder. |
@asmorkalov Thanks for the feedback and interest! The current commit has only been tested and confirmed to work on the Raspberry Pi 5, with HEVC hardware decoding. As RPi5 only has an HEVC decoder. I do have a Raspberry Pi 4, and I'd be happy to investigate extending this support to it (for H.264) in the next couple of weeks. |
Great! I have Pi4 and Pi3 in my hands for test. I'll post results here, if get interesting results. |
Please add some notes how to setup Pi for this. |
@asmorkalov Here is the build notes:
Build OpenCV here is my console_logs
Create the test folder, video and script
Run the test file
Here is my results on RPi5 CPU VS hwaccel
|
Works with my Pi4. |
Hello @MELSunny Thanks a lot for the very useful contribution again! I made several experiments with my Pi 4 (8G) and outcome is very promising. Your example works with significant acceleration. Also the Pi4 and Pi 5 support h264 codec with the same API. FFmpeg for Pi supports it too, but your example fails to play it --hwaccel option. I transcoded you video with command:
ffplay on Pi Pi4 works well:
But the sample stops:
h264 is still very popular case for video and CI. It'll be great if you tune the PR and enable it too. |
@asmorkalov Thank you for your feedback. You are correct that the Raspberry Pi 4 and 5 share the same decoding/encoding API. However, their hardware media capabilities differ. The RPi 4's hardware supports both H.264/HEVC decoding and H.264 encoding. This allows for a complete hardware-accelerated transcoding pipeline using a command like:
In contrast, the RPi 5's hardware only supports HEVC decoding and lacks a hardware encoder.
I have only enabled and tested the RPi 5's decoder so far. For testing purpose, you could download various format of video from the link below |
@MELSunny Friendly reminder. I'm curious, if you do the patch on base of some example or paper? Could you share link, I'll try to help you. I need more context to go. |
This PR enables V4L2 stateless HEVC hardware acceleration for Raspberry Pi 5 within OpenCV's videoio module. It leverages FFmpeg's drm acceleration (FFmpeg API changes), significantly improving HEVC decoding performance on RPi5 for robotics and embedded vision applications.
I have a working proof-of-concept with local benchmarks showing clear gains.
Checklist Status:
Ready: License, branch (4.x), FFmpeg reference, and (linked) related issue (#27452).
Seeking Guidance: Need help with formal C++ performance/accuracy tests, opencv_extra integration, and full documentation/examples.
As a Python developer, I welcome C++ best practice feedback and assistance with testing setup.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.