[app] Kodi on armbian with hardware accelerating decode

The hantro g1 support for rk3568 is already merged in linux-next: https://patchwork.kernel.org/project/linux-rockchip/patch/20220214212955.1178947-1-piotr.oniszczuk@gmail.com/. And armbian has this patch applied in edge kernel 5.18. And my armbian image also supports it: https://github.com/amazingfate/armbian-rock3a-images/. I use my armbian jammy gnome image to test kodi.

Video hardware decode is only support in kodi gbm mode now, but still not working out of box because of 2 reasons:
1, mesa is compiled with swrast support, so kodi gbm will start in software rendering, which doesn’t support gpu rendering. I’ve confirmed that mesa has nothing to do with kodi hardware acceleration.
2, kodi from debian is build with -DAPP_RENDER_SYSTEM=gl, but we need gles instead.

So I’ve rebuild mesa without swrast and kodi with gles render system. After install missing font packages fonts-noto-core fonts-roboto-hinted fonts-noto-mono, I can start kodi gbm by running command kodi-standalone --windowing=gbm. At first my screen is black with no video input, replugging the HDMI would help showing the kodi window.

In Settings -> Player -> Videos, enable Allow using DRM PRIME decoder and Allow hardware acceleration with DRM PRIME, you can now play h264 video up to 1080p@60fps with hardware decode. I can play bbb_sunflower_1080p_60fps_normal.mp4 with cpu load less than 40%.

Here is the mesa kodi and ffmpeg debs I’ve built for armbian jammy: https://drive.google.com/drive/folders/1Qq7bALtY02He3jPM1gLuX1hz2vrLYXTl?usp=sharing. You can use apt to install on your armbian jammy, for example:

sudo apt install ./kodi_19.4+dfsg1-2_arm64.deb ./kodi-bin_19.4+dfsg1-2_arm64.deb ./kodi-data_19.4+dfsg1-2_all.deb --reinstall
sudo apt install ./ffmpeg_4.4.1-3ubuntu9_arm64.deb ./libavcodec-dev_4.4.1-3ubuntu9_arm64.deb ./libavcodec58_4.4.1-3ubuntu9_arm64.deb ./libavdevice-dev_4.4.1-3ubuntu9_arm64.deb ./libavdevice58_4.4.1-3ubuntu9_arm64.deb ./libavfilter-dev_4.4.1-3ubuntu9_arm64.deb ./libavfilter7_4.4.1-3ubuntu9_arm64.deb ./libavformat-dev_4.4.1-3ubuntu9_arm64.deb ./libavformat58_4.4.1-3ubuntu9_arm64.deb ./libavutil-dev_4.4.1-3ubuntu9_arm64.deb ./libavutil56_4.4.1-3ubuntu9_arm64.deb ./libpostproc-dev_4.4.1-3ubuntu9_arm64.deb ./libpostproc55_4.4.1-3ubuntu9_arm64.deb ./libswresample-dev_4.4.1-3ubuntu9_arm64.deb ./libswresample3_4.4.1-3ubuntu9_arm64.deb ./libswscale-dev_4.4.1-3ubuntu9_arm64.deb ./libswscale5_4.4.1-3ubuntu9_arm64.deb --reinstall

Update: wayland also support hardware decode, setting the same options as gbm above will make it.

2 Likes

For wayland, just install the ffmpeg and kodi, then you can use drm prime hardware acceleration.

1 Like

@amazingfate

Hi

Can you also build Chromium or Firefox with hardware decode or 3D support?

Kodi, ffmpeg could also work for Armbian Jammy on RockPi 4, right or other changes needed?
Do you have Armbian Jammy for RockPi 4 with these patches perhaps - https://github.com/armbian/build/pull/3893

Chromium from this ppa: https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta has panfrost support. Hardware decode is not well supported by chromium, but people are working on it: https://bugzilla.redhat.com/show_bug.cgi?id=2071126. I tried to build a verion of chromium with patch https://chromium-review.googlesource.com/c/chromium/src/+/3380426/4, but hardware decode doesn’t work.
The patches you mentioned add the support for HEVC 10-bit HDR, which is not supported by rk3568 mainline kernel by now, so I don’t care about it. My kodi and ffmpeg should work on rockpi4 without other changes. To get HEVC 10-bit HDR support you have to wait for the pull request getting merged and install the new kernel with those patches.

@amazingfate
Thanks
Can you also build mpv video player with video hardware decoding support?

No need to build mpv because mpv use ffmpeg. I can use the vpu using mpv option --hwdec=drm-copy, but the video is not played smoothly.

moonlight 是否可以用这个支持 硬件解码的ffmpeg 构建

Moonlight add drmprime and v4l2-request patches from libreELEC since v3.1.0:https://newreleases.io/project/github/moonlight-stream/moonlight-qt/release/v3.1.0.
It should work but I didn’t test.

好的,感谢1111111111111

Freerdp h264 avc444 有没有办法也支持硬件解码

freerdp的avc444模式,h264解码只是其中一部分,还涉及其他软件处理,现在主线的v4l2-request只能用drm prime的方式解码,我还没试过,你要感兴趣可以自己试试

1 Like

we used armbian 22.05,linux 5.17.9.We tested the mainline Linux VPU decoding capability on the rock 3a board(soc rk3568). We used ffmpeg from https://github.com/jernejsk/FFmpeg and configuration:–enable-libdrm --enable-libv4l2 --enable-v4l2-request --enable-libudev --enable-static --disable-sharedb0. When we use the following command prompt an error:

./ffmpeg -loglevel debug -hwaccel drm -i …/Jellyfish_1080_10s_30MB.mp4 -pix_fmt bgra -f fbdev /dev/fb0

Successfully opened the file.
Device creation failed: -14.
[h264 @ 0xaaaaac42f520] No device available for decoder: device type drm needed for codec h264.
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Device setup failed for decoder on input stream #0:0 : Bad address

The VPU driver has been loaded correctly:

root@rock-3a:~/FFmpeg# dmesg |grep vpu
[ 53.304850] hantro_vpu: module is from the staging directory, the quality is unknown, you have been warned.
[ 53.328532] hantro-vpu fdea0000.video-codec: Adding to iommu group 0
[ 53.331978] hantro-vpu fdea0000.video-codec: registered rockchip,rk3328-vpu-dec as /dev/video0

and

root@rock-3a:~/FFmpeg# dmesg |grep drm
[ 2.752665] rockchip-drm display-subsystem: bound fe040000.vop (ops vop2_component_ops)
[ 2.756569] rockchip-drm display-subsystem: bound fe0a0000.hdmi (ops dw_hdmi_rockchip_ops)
[ 2.757416] [drm] Initialized rockchip 1.0.0 20140818 for display-subsystem on minor 0
[ 2.757569] rockchip-drm display-subsystem: [drm] Cannot find any crtc or sizes
[ 2.757724] rockchip-drm display-subsystem: [drm] Cannot find any crtc or sizes
[ 4.028876] [drm] Initialized panfrost 1.2.0 20180908 for fde60000.gpu on minor 1
[ 51.128088] systemd[1]: Condition check resulted in Load Kernel Module drm being skipped.
[12442.376669] rockchip-drm display-subsystem: [drm] fb0: rockchipdrmfb frame buffer device

and

root@rock-3a:~/FFmpeg# v4l2-ctl -d 0 --list-formats --list-ctrls

Codec Controls

               h264_profile 0x00990a6b (menu)   : min=0 max=4 default=2 value=2

Stateless Codec Controls

           h264_decode_mode 0x00a40900 (menu)   : min=1 max=1 default=1 value=1
            h264_start_code 0x00a40901 (menu)   : min=1 max=1 default=1 value=1
h264_sequence_parameter_set 0x00a40902 (unknown): type=200 flags=has-payload
 h264_picture_parameter_set 0x00a40903 (unknown): type=201 flags=has-payload
        h264_scaling_matrix 0x00a40904 (unknown): type=202 flags=has-payload
     h264_decode_parameters 0x00a40907 (unknown): type=204 flags=has-payload
       vp8_frame_parameters 0x00a409c8 (unknown): type=240 flags=has-payload
     mpeg_2_sequence_header 0x00a409dc (unknown): type=251 flags=has-payload
      mpeg_2_picture_header 0x00a409dd (unknown): type=252 flags=has-payload

mpeg_2_quantisation_matrices 0x00a409de (unknown): type=250 flags=has-payload
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture Multiplanar

    [0]: 'NV12' (Y/CbCr 4:2:0)

Only drm_prime is supported.
This command works for me:
ffmpeg -hwaccel drm -hwaccel_output_format drm_prime -i test.mp4 -f null -

还是一样的错误:
root@rock-3a:~# ffmpeg -hwaccel drm -hwaccel_output_format drm_prime -i Jellyfish_1080_10s_30MB.mp4 -f null -
ffmpeg version 4.2.7-0ubuntu0.1 Copyright © 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘Jellyfish_1080_10s_30MB.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
Duration: 00:00:10.01, start: 0.000000, bitrate: 25139 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 25137 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Device creation failed: -14.
[h264 @ 0xaaaaaab305d0] No device available for decoder: device type drm needed for codec h264.
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Device setup failed for decoder on input stream #0:0 : Bad address

@amazingfate 我现在ffmpeg 库是我自己编译的,依赖库是我自己apt 公共源安装的,你有用的那个deb包,因为的Ubuntu版本是focal!

我不知道你用的什么源码编出来的4.2.7版本的ffmpeg,也不知道你在的内核支不支持硬件解码。建议用我提供的镜像,或者使用armbian构建最新的主线内核。我现在是5.19内核,相关版本输出如下:

jfliu@rock-3a:~$ ffmpeg -version
ffmpeg version 4.4-Kodi Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
configuration: --prefix=/usr --extra-version=3ubuntu9 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libudev --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-v4l2-request --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100
jfliu@rock-3a:~$ uname -a
Linux rock-3a 5.19.0-rk35xx #trunk SMP PREEMPT Mon Aug 1 04:15:52 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

root@rock-3a:~/FFmpeg# ./ffmpeg -hwaccel drm -hwaccel_output_format drm_prime -i …/Jellyfish_1080_10s_30MB.mp4 -f null -
ffmpeg version 8d663e7b4c-Kodi Copyright © 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --enable-libdrm --enable-libv4l2 --enable-v4l2-request --enable-libudev --enable-static --disable-shared
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘…/Jellyfish_1080_10s_30MB.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
Duration: 00:00:10.01, start: 0.000000, bitrate: 25139 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 25137 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to ‘pipe:’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.76.100
Stream #0:0(und): Video: wrapped_avframe, drm_prime(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc58.134.100 wrapped_avframe
frame= 300 fps= 75 q=-0.0 Lsize=N/A time=00:00:10.01 bitrate=N/A speed=2.51x
video:157kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

可以了,感谢帮助!!!忘记打./了 默认走的是Ubuntu自带的FFmpeg:rofl:

你们讨论的是rk3568 GPU支持的硬件加速解码,而非VPU支持的硬解码。对吗?

对你来说回答什么都不重要,建议自己搞清楚基本概念