[A06] Mainline hardware video decoding tested working!

Just updated kernel to 6.0.9 by adapting the manjaro patches, and I saw that rk3399 hardware video decoding is now supported in the kernel.

Note, there are two ways of hardware video decoding, one is to use the mali GPU, and the other is to use the on-chip video decoder, which is more efficient. In this post I’m talking about the latter case.

To leverage this capability:

  1. Make sure the kernel is recent (go 6.0!), and enable the following options:
  • CONFIG_VIDEO_HANTRO=m
  • CONFIG_VIDEO_HANTRO_ROCKCHIP=y
  • CONFIG_VIDEO_ROCKCHIP_VDEC=m
  1. Build and the ffmpeg fork that supports the rockchip vdec:
  1. try ffmpeg:
  • without hw dec: ffmpeg -i input.mp4 -f null - -benchmark
  • with hw dec: ffmpeg -hwaccel drm -i input.mp4 -f null - -benchmark
  1. mpv
  • the distro package may have been statically linked to ffmpeg, so it won’t work out of the box. I use the aur version: AUR (en) - mpv-git
  • the custom build will be linked against our modified ffmpeg
  • mpv --hwdec=drm test.mp4
  • this setting can be stored in config files
  • In my tests, I tried to playback a 1080p h264 video. Without hw dec: saturates one big core and 50% load on other cores with high frequency; With hw dec: total cpu utilization <10%, can play smoothly at gear 2 (2 little cores @ 800MHz)
  • It not only decodes, but goes directly to blit the video onto the screen. The cpus are very happy about this.
  1. chromium
  1. moonlight (game straeming)
  • works after recompile & link with custom ffmpeg. You’ll see rkvdec related debugging logs in the console output.

Tested not working:

  • 4k mkv: rkvdec gives up, fallback to gpu decoding
  • freerdp: need further investigate how to enable hw codec
  • vlc: need further investigate how to pass -hwaccel drm to it

To verify it’s working for one software, launch it, and then watch /proc/interrupts and see if rkvdec interrupt number grows.

So… clockworkpi team, please incorporate this into future OS images. It’s a matter of “working vs. works great”!

13 Likes

I can also confirm hardware decoding seems to work on kernel 6.0 with mpv 0.35 and ffmpeg from the linked repo.

2 Likes

Hey,

Just to follow up on this if someone wants to follow this guide now:

Step 2, for Arch/Manjaro, ffmpeg-v4l2-request-git is broken (at least for me and this guy).

There’s a patch here, but it’s patched on version 6.0+, so I tried to build it instead.

Git clone this (https://aur.archlinux.org/ffmpeg-v4l2-request-git.git) and edit the PKGBUILD file
Change _version='5.1.2' to _version='6.0'.
Save, exit, run makepkg -si.

Go to step 3

Thanks @yatli for bringing this on the DevTerm :slight_smile:

Yes you’re right! Ffmpeg v4l2 request can leap forward into 6.0.
Don’t forget to also adjust the 3 branch names in PKGBUILD!
Also, we can hack PKGBUILD package name directly to ffmpeg (without the suffix) and let it overwrite the distro provided package. This helps to avoid manually overwriting binaries, which is always hit and miss.

Now it can even do chromium YouTube surfing for some good 3 hours…

I really hope we see this in an official OS build.

(Or maybe unofficial ones. Whatever works!)

It’d be even better if the maintainer would upgrade to 6.0. I’ll drop a comment on AUR later.
As for the overwriting, isn’t the provides=("ffmpeg", "ffmpeg4.4") enough?

I have a very clear difference between using hwdec=drm and not using it on my machine, but I don’t see any rkvdec interrupt, and mpv outputs an error message from ffmpeg:

[ffmpeg/video] h264: v4l2_request_probe_video_device: try output format failed

But it works, apparently :thinking:

Btw, did you find how to make chromium work? Is it an older version?

I get 4h10m of h264 720p video playback with mpv. Impressive!

1 Like

As for the overwriting, isn’t the provides=("ffmpeg", "ffmpeg4.4") enough?

Yeah that’s what I suggested back then… But 6.0 is too different now, things linked to 4.4 wouldn’t start. :thinking:

Probably install both 4.4 and 6.0 from this PKGBUILD?

@lonewsk check these out:

6.0 and 4.4 can co-exist now.

1 Like

Hey @yatli
I’ve been trying to make moonlight work, but can’t find a way. How did you recompile with custom ffmpeg?