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

Will be looking into it this weekend. Very possible Plex is ignoring the radeon drivers in their most recent version. Might be possible to trick it to load the right one with a symlink (from i965_drv_video.so to the radeonsi driver), should work as both are expected to expose the same VAAPI signatures.

I’m not sure exactly what happened but… I removed PMS from my docker-compose.yml and installed it standalone (using the .4392 version linked from GitHub - axlecrusher/plex_download_urls: Archive of Plex mediaserver download URLs). I copied all the files as shown in the first post of the thread and… it worked!

May 18, 2021 16:42:59.500 [0x7f3e6ffff700] Debug — [Transcode] Codecs: testing hevc (decoder) with hwdevice vaapi
May 18, 2021 16:42:59.500 [0x7f3e6ffff700] Debug — [Transcode] Codecs: hardware transcoding: testing API vaapi
May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x3231564e -> nv12.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x30313050 -> p010le.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x36313050 -> unknown.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x30323449 -> yuv420p.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x32315659 -> yuv420p.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x56595559 -> unknown.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x32595559 -> yuyv422.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x59565955 -> uyvy422.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x41524742 -> bgra.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x41424752 -> rgba.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x58524742 -> bgr0.

May 18, 2021 16:42:59.507 [0x7f3e6ffff700] Debug — [Transcode] [FFMPEG] - Format 0x58424752 -> rgb0.

Huh, interesting, maybe the patch isn’t needed anymore. Does anyone know where they keep the release notes? @ChuckPa has AMD support been officially added?

1 Like

Good luck with your investigation. FWIW, here are the contents of the docker-compose.yml from my system… note that I have lots of other stuff loaded w/ docker-compose that I’m purposely omitting but PMS always worked fine using this method - with the exception of hardware transcoding.

services:
  plex:
    #image: linuxserver/plex
    image: mauimauer/plex
    container_name: plex
    network_mode: host
    devices:
      - /dev/dvb
      - /dev/dri:/dev/dri
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - UMASK_SET=022 #optional
      - PLEX_CLAIM= #optional
    volumes:
      - /mnt/hdd0/plexconfig:/config
      - /mnt/hdd0/TV:/tv
      - /mnt/hdd0/Movies:/movies
      - /mnt/hdd0/Music:/music
      - /home/andrew/plex_transcode:/transcode
    dns:
      - 192.168.1.1
    restart: unless-stopped

There is no official support for AMD.

If you’re good enough to get the AMD drivers to show up properly under libva then yes, Plex can make use of it.

I tested the latest version from linuxsever and it doesn´t work with hw transcoding on my system. Therefore I go back to the docker container published by mauimauer and this works with hw transcoding.

I can confirm that things are nonfunctional again with the latest Plex release 1.22.3.4523-d0ce30438

The transcoder simply dies with a segfault

Jobs: '/usr/lib/plexmediaserver/Plex Transcoder' exit code for process 2991 is -11 (signal: Segmentation fault)

AMD’s VAAPI interface remained stable so this is just Plex regressing back. Need to dig deeper to see if a cause for this is logged anywhere. It might be feasible to just splice in a transcoding binary from an earlier release.

1 Like

Not working

FFMPEG_EXTERNAL_LIBS='/config/Library/Application\ Support/Plex\ Media\ Server/Codecs/73e06c8-3759-linux-x86_64/' LIBVA_DRIVERS_PATH='/usr/lib/plexmediaserver/lib/dri' /usr/lib/plexmediaserver/Plex\ Transcoder -codec:#0x01 h264 -codec:#0x02 aac -ss 192 -analyzeduration 20000000 -probesize 20000000 -i /data/Movies/movie.mp4 -filter_complex "[0:#0x01]scale=w=1920:h=800[0];[0]format=pix_fmts=yuv420p|nv12[1]" -map [1] -codec:0 libx264 -crf:0 16 -maxrate:0 2707k -bufsize:0 5414k -r:0 23.975999999999999 -preset:0 veryfast -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=hex:8x8dct=0:partitions=none -force_key_frames:0 "expr:gte(t,n_forced*3)" -filter_complex "[0:#0x02] aresample=async=1:ocl='stereo':rematrix_maxval=0.000000dB:osr=44100[2]" -map [2] -metadata:s:1 language=eng -codec:1 aac -b:1 256k -f dash -seg_duration 3 -init_seg_name init-stream$RepresentationID$.m4s -media_seg_name chunk-stream$RepresentationID$-$Number%05d$.m4s -window_size 5 -delete_removed false -skip_to_segment 65 -time_delta 0.0625 -manifest_name http://127.0.0.1:32400/video/:/transcode/session/manifest?X-Plex-Http-Pipeline=infinite -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 dash -start_at_zero -copyts -init_hw_device vaapi=vaapi: -filter_hw_device vaapi -loglevel verbose -loglevel_plex error

Working
`

FFMPEG_EXTERNAL_LIBS='/config/Library/Application\ Support/Plex\ Media\ Server/Codecs/73e06c8-3759-linux-x86_64/' LIBVA_DRIVERS_PATH='/usr/lib/plexmediaserver/lib/dri' /usr/lib/plexmediaserver/Plex\ Transcoder -codec:#0x01 h264 -hwaccel:#0x01 vaapi -hwaccel_fallback_threshold:#0x01 10 -hwaccel_output_format:#0x01 vaapi -hwaccel_device:#0x01 vaapi -codec:#0x02 aac -analyzeduration 20000000 -probesize 20000000 -i /data/Movies/movie.mp4 -filter_complex "[0:#0x01]hwupload[0];[0]scale_vaapi=w=1920:h=800:format=nv12[1];[1]hwupload[2]" -map [2] -codec:0 h264_vaapi -b:0 2030k -maxrate:0 2707k -bufsize:0 5414k -r:0 23.975999999999999 -force_key_frames:0 "expr:gte(t,n_forced*3)" -filter_complex "[0:#0x02] aresample=async=1:ocl='stereo':rematrix_maxval=0.000000dB:osr=44100[3]" -map [3] -metadata:s:1 language=eng -codec:1 aac -b:1 256k -f dash -seg_duration 3 -init_seg_name 'init-stream$RepresentationID$.m4s' -media_seg_name 'chunk-stream$RepresentationID$-$Number%05d$.m4s' -window_size 5 -delete_removed false -skip_to_segment 1 -time_delta 0.0625 -manifest_name http://127.0.0.1:32400/video/:/transcode/session/manifest?X-Plex-Http-Pipeline=infinite -avoid_negative_ts disabled -map_metadata -1 -map_chapters -1 dash -start_at_zero -copyts -vsync cfr -init_hw_device vaapi=vaapi: -filter_hw_device vaapi -loglevel verbose -loglevel_plex error
`
Going to see if we can solve this with a wrapper…Plex simply stopped setting up the hw accelerated chain

2 Likes

Well, this sucks. So it seems Plex is at least attempting to use HW acceleration, however the transcoder just dies, the commandline is identical to previously working versions. So it’s simply a regression in the Plex Transcoder

/usr/lib/plexmediaserver/Plex Transcoder: 1900 Segmentation fault (core dumped)

All we can really do here is wait and hope one of the next releases fixes this.

2 Likes

After lots of patching, I have been able to make the libva init work again, but it still seems something fundamental has changed within the Plex Transcoder (which is basically just a propietary version of FFMPEG) so that a successful HW decoding/encoding pipeline can’t be setup. No idea yet why this is failing.

May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x3231564e -> nv12.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x30313050 -> p010le.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x36313050 -> unknown.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x30323449 -> yuv420p.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x32315659 -> yuv420p.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x56595559 -> unknown.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x32595559 -> yuyv422.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x59565955 -> uyvy422.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x41524742 -> bgra.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x41424752 -> rgba.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x58524742 -> bgr0.
May 28, 2021 14:42:49.593 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x58424752 -> rgb0.
May 28, 2021 14:42:49.601 [0x7f8d2cf96b38] Error — [Transcode] [FFMPEG] - Cannot load libcuda.so.1
May 28, 2021 14:42:49.601 [0x7f8d2cf96b38] Error — [Transcode] [FFMPEG] - Could not dynamically load CUDA
May 28, 2021 14:42:49.610 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x3231564e -> nv12.
May 28, 2021 14:42:49.610 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x30313050 -> p010le.
May 28, 2021 14:42:49.610 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x36313050 -> unknown.
May 28, 2021 14:42:49.610 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x30323449 -> yuv420p.
May 28, 2021 14:42:49.610 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x32315659 -> yuv420p.
May 28, 2021 14:42:49.610 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x56595559 -> unknown.
May 28, 2021 14:42:49.611 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x32595559 -> yuyv422.
May 28, 2021 14:42:49.611 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x59565955 -> uyvy422.
May 28, 2021 14:42:49.611 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x41524742 -> bgra.
May 28, 2021 14:42:49.611 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x41424752 -> rgba.
May 28, 2021 14:42:49.611 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x58524742 -> bgr0.
May 28, 2021 14:42:49.611 [0x7f8d2cf96b38] Debug — [Transcode] [FFMPEG] - Format 0x58424752 -> rgb0.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x3231564e -> nv12.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x30313050 -> p010le.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x36313050 -> unknown.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x30323449 -> yuv420p.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x32315659 -> yuv420p.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x56595559 -> unknown.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x32595559 -> yuyv422.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x59565955 -> uyvy422.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x41524742 -> bgra.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x41424752 -> rgba.
May 28, 2021 14:42:49.703 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x58524742 -> bgr0.
May 28, 2021 14:42:49.704 [0x7f8d34d68b38] Debug — [Transcode] [FFMPEG] - Format 0x58424752 -> rgb0.
May 28, 2021 14:42:49.704 [0x7f8d34d68b38] Error — [Transcode] [FFMPEG] - Failed to create surface: 14 (the requested RT Format is not supported).
May 28, 2021 14:42:49.704 [0x7f8d34d68b38] Error — [Transcode] [FFMPEG] - Unable to allocate a surface from internal buffer pool.
2 Likes

Hey there, I’m experiencing the same issues. HW transcoding stopped working after upgrading to 1.23. I’m now running on 1.23.2.4600 (upgraded today) but still no luck. My CPU is almost fully utilized when transcoding 4K files.

Log file looks like this:

May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] DEBUG - [Transcode] Codecs: hardware transcoding: testing API nvenc
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] ERROR - [Transcode] [FFMPEG] - Cannot load libcuda.so.1
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] ERROR - [Transcode] [FFMPEG] - Could not dynamically load CUDA
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] DEBUG - [Transcode] Codecs: hardware transcoding: opening hw device failed - probably not supported by this system, error: Unknown error occurred
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] DEBUG - [Transcode] MDE: Cannot direct stream video stream due to profile or setting limitations
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] DEBUG - [Transcode] Codecs: testing hevc (decoder) with hwdevice vaapi
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] VERBOSE - [Transcode] [FFMPEG] - Rescanning for external libs: ‘/raid/data/users/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Codecs/fa235d6-3858-linux-x86_64/’
May 29, 2021 09:23:46.372 [0x7f24cf5b6b38] DEBUG - [Transcode] Codecs: hardware transcoding: testing API vaapi

@mauimauer: What did you do to fix/patch this?

EDIT: My graphics card is an Nvidia GTX 1060 GiB and Plex is running on bare metal.

There is no solution yet. However since you are using an nVidia GPU, which is supposed to be officially supported by Plex, you should open a bug to make them aware.

1 Like

1.23.1.4602 still broken (ie. Plex doesnt properly test for vaapi support and doesnt setup hwupload routes with FFMPEG as it used to)

1 Like

good work man , currently using your repository, working perfectly on my 3400g.really hope it will support officially one day,

The solution doesn’t seem to work anymore for 1.23.2.4656 :frowning:
Is there a known fix?

Not at this time. I tried all sorts of things, but as it stands more recent versions of Plex seem to have broken/changed the way they interact with vaapi. I’ll keep a lookout for new versions potentially getting this to work again but right now it’s not looking good.

I’m still using version 1.22.3.4392-d7c624def. Is that the most recent that works?

Yep, just had another try with the latest version (1.23.3.4707-ebb5fe9f3). Compared to previous versions Plex is still failing to detect and properly use transcoding via vaapi. I doubt they will look into this issue given they don’t officially support transcoding on AMD GPUs at all.

Jun 26, 2021 15:46:09.869 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] Codecs: hardware transcoding: testing API vaapi
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x321564e -> nv12.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x30313050 -> p010le.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x36313050 -> unknown.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x30323449 -> yuv420p.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x32315659 -> yuv420p.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x56595559 -> unknown.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x32595559 -> yuyv422.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x59565955 -> uyvy422.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x41524742 -> bgra.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x41424752 -> rgba.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x58524742 -> bgr0.
Jun 26, 2021 15:46:09.875 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Format 0x58424752 -> rgb0.
Jun 26, 2021 15:46:09.876 [0x7f0766186b38] Error — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Failed to create surface: 14 (the requested RT Format is not supported).
Jun 26, 2021 15:46:09.876 [0x7f0766186b38] Error — [Transcode/kkwmm5in6wo1klitj2956t60] [FFMPEG] - Unable to allocate a surface from internal buffer pool.
Jun 26, 2021 15:46:09.876 [0x7f0766186b38] Debug — [Transcode/kkwmm5in6wo1klitj2956t60] Codecs: hardware transcoding: allocating frames failed, error: Out of memory
Jun 26, 2021 15:46:09.141 [0x7f0766186b38] Error — [Transcoder] [AVHWFramesContext @ 0x7fab0692dec0] Failed to create surface: 14 (the requested RT Format is not supported).
Jun 26, 2021 15:46:09.142 [0x7f07666e6b38] Error — [Transcoder] [AVHWFramesContext @ 0x7fab0692dec0] Unable to allocate a surface from internal buffer pool.
Jun 26, 2021 15:46:09.142 [0x7f0766186b38] Error — [Transcoder] [h264 @ 0x7fab05b60640] Failed setup for format vaapi_vld: hwaccel initialisation returned error.

For those wondering what the latest supported release is, 1.22.3.4523-d0ce30438 is the latest 1.22 and works for me.

I’ve got a Gist here with a Dockerfile I’m using to extend from Plex’s official images. Hopefully sticking with the official image will make it more likely that the Plex folks take a look at it.

I also want to highlight the fact that HDR tone remapping needs to be disabled, as noted elsewhere in the thread. I spent a while debugging before spotting it :sweat:

Have there been any updates (recently) on HDR? I am looking to build a machine capable of transcoding, instead of just a local play library, and I already have a spare AMD mobo. I’d really hate to have to buy even more hardware just to catch the edge case for HDR (which I do have in my library).

If HDR still isn’t supported, is it possible to set Plex to fallback to software transcoding content when it is HDR? I’d be shooting for the highest end APU I can get (4750G or 5800G if available by then), which have passmark scores that are theoretically capable of at least one 4K/HDR transcode.

edit: By HDR fallback, what I mean is that from the above it sounded like user encountered errors when HDR tonemapping tickbox was enabled. I don’t mind if it falls back to software transcode for HDR, I just wanna be sure it won’t fail completely and error out.