-
Notifications
You must be signed in to change notification settings - Fork 89
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
HEVC/h265 support for GStreamer on Raspbery Pi 4B/400/5 #358
Comments
Just as a minor bit of information. I've nearly gotten ffmpeg working with uxplay - Currently the frames are all green for some reason but I'll iron that out soon. Main thing is though that the decoder block on the RPi 4 is capable of decoding the AirPlay H265 packets and it seems to run at a relatively good frame rate (hard to tell as the stream looks shocking). The relevant changes just needs to be pushed into gstreamer now. |
I have some RPI 5's and can dedicate one to testing too. Ideally we would rebuild the RPi ffmpeg from its code so printf statements could be inserted to follow how it connects to the drivers and to which drivers). Stateless v4l2 justs queues an encoded frame in the "OUTPUT" (from encoder) queue |
more info from jc-kinesim
|
current R Pi OS HEVC driver https://github.com/raspberrypi/linux/tree/rpi-6.6.y/drivers/staging/media/rpivid |
RPi-FFmpeg is quite easy to build, unfortunately it just takes quite a while (~30 minutes on a RPi 4 with a decent SD card). I expect that subsequent rebuilds with minor changes would be faster but I haven't tried. Just something worth mentioning is that the hardware decoder outputs a DRM-frame which doesn't seem to be supported by many graphics libraries. I originally used SDL and tried to copy the hardware frame via the CPU into main memory to then be converted to YUV and eventually output back onto the display however it seemed to make those green frames that I was talking about earlier. Instead I'm using a OpenGL instance now, as I'm relatively sure that it can directly render DRM-Prime frames without any conversion/copying. I just want to get a working prototype at the moment and test that it can decode relatively well (it seemed relatively stable with an iPhone 15 Pro, it was decent with an iPad pro and i'll test my macbook later once I've actually got it stably outputting frames (can force the full 3840x2160 output with that) to stress test it. |
Might have to give up with trying to get ffmpeg imported. Non-stop getting green-tinted frames from the decode and I can't seem to figure out what I'm doing wrong. Including ffmpeg into uxplay is relatively easy though (including adding hw-accelerated). Very frustrating |
I am trying to find out why gstreamer is not detecting the rpivid driver on a R Pi 5. The rpivid_hevc driver is loaded (see it in lsmod), the gstreamer libv4l2codec is correctly compiled and present (installed by gstreamer-1.0-plugins-bad) "gstreamer-inspect-1.0 v4l2codec" shows the drivers, but lists "0 features" which means that no v4l2 devices was detected. however, the v4l2 devices can be listed with "v4l2-ctl --list-devices" (v4l2-ctl is in the "v4l-utils" package, which is probably installed, if not, install with apt on R Pi OS) This shows that the rpivid kernel model (on R Pi OS) is connected to /dev/video19 on my system. (and /dev/media0) "v4l2-ctl -d19 -D" lists all its details, including that it is enabled. |
|
This is where the problem with gstreamer happens
its a place to start to see what is going wrong. |
I was reading somewhere that the output of the decoder is SAND8/SAND30... Maybe that's where the issue lies? |
The problem is much more basic than that:
|
HOORAY!!!! commenting out that test indeed allows the "v4l2slh265dec V4L2 Stateless H.265 Video Decoder" to be registered, and show up with "1 feature" in "gst-inspect-1.0 v4l2codec" |
And it works??? |
not yet, sorry v4l2slh265dec0 error Unsupported bitdepth/chroma format but it's a start...... |
(without UxPlay, just run gst-inspect-1.0) The rpivid driver is reporting valid formats in response to VIDIOC_G_FMT and VIDIOC_ENUM_FMT ioctl calls
|
|
|
Those are the SAND formats I was referencing earlier. (Post 12 of https://forums.raspberrypi.com/viewtopic.php?t=343593) |
OK! I'm guessing "sand" refers to the proprietary hevc decoding block hardware in R PI. Well I got to understand enough to discover that by myself! The "unsand" code in jc-kinesim's ffmped rpi-ffmpeg work is https://github.com/jc-kynesim/rpi-ffmpeg/blob/test/6.0.1/main/libavfilter/vf_unsand.c |
I have asked jc-kinesim whether this R Pi Foundation code (copyright date 2018) replaces or works with the older non-RPi vf_unsand.c jc-kynesim/rpi-ffmpeg#94 (comment) Its a LOT of code. Maybe too big to be accepted into gstreamer? I wonder if it could be accessed by checking whether libav locally contains this code or not. this is the commit in dec 2023 at rpi-ffmpeg. |
Its possible that UxPlay could offer a gstreamer patch that UxPlay users could use to rebuild libgstv4l2codecs.c This is how it supported gstreamer's v4l2 (stateful h264 decode) before I got fixes accepted into gstreamer. |
dependecies of RPI sand code #include "libavutil/frame.h" this might drag in a lot, should check if gstreamer-libav uses it. |
I doubt that you would want this as it's just adding unnecessary bloat on the project, however I've just gotten FFmpeg working in UxPlay and correctly decoding H.265 streams. Worst comes to worst that can be an alternative provision? |
well now at least we know what the issues are.
SAND pixelformats fourcc = NC12, NC30 are not supported in gstreamer-plugins-bad v4l2codecs |
vf_unsand .c |
some more into A response from @6by9 (R Pi engineer) to my post at jc-kynesim/rpi-ffmpeg#94 (comment)
I also posted on Gstreamer forum: |
some more activity: maybe some action at R Pi might get stirred up by my queries. |
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7355 |
@connorh315 more news, the R Pi HEVC driver has at last been submitted to the Linux kernel for review..... |
Now that UxPlay 1.70 supports HEVC/h265/4K video, this issue thread is for discussion of how to get the stateless Video4Linux2 HEVC driver(s) on Raspberry Pi 4B/400/5 working with the stateless V4l2 plugin in gstreamer1.0-plugins-bad
LibreELEC/Kodi have HEVC on these Pi's working using a modified ffmpeg created by R Pi engineers:
see jc-kynesim/rpi-ffmpeg#94 (comment)
and https://discourse.gstreamer.org/t/v4l2-stateless-api-support/3339
The gstreamer code is at https://gitlab.freedesktop.org/gstreamer/gstreamer/-/tree/main/subprojects/gst-plugins-bad/sys/v4l2codecs?ref_type=heads
see here for useful info from LibreELEC
https://wiki.libreelec.tv/hardware/raspberry-pi
if we can understand how to access the HEVC drivers on these R Pi models working with UxPlay , perhaps with a patch to gstreamer-plugins-bad, a pull request to gstreamer can be made (this was done in the past to get GPU Hardware H264 decoding on R Pi 4B and earlier working with UxPlay (with the stateful v4l2 plugin in gstreamer-plugins-good).
The stateless V$L2 API is described below: hopefully this is already mainly implemented by gstreamer
https://www.linuxtv.org/downloads/v4l-dvb-apis/userspace-api/v4l/dev-stateless-decoder.html
The text was updated successfully, but these errors were encountered: