Got HW Transcoding to work with libva/vaapi on Ryzen APU (Ryzen 7 4700U)

@war_lock Would you mind manually installing the packages @hexeth installs in his image on the original Plex + mod container?

Ideally one at a time and then testing. Then moving to the next package.

apt-get update
apt-get install -y software-properties-common
add-apt-repository ppa:oibaf/graphics-drivers -y
apt-get update
apt-get install -y vainfo
apt-get install -y mesa-va-drivers
apt-get install -y mesa-vdpau-drivers
apt-get install -y libdrm-amdgpu1
apt-get install -y libavutil56

doesnt work and vainfo gives the following error:

root@plex:/# vainfo
vainfo: Relink /vaapi-amdgpu/lib/libbsd.so.0' with /lib/x86_64-linux-gnu/libc.so.6’ for IFUNC symbol `memmove’
Segmentation fault (core dumped)

@war_lock Once you have launched the container shell, you can execute the command below before installing the packages.

unset LD_LIBRARY_PATH

This will restore use of the default librairies for the duration of your shell’ session.

EDIT

Another (probably most effective) way to identify the differences between @hexeth image and the mod would be to use ldd. You could execute this command on each container and report the results here.

Mod container:

ldd /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so

hexeth image:

ldd /lib/plexmediaserver/lib/dri/radeonsi_drv_video.so

Note that you first need to launch a transcoding prior of using ldd. The dri lib needs to be loaded before ldd can list the dependencies.

Thank you, @hexeth I was spending like 10 hours in front of my computer trying to figure it out and bump! This work perfect. Usually I dont reply any post but you deserved. Have a nice day.,

Could you explain a little more how can this work because I do not much familiar with docker and stuffs. Thank for your contribution. How should add this to my current image docker plex?

If you are using linuxserver.io Plex image, they have a built-in mechanism to customize containers with user mods:
docker-mods/README.md at master · linuxserver/docker-mods · GitHub

When the container starts, it downloads the mod which contains the librairies. To enable the mod you need to specify the DOCKER_MODS environment variable. In addition, you need to specify LIBVA_DRIVERS_PATH and LD_LIBRARY_PATH environment variables, so the mod’s librairies get actually loaded at runtime.

       -e DOCKER_MODS=jefflessard/plex-vaapi-amdgpu-mod \
       -e LIBVA_DRIVERS_PATH="/vaapi-amdgpu/lib/dri" \
       -e LD_LIBRARY_PATH=/vaapi-amdgpu/lib:/lib/plexmediaserver/lib:/lib/x86_64-linux-gnu/:/lib \
1 Like

working for me on Ryzen 4650G on Ubuntu host, great work @jeffle81 :grinning:

1 Like

just to clarify, hexeth image does not work for me, hw acceleration works but it creates color flashes which are presumably from faulty drivers, the container that does work 100% is the current one from mauimauer which is alpine based
Your image though, does not even work with any hw acceleration at all for me.

its strange though that this seems to work fine for other users using desktop CPUs (I am using a mobile CPU)

this is the vainfo output from the container after unset of the path and then installing all packages:

root@plex:/# vainfo
error: XDG_RUNTIME_DIR not set in the environment.
error: can’t connect to X server!
libva info: VA-API version 1.14.0
libva info: Trying to open /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so
libva error: dlopen of /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so failed: libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

@jeffle81 To add on to what @war_lock said, using hexeth’s image HW transcoding works 80% of the time but I don’t have any encoding issues when it runs. Whereas, mauimauer’s image works perfectly for me, but I switched because it was not being updated regularly.

I have a desktop Ryzen 5 2400G

I just published a newer release which automatically defines LD_LIBRARY_PATH specifically scoped at Plex. So, it won’t apply to other binaries in the container.

You now need to remove -e LD_LIBRARY_PATH=... from your docker run command.

@war_lock and @InvisiGo thanks for the clarification. I will have a look at @mauimauer image when I will have some time.

Can you update the readme on docker hub to reflect that? Also, do you still need that on the exec command to test with?

@cardonator Done!

Here is the updated quick test command

docker exec -it -e LD_LIBRARY_PATH=/vaapi-amdgpu/lib plex \
/lib/plexmediaserver/Plex\ Transcoder -hide_banner -loglevel debug -vaapi_device /dev/dri/renderD128

@war_lock and @InvisiGo I had a quick look at mauimauer Dockerfile and I didn’t see anything obvious.

What are your Linux kernel versions? Mine is 5.10.146
I am asking because there has been a lot of changes on the AMDGPU kernel internal module lately. Maybe you are running an older kernel version which is not compatible with current radeonsi_drv_video.so driver.

To check your kernel version:

uname -r

I get 5.18.0-0.deb11.4-amd64 when after running uname -r

I get 5.15.0-53-generic and it seems that hw transcoding now sometimes does work while sometimes it doesnt which is better than before, also works without color flashing.

mauimauers image is based on Alpine which is why its so different, I would just use his image if it were maintained at all

Splitting the commandline.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-vaapi_device' ... matched as option 'vaapi_device' (set VAAPI hardware device (DRM path or X11 display name)) with argument '/dev/dri/renderD128'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option hide_banner (do not show program banner) with argument 1.
Applying option loglevel (set logging level) with argument debug.
Applying option vaapi_device (set VAAPI hardware device (DRM path or X11 display name)) with argument /dev/dri/renderD128.
[AVHWDeviceContext @ 0x7f97d681a0c0] libva: VA-API version 1.16.0
[AVHWDeviceContext @ 0x7f97d681a0c0] libva: Trying to open /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so
[AVHWDeviceContext @ 0x7f97d681a0c0] libva: Found init function __vaDriverInit_1_16
/usr/share/libdrm/amdgpu.ids: No such file or directory
[AVHWDeviceContext @ 0x7f97d681a0c0] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x7f97d681a0c0] Initialised VAAPI connection: version 1.16
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x3231564e -> nv12.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x30313050 -> p010le.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x36313050 -> unknown.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x30323449 -> yuv420p.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x32315659 -> yuv420p.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x56595559 -> unknown.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x32595559 -> yuyv422.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x59565955 -> uyvy422.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x41524742 -> bgra.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x41424752 -> rgba.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x58524742 -> bgr0.
[AVHWDeviceContext @ 0x7f97d681a0c0] Format 0x58424752 -> rgb0.
[AVHWDeviceContext @ 0x7f97d681a0c0] VAAPI driver: Mesa Gallium driver 22.2.4 for AMD Radeon Graphics (renoir, LLVM 15.0.5, DRM 3.42, 5.15.0-53-generic).
[AVHWDeviceContext @ 0x7f97d681a0c0] Driver not found in known nonstandard list, using standard behaviour.
Successfully parsed a group of options.
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

I got this!! Thank you for you help! it works sharp. Have a nice day.

1 Like

Well, a fairly recent kernel! This should not be the problem then.

For the records, current Alpine edge kernel version is 5.15.

I would like to help further but I don’t know where to look at!

On my side, I observed that hw decoding doest not always apply. Sometimes it doesn’t enable at all for some specific files, while it will enable only at some specific resolutions for some other files. I have not been able yet to understand on what basis this happens. No error in Plex logs… Let me know if you happen to identify a pattern in which case it works or not.

By the way, the librairies of the mod are taken out of current Alpine edge version, so that shouldn’t be the issue.

I tried this on the lsio VERSION=public image and I get this error

[AVHWDeviceContext @ 0x7f77cbe372c0] libva: VA-API version 1.15.0
[AVHWDeviceContext @ 0x7f77cbe372c0] libva: Trying to open /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so
[AVHWDeviceContext @ 0x7f77cbe372c0] libva: dlopen of /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so failed: Error loading shared library libxcb-sync.so.1: No such file or directory (needed by /vaapi-amdgpu/lib/dri/radeonsi_drv_video.so)
[AVHWDeviceContext @ 0x7f77cbe372c0] libva: va_openDriver() returns -1

Sorry, false alarm. This was the test command. IT worked when I used the right environment variable.

1 Like

It looks like LD_LIBRARY_PATH is not set. If you use the previous mod version you need to set an environment variable in docker run command. This was done with the following arguments

-e LD_LIBRARY_PATH=/vaapi-amdgpu/lib:/lib/plexmediaserver/lib:/lib/x86_64-linux-gnu/:/lib

In the today’s newer release, it should be set automatically by the run command of s6 svc-plex in /etc/s6-overlay/s6-rc.d/svc-plex/run, which is:

#!/usr/bin/with-contenv bash

echo "Starting Plex Media Server. . . (you can ignore the libusb_init error)"
export PLEX_MEDIA_SERVER_INFO_MODEL=$(uname -m)
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION=$(uname -r)
export LD_LIBRARY_PATH=/vaapi-amdgpu/lib
exec \
    s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 32400" \
        s6-setuidgid abc "/usr/lib/plexmediaserver/Plex Media Server"

When doing the test using the newer version, make sure to set the LD_LIBRARY_PATH like this

docker exec -it -e LD_LIBRARY_PATH=/vaapi-amdgpu/lib plex \
/lib/plexmediaserver/Plex\ Transcoder -hide_banner -loglevel debug -vaapi_device /dev/dri/renderD128