Activating Plex hardware acceleration

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
I have a workaround for the issue where we can't restart the jail without losing /dev/dri. My caution is that when I tested this "over and over again", I caused FreeNAS to crash and reboot. While this might allow you to restart the jail without losing /dev/dri, still use caution and don't restart Plex "just because", as you might crash FreeNAS in the process.

1) Change the plex-ruleset.sh script to use ruleset 110, not 5; and change the Plex jail to use ruleset 110. Rationale: Visibility. You will see the incorrect devfs behavior on iocage restart this way, but not when the ruleset is 5. With ruleset 5, in failure case, you get "+ Removing devfs_ruleset: 5 OK" on stop followed by "+ Using devfs_ruleset: 5" on start. With ruleset 110, in failure case, you get "+ Removing devfs_ruleset: 110 OK" on stop, followed by "+ Using devfs_ruleset: 5" on start. This makes it immediately obvious when something went wrong. You can then either reboot FreeNAS or manually edit /etc/devfs.rules and restart the devfs service to mimic what the script does. Either way, make sure ruleset 110 is present before starting the Plex jail again.

2) To restart the Plex jail, use a sequence of "iocage stop plex" followed by "service devfs restart" followed by "iocage start plex". Stick that into a script if you like.

You should see "+ Removing devfs_ruleset: 110 OK" on stop, followed by "+ Using devfs_ruleset: 110" on start.

Again, caveat that running this repeatedly may very well crash FreeNAS. It did for me on ruleset 5; I didn't hammer on it with ruleset 110. My backup is running and I don't want to crash FreeNAS again.
 

ARRRRGGGGHHH

Dabbler
Joined
Mar 25, 2020
Messages
32
Dedication!

I'll just leave it alone for now i think...

Doesn't take tooo long to reboot the machine. And i generally don't restart my jails that often.

Just going through permissions pain setting things up again and changing how i did things (that's always a good idea. Introducing lots of changes at once!).
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
For those who have this working: Are any of you running FreeNAS on an MBR/BIOS boot install, or is everyone on GPT/EFI? One if the links in this thread suggests that GPT/EFI may be required for iGPU to work on SuperMicro boards, I'd like to understand whether that's so.
 

Jacopx

Patron
Joined
Feb 19, 2016
Messages
367
I have read the whole thread... I have an Intel Xeon E5-2670 and I’d like to ad a GPU to support the HW Transcoding, someone have suggestion?
 

ARRRRGGGGHHH

Dabbler
Joined
Mar 25, 2020
Messages
32
I have read the whole thread... I have an Intel Xeon E5-2670 and I’d like to ad a GPU to support the HW Transcoding, someone have suggestion?
Transcoding only works on Intel iGPUs.

That CPU does not appear to have one.

So you have no options for HW transcoding using FreeNAS.
 

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
I am super grateful for the hard work you guys put in. After following the instructions in post number 42, I seem to have it working, although it took a full reboot to see the dri and drm passed into the jail. I do see (hw) in the dashboard when a stream is being transcoded, and I do see it in the Tautulli interface as well.

I'm assuming on a jail restart, I'd run into the bug previously mentioned. I have not tried the ruleset 110 trick yet.

Now for my question, is Quick Sync the same in all Intel CPUs that support it? I'm seeing little to no benefit. I tried running two concurrent 4k to 1080p streams, and even before I started the second stream, my CPU was in the 95% range. I'm using a Core i3 6100T. I admit it's a pretty low-power chip. (that's precisely why I chose it, to sip as little power from the wall as possible) Perhaps I was too optimistic about the benefit of Quick Sync in such a lower-powered CPU?
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
Thanks for testing @JohnnyGrey ! Clearly not all GPUs are created equal. That i3 has a Gen 9 GPU, HD Graphics 530. I also have a Gen 9 GPU, HD Graphics P630. Mine uses maybe 4% CPU per 4k stream. The P630 in a 1225v6 is clocked at 1100Mhz and has 192:24:3 cores, the exact core config as a HD 530, just slightly lower clock on the 530.


The P630, on paper, should be slightly better I am thinking, not vastly better. This might be down to drivers. Still, getting even one 4k stream transcoded on an i3 is pretty damn good I'd say! You say you see little benefit: Was that i3 able to transcode a 4k stream before, using software?

Edit: I think the mystery is solved. I looked at wiki and found this entry for Kaby Lake. That suggests Kaby Lake for 4k transcode, not Skylake.
“The Kaby Lake line of processors was introduced in August 2016. New features: speed increases, support for 4K UHD "premium" (DRM encoded) streaming services, media engine with full hardware acceleration of 8- and 10-bit HEVC and VP9 decode.” Those features matter, because 4k BluRay uses HEVC encoding. I should probably clean up my PR, add this information, and reissue it to the guy who hosts the instructions.
Edit: Done, updated PR is in, asked kern2011 to please accept it.

Intel GPU list:

Intel QuickSync versions, which CPUs have them, and their capabilities:

Edit: Reasonable guidance might be Haswell (4th gen) or better for 1080p transcode, and Kaby Lake (7th gen) or better for 4k transcode. Skylake does support 8-bit HEVC, but only partial acceleration for 10-bit HEVC. The utility of transcoding HDR on the fly without HDR10 tone mapping is questionable and, there is clearly a large performance gap between 6th and 7th gen when it comes to 4k transcode.

Keep in mind you can always optimize for mobile in the background, which does the transcode ahead of time and stores a file.
 
Last edited:

ARRRRGGGGHHH

Dabbler
Joined
Mar 25, 2020
Messages
32
I run a G4560 (very cheap chip) for the above exact reasons. Check if your mobo supports it.

To get HEVC support.

Transcoding a 4K HEVC to 1080p on a mobile consumes approx 30% CPU usage.

Also you may not have the issue of dri/DRM going missing. So far we have only found it to be a Kaby Lake issue. Would be good to test for it though to see if 6th Gen CPU's also have the issue.
 

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
I run a G4560 (very cheap chip) for the above exact reasons. Check if your mobo supports it.

To get HEVC support.

Transcoding a 4K HEVC to 1080p on a mobile consumes approx 30% CPU usage.

Also you may not have the issue of dri/DRM going missing. So far we have only found it to be a Kaby Lake issue. Would be good to test for it though to see if 6th Gen CPU's also have the issue.
I’m running a SuperMicro X11SSH motherboard, so that should.

My transcodes are showing as being hardware accelerated, when they weren’t before, so it is actually working, but I think it all boils down to the Skylake chip, when both of you have Kaby Lake CPUs.

@Yorick, I was able to transcode a 4K stream just fine, but CPU usage was just as bad as it is now. I’m really regretting choosing a low-powered chip. Another 10-20 watts from the wall is nothing when the provided horsepower is so much greater.

edit: I’ll do some more testing later today when I get home from work. I’ll try and and find some similar 1080p files as well as some similar 4K files and get some simultaneous transcodes going while watching CPU usage.
 
Last edited:

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
Some further testing: Seems to be working fine transcoding 1080p to a mix of 720p formats. I have four concurrent streams going, three on my desktop (two browser, one Win10 app), and one on my phone. CPU usage as reported in FreeNAS gui bounces between 10%-40%, depending on whether the transcodes are being throttled. Still nowhere near the performance that you guys get with your Kaby Lake CPUs, but I still count this as a win. I'm sure the lack of 4K support is due to the older chip.

As for the bug: Confirmed. Upon the first restart of the jail, I have lost drm and dri passthrough, and three of the same transcodes now have FreeNAS pegged at 100% use. In fact the transcodes are throttling much less because the speed is much closer to 1.

1586379993511.png


EDIT: Bam, ruleset 110 works! Edited the script via SSH. Stopped the jail from gui. Edited jail ruleset from gui. Ran the script via SSH. Restarted devfs service via SSH. Started jail via SSH, and the devices are back!

1586381179790.png



As for the 4K problem, in my case, I have two potential solutions, or rather ways to avoid this: Either 1.) Separate 4K items into their own library, and revoke access to that library to my external userss, or 2.) Have Plex create optimized versions of the 4k files, so they won't have to be transcoded on the fly. Or if they do, they'll be transcoded from the lower bitrate files. I hope that's how it works.

(or 3, buy a new CPU lol)
 
Last edited:

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
Super, thank you for all that work!

To be clear, using ruleset 110 doesn’t sidestep the devfs bug, it just makes it very visible. With 110, IF you have the issue during jail start, you will see that a low numbered ruleset is being used instead. Then you can stop the jail, restart the devfs service, and start the jail again to fix the issue.

As for 4k content and mobile users, you can put a 1080p version alongside and Plex will use it. In fact, if your content is 4k HDR, the best thing you can do for mobile users is to place the regular 1080p version, if it came in the box set, alongside it. HDR to SDR transcode still isn’t awesome.

You can also tell Plex to optimize in the background, it will place a second file alongside and again, use the file that is most appropriate. You can also tell Plex whether to go for speed or quality when creating the optimized transcode. It is remarkably clever that way.
 

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
Super, thank you for all that work!

To be clear, using ruleset 110 doesn’t sidestep the devfs bug, it just makes it very visible. With 110, IF you have the issue during jail start, you will see that a low numbered ruleset is being used instead. Then you can stop the jail, restart the devfs service, and start the jail again to fix the issue.

As for 4k content and mobile users, you can put a 1080p version alongside and Plex will use it. In fact, if your content is 4k HDR, the best thing you can do for mobile users is to place the regular 1080p version, if it came in the box set, alongside it. HDR to SDR transcode still isn’t awesome.

You can also tell Plex to optimize in the background, it will place a second file alongside and again, use the file that is most appropriate. You can also tell Plex whether to go for speed or quality when creating the optimized transcode. It is remarkably clever that way.

I have most of my 4K titles queued up in Plex to create some 1080p files. You have a good point, I could probably get a better looking file by ripping from an actual 1080p source.

Is there anyway to see what actual ruleset was loaded if the jail is started from the GUI? Even so, if I ever need to stop the jail, I’ll do it from the command line from now on. Do I need to rerun the script in between, or is restarting the devfs service enough?

Now I’m debating getting a new CPU. I don’t think I’ll have much luck sourcing a used e3 v6, and I’m not sure if the new ones I see are inflated in price. There are, however, a decent number of i3 7100’s up on eBay for $50-85. Given that I’m rocking a low-powered variant of the 6100, I’d be looking at a substantial clock speed bump too.

Again, thanks for all your prior troubleshooting! Now I can’t wait for the day that Plex brings NVENC/NVDEC to FreeBSD.
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
Is there anyway to see what actual ruleset was loaded if the jail is started from the GUI? Even so, if I ever need to stop the jail, I’ll do it from the command line from now on. Do I need to rerun the script in between, or is restarting the devfs service enough?

Not visible from GUI. No need to run the script, a simple "iocage stop plex;service devfs restart;iocage start plex" does the job. I have that in a script called restart-plex.sh, and I arguably could have made that an alias instead. More for testing, I really don't need to restart plex once it's up and running.

Now I’m debating getting a new CPU. I don’t think I’ll have much luck sourcing a used e3 v6, and I’m not sure if the new ones I see are inflated in price. There are, however, a decent number of i3 7100’s up on eBay for $50-85. Given that I’m rocking a low-powered variant of the 6100, I’d be looking at a substantial clock speed bump too.

I think that i3 7100 off eBay is a great idea. The Xeon is 270 new on NewEgg, and the same on eBay. Ouch.

Now I can’t wait for the day that Plex brings NVENC/NVDEC to FreeBSD.

I'll offer a bet that TrueNAS SCALE (the Linux version) will be ready before Plex brings NVidia support to FreeBSD. For, say, a 6-pack of something good and local? I can offer TreeHouse :).
 
Last edited:

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
...I really don't need to restart plex once it's up and running.
Agreed. If I ever need to restart Plex, it's the service, not the entire jail.

I think that i3 7100 off eBay is a great idea. The Xeon is 270 new on NewEgg, and the same on eBay. Ouch.
I do too. I'm keeping the ebay'd 7100 in consideration, but in the meantime I just sent a PM to someone selling an i3 7300 engineering sample for $50 in the HardwareSwap subreddit. Hopefully that pans out.

I'll offer a bet that TrueNAS SCALE (the Linux version) will be ready before Plex brings NVidia support to FreeBSD. For, say, a 6-pack of something good and local? I can offer TreeHouse :).
I wish I could say I was a connoisseur of the "good" stuff, but alas, I am not. If it's not a Coors Light, then it's a White Claw or a Not Your Father's Root Beer.
 

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
My apologies for any ongoing double-posting.

I just swapped in my i3 7300, and I see no change. It seems no HEVC 10 4K files are utilizing hardware transcoding. It's still eating up 95-99% of my CPU with a single stream. I can only see hardware transcodes with files that aren't HEVC.

Going from CPU gen 6 to gen 7 should use the same Intel driver, correct? I am on the latest version of Plex, too.

What's even stranger, is despite the identical CPU usage, I saw a hardware transcode with the 6100T, but not with the 7300.

First image is the HEVC 10 file with the 6100T:
HEVC 10 Transcode on 6100T (2).png


Now the same settings and same file with the 7300. Notice the lack of (hw)?
1586815491430.png


Any idea on why this is all messed up guys? Even if I don't get this working right away, I still gained a decent clock-speed bump for only $50usd.
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
Interesting. I don’t know what the Intel media driver package does when it gets installed. It may be worth stopping the plexmediaserver service, uninstalling the Intel driver package in the jail, reinstalling it, and then restarting the plexmediaserver package.

I am assuming /dev/dri is visible inside the jail. If it’s not, that needs to be remedied first.
 

zperetz

Dabbler
Joined
Dec 2, 2017
Messages
36
Interesting. I don’t know what the Intel media driver package does when it gets installed. It may be worth stopping the plexmediaserver service, uninstalling the Intel driver package in the jail, reinstalling it, and then restarting the plexmediaserver package.

I am assuming /dev/dri is visible inside the jail. If it’s not, that needs to be remedied first.
Actually, all necessary libraries are already included in PMS installation. /dev/dri visibility should be enough...
Code:
root@PMS-Plexpass:/ # ls -la /usr/local/share/plexmediaserver-plexpass/lib/dri/
total 108050
drwxr-xr-x  2 root  wheel          4 Apr 10 04:39 .
drwxr-xr-x  3 root  wheel         49 Apr 10 04:39 ..
-rw-r--r--  1 root  wheel    7926440 Apr  9 14:07 i965_drv_video.so
-rw-r--r--  1 root  wheel  188734992 Apr  9 14:07 iHD_drv_video.so
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
Actually, all necessary libraries are already included in PMS installation. /dev/dri visibility should be enough...

Have you tested this? So far, all instructions we have included installation of an Intel package.
 

JohnnyGrey

Dabbler
Joined
Jul 1, 2017
Messages
45
This is (almost) official opinion from here. I had no time to test it yet.

Confirmed! Intel driver is not needed! Following your advice, @Yorick, I decided to stop the plexmediaserver_plexpass service, and uninstall the Intel drivers. Instead of reinstalling right away, I instead decided to test @zperetz latest theory, and lo and behold, it's still hardware transcoding!

As for my specific HEVC 10 issue, I've done some more testing, and I've narrowed it down to a few titles. It seems any 4K file that Plex labels as "4K (HEVC Main 10 HDR)" transcode perfectly fine, and I'm only seeing 20-30% system CPU usage. (The image looks like crap, but that's to be expected) However, anything that Plex labels as "4K (HEVC Main 10)" (no HDR), gets transcoded via software. This doesn't really strike me as an Intel limitation, but perhaps a Plex bug?

I'm still not seeing as low of a CPU usage as you are, but perhaps that just shows us that, as you said, not all CPUs are created equal.

1586899763245.png
 
Last edited:
Top