Enable Hardware acceleration support for BSD based Plex Servers

And reading this I now see I forgot to tell you about driver install… my bad… not sure u need all of that but at least libva-intel-driver

After you pointed me to the article, a post there fixed it for me. DRM needs to load before the kernel boots and so drm_load=“YES” needs to be added to the loader.conf. I had to move some conflicting modules out the kernel so it would load correctly. Because the rc.conf entry does not work on XigmaNAS, a postInit command script to run “kldload i915kms” loads the modules. After which my server now supports HW transcoding. I’ll post instructions on enabling HW transcoding on XigmaNAS later, at which point you may want to sticky the post. :slight_smile:

2 Likes

That shouldn’t be needed though… when you load i915kms that does it for you… this is what I put in my rc.conf (the devfs line is for the jail setup)

kld_list="/boot/modules/i915kms.ko"
devfs_load_rulesets="YES"

The other important step is making sure the correct driver is installed (and I suggest u install only the one you do need):

pkg search libva-intel | grep driver
libva-intel-driver-2.3.0_3     VAAPI legacy driver for Intel GMA 4500 (Gen4) or newer
libva-intel-hybrid-driver-1.0.2_1 Hybrid VP8 encoder and VP9 decoder for Intel GPUs
libva-intel-media-driver-18.4.1 VAAPI driver for Intel HD 5000 (Gen8) or newer

I only needed libva-intel-media-driver-18.4.1 (EDIT should be the same for you has the processor has Intel HD 610, gen9 - this is the intel HD gen not the cpu it self in case it confuses you)

And of course make sure plex user is in the video group (this is a step some of this posts are missing and I have pointed out)

The problem is, drm.ko isn’t loaded soon enough and thus will not allow applications to detect the driver. When drm.ko is loaded before the kernel boots, it will have an address low enough to allow applications to detect the driver. Then i915kms.ko can be loaded from rc.conf, or in XigmaNAS’s case loaded through a command during postinit. No additional drivers need to be installed. At least in my case I didn’t need to install any additional packages for my Intel CPU. Confirming that HW transcoding is actually working, in addition to Plex now displaying “(hw)” next to the transcode status, CPU usage is down 50%.

See Plex in FreeNAS jail and vaapi Intel hardware acceleration support which applied to my situation. Post boot the address I had was 0x187 and when loaded from pre-boot it then got 0x17. Which seemed to work. XigmaNAS is essentially FreeBSD but there’s a lot of custom stuff and mods in there so it is slightly different. But if it works… In any event, I will be working with the XigmaNAS devs to make the Plex extension installer also enable HW transcoding.

Hum I see well as long as it works… Feels a bit more complicated that way than just installing the driver, and for the package in xigmanas it might be easier to make it depend on the driver … It could even be done in freebsd’s port, and they can also had an option to make sure plex is in the video group, all of that could just be in a flavour port (plexmediaserver flavour HWT if you will)

I honestly think it’s quite simple. The problem is a majority of XigmaNAS users run on an embedded platform which means packages installed via pkg are wiped when rebooted as the root disk is all preloaded into RAM before being booted. Which means installs are never persistent. Full platform users like me can install to the root disk without losing these changes. This is why a Plex installer exists for XigmaNAS. We just need to modify it to allow the kernel modules to remain persistent, and then get the kernel loader to preload drm.ko.

Right now the install instructions for XigmaNAS Full platform users are:

  1. Install Plex with the OBI (one button installer)
  2. Run “pkg install drm-fbsd12.0-kmod”
  3. Under the “Access”, Goto “Users & Groups”->Groups and add a new group called “video” with ID 44.
  4. Goto “Users” and add “plex” to the “video” group.
  5. Under “System”, goto “Advanced”->“loader.conf” and add an entry. Variable name: “drm_load” and value: “YES” no quotes. Save and apply.
  6. Goto “System Commands” and add the command “kldload i915kms” to load during “PostInit”
  7. Finally, goto the “File Manager” and navigate to the directory “/boot/kernel” and delete the files: “drm.ko”, “drm2.ko”, and “i915kms.ko”. This is so the kernel loader loads the correct files found in “/boot/modules”
  8. Reboot the server

This of course applies to Intel based systems. Obviously the OBI will be modded to do this automatically.

2 Likes

Like I said whatever works for you the better, but this seems somewhat inconsistent… how can you then install drm-fbsd12.0-kmod and not lose it? It seems then pkgs might be saved to another place?

Also can the OBI edit boot/loader.conf too? And remove kernel modules? that seems dangerous but ok…

In the end of the day however its about what works best for you, and if this is the better way and works, awesome!

I super glad you got it working actually cause this is not a system we official support (yes its freebsd based but you never know) and this seems to work fine!

I have a full install so everything is persistent. Embedded platforms will lose installed packages. In any event the OBI will probably override the kernel a bit. I just went in and tampered with myself and was happy when it successfully rebooted. :slight_smile:

2 Likes

I can confirm success on an Intel NUC8i5 and FreeBSD 12.0-RELEASE. All I had to do was install the drm-current-kmod package, which also pulled in gpu-firmware-kmod.

After that, followed the pkg-message of adding:

kld_list="/boot/modules/i915kms.ko"

… into /etc/rc.conf, and ‘plex’ user to the ‘video’ group (in /etc/group).

Rebooted the NUC and launched some 1080p h265 to h264 transcodes via the web client, and Tautulli confirmed they were all HW transcoding. I had 9 running in parallel, and they were all playing smoothly. I’m not sure what the limit is, but that’s more than enough for my usage. Some sort of gpu-top to see how busy the Intel 655 was would have been nice.

Do you have a headless setup?

Yes. It’s actually in an esxi VM with the GPU passthrough’d to it. No X11 stuff installed.

I have similar issue with my FreeBSD 12 setup. I can confirm that VAAPI works perfectly in my FFMPEG. vainfo shows:

error: XDG_RUNTIME_DIR not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.4.1
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /usr/local/lib/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_4
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.4 (libva 2.4.1)
vainfo: Driver version: Intel iHD driver - 1.0.0
vainfo: Supported profile and entrypoints
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileNone                   :	VAEntrypointStats
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointFEI
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointFEI
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointFEI
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointFEI
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointVLD

But plexmediaserver shows:

ay 22, 2019 23:28:30.260 [0x80bf88000] Error — [FFMPEG] - Failed to initialise VAAPI connection: -1 (unknown libva error)

plex user in video group. Obviously I have latest pkgs installed otherwise I won’t get it work.

However I want to note that I am using iHD driver as my CPU is a Coffee Lake.

And I can use ffmpeg command to transcode via hardware. Normally I got like 11x - 12x transcoding performance with around 10% CPU utilisation only.

@Support team - I found the issue now. There are 2:

  1. Neither your installation package downloaded from website or the one from freebsd package repository have the right VAAPI driver - the driver should be iHD_drv_video.so.
  2. On my FreeBSD 12.0 with latest Intel VAAPI driver installed, both iHD and i965 works but that is on libva version 1.4
  3. The environment is forced to i965_drv_video driver, which only works with selected Intel card for the version that you’ve embedded, which is libva version 1.1.

I got ZFS, so either ubuntu or FreeBSD would work. Would it be working better on Ubuntu?

Adding 1 more point, just checked, only iHD driver supports HEVC decode and encoding. I do have those kinds of video. Ideally iHD driver is the way to go.

Ok, I see what you mean now. HW transcoding was working fine while I was setting it up at my desk. But after moving it to my rack, HW transcode stopped working. I plugged in a monitor to test, rebooted the plex VM, and it works again. Looks like I’ll need to use a dummy HDMI plug.

any updates?

Sorry to bump an old thread, but I too am trying to get Hardware Acceleration working on FreeBSD, XigmaNAS to be specific. I’m running XigmaNAS version 12.0.0.4.6766 which is built on FreeBSD 12.0-RELEASE-p6. I have an Intel Core i5 3570K CPU on an Asus P8H61-I R2.0 motherboard with 16GB RAM. My Plex version is 1.16.4.1469. From what I can tell looking through documentation, my CPU supports Quick Sync, therefore is supported by Plex. According to the Intel support page, my CPU has HD4000 integrated graphics. I have ticked the check box to “Use hardware acceleration when available” on the Home -> Settings -> Transcoder page, yet viewing the Activity -> Dashboard page, my CPU is not hardware transcoding. I have done some searching and found this:

pkg search libva

libva-2.5.0 VAAPI wrapper and dummy driver
libva-glx-2.5.0 VAAPI wrapper for GLX
libva-intel-driver-2.3.0_4 VAAPI legacy driver for Intel GMA 4500 (Gen4) or newer
libva-intel-hybrid-driver-1.0.2_2 Hybrid VP8 encoder and VP9 decoder for Intel GPUs
libva-intel-media-driver-19.3.p1 VAAPI driver for Intel HD 5000 (Gen8) or newer
libva-utils-2.5.0_2 Collection of tests and utilities for VAAPI
libva-vdpau-driver-0.7.4_9 VDPAU-based backend for VAAPI
libvanessa_adt-0.0.9_1 Library that provides ADTs (queues, dynamic arrays, and more)
libvanessa_logger-0.0.10_1 Library that provides a generic logging layer
libvanessa_socket-0.0.12_1 Library that provides a simple layer for TCP/IP socket operations

I have to wonder if a driver for my integrated GPU is not available on my installation. I notice the libva-intel-driver-2.3.0_4 says it supports HD4500 on Gen4 CPUs and libva-intel-media-driver-19.3.p1 says it supports HD5000 on Gen8 CPUs, but I don’t see a driver for HD4000 for Gen3 CPUs, even though Gen2 CPUs and newer are supported.

Does anyone have any ideas how i might be able to resolve this, or if this is even the problem?

Sorry for the late reply, I cant comment much on XigmaNAS but you should only need to install the most recent drm-kmod package and make sure to load that one in rc.conf or similar. You will need to find how to do it for XigmaNAS on your own, but I imagine it’s similar to FreeBSD.

Other them that plex user needs to be added to the video group.
You don’t neened to install any overland drivers, plex should handle that on its own.

Thanks for the reply mikec_pt. I tried this:

pkg search drm-kmod

drm-kmod-g20190710 Metaport of DRM modules for the linuxkpi-based KMS components

It looks to be already installed?

1 Like