getting HEVC decoding working with LibreELEC patches

  • Hi everyone,

    I really appreciate all the RockChip work done here, but LibreELEC as a distribution does not fit my needs.

    Therefore I have created packages for my distribution with the LibreELEC patches and keep kernel+Kodi versions aligned with LibreELEC insofar the patches apply and work.

    Currently I am running LInux 6.2.2 (patches for 6.1.2 applied cleanly), Kodi 20.0, FFMPEG 4.4.1-Nexus-Alpha1 (LibreELEC patches which seem to be for 5.1.2 apply cleanly here too).

    I have most things working fine, except that I cannot seem to decode HEVC content which does work on LibreELEC when I checked last week.

    For the kernel, I have applied these patches:

    https://github.com/LibreELEC/Libr…s/linux/default
    For FFMPEG; I applied these patches:
    https://github.com/LibreELEC/Libr…s/v4l2-drmprime
    https://github.com/LibreELEC/Libr…es/v4l2-request

    My build scripts can be found here (the FFMPEG patches I integrated into Kodi's FFMPEG build as that is how my distro builds kodi):

    linux-rockchip-PKGBUILD/PKGBUILD at master · rubenvb/linux-rockchip-PKGBUILD
    PKGBUILD and patches for rk3399 linux build. Contribute to rubenvb/linux-rockchip-PKGBUILD development by creating an account on GitHub.
    github.com
    kodi-rockchip/PKGBUILD at master · rubenvb/kodi-rockchip
    PKGBUILD and related files for kodi on my rk3399. Contribute to rubenvb/kodi-rockchip development by creating an account on GitHub.
    github.com

    I have an old Kodi log of mine (Kodi 19.0 Alpha,FFMPEG 4.2.2, Linux 5.7.0) which shows the HEVC decoding working: kodi_working.log

    It goes on to probe the various devices, set up the pixel format yuv420p10le, and continue on its merry way.

    Currently, running the above patched binaries, I get the story in "kodi_broken.log"

    For some reason it can't set the format it wants on the v4l2 device.

    Note: this latter log is produced by trying to play a file that plays correctly under LIbreELEC.

    Is there some Kodi or FFMPEG or Linux configuration that might cause this difference?

    Aside from sifting through LibreELEC patches, I have tried:

    • ensuring there is only one /dev/videoN device (rkvdec, and well, rkvenc but that one should be skipped...) by unloading the other modules (rockchip_rga, rockchip_hantro, rockchip_iep)
    • Checking the v4l2-ctl output through v4l2-ctl: v4l2-ctl.log

    I will try using FFMPEG 5.1.2 but I fear that won't make much difference, as I've had this problem for quite a while (since right after the "kodi_working.log".

    Any help is much appreciated!

  • Hello

    I am trying to do the same thing with Allwinner H3 OrangePi zero, which works with the latest Kodi.

    One thing you can do to test success of your linux patch is:

    v4l2-compliance --device /dev/video0

    v4l2-ctl --device /dev/video0 -all

    If you don't see references to h264 abilities, maybe the linux patches don't work for you.

    The latest Kodi works with linux 6.1.19... maybe you should try that.

    I didnt think of applying the drmprime patch... that seems important... I will try it.

  • I didn’t read your logs, and I think that the kernel patching is not your problem, maybe.

    what do you get with:

    ffmpeg —hwaccels

    ffmpeg —decoders | grep h264… then v4l2… and request

  • You could also load the latest Kodi in your rockchip sbc, add the tools-ffmpeg addon, then run:

    ffmpeg —hwaccels (you will also see the ffmpeg version, and the ./configure options)

    ffmpeg —decoders (looking for v4l2_request)

    And if you build the whole libreelec (latest) in your PC, you might find evidences of the pre compilation options used, in the Makefile, and the patches that were applied.

  • Hi robertoj,

    I have just Frankenstein-extracted the LibreELEC SYSTEM partition and by bind mounting /dev, /proc, and /sys, chrooting into the extracted directory, and running /lib/kodi/kodi.sh I could get Kodi to run, audio and video and all, and I could effortlessly play an HEVC file.

    This means my patched 64-bit kernel contains all the necessary and correct bits to play back HEVC properly, and the problem as you suspected lies with either ffmpeg or kodi.

    Since building kodi with (patched) ffmpeg in-tree is such a hassle, I am reworking my kodi build to use a system installed ffmpeg which I can patch and replace more easily.

  • I have some scripts to rebuild the Debian FFMPEG packages with v4l2-request support which may provide some helpful info. In particular when compiling FFMPEG, you need to add --enable-v4l2-request to the configure arguments, but you also have to have Linux kernel headers (in Debian the package name for this is linux-libc-dev) from a kernel with v4l2-request support installed on the system where you are compiling FFMPEG. You can see in the script I install linux-libc-dev from a kernel I built previously.

  • I feel ridiculously stupid, but my problem was that the linux-qpi-headers package on Archlinux ARM does not match the regular kernel version. There was probably a difference in some constant that my kernel gave another meaning to (see the "type 9" vs "type 10" in the good and bad logs I posted above.

    Installing matching linux-api-headers and just rebuilding everything as I was doing (so linux and ffmpeg with the LibreELEC rockchip patches for linux 6.2.x) accelerated HEVC now works like a charm.

    Thank you again LIbreELEC devs for maintaining these patches for already so long for this trusty little ARM chip.