UPDATE: Plex has added native support for NVDEC on Linux! This patch is now redundant and no longer needed if you are using a recent version of Plex!
All, there is a pretty lengthy thread going in the feature request section of the forums to make this a native feature, but recently the PMS libraries have been updated enough to insert this support with a simple patch. I have posted a copy of a script to install a patch to enable NVDEC support on Linux at the GitHub repository below: plex-nvdec-patch.sh
This has been tested by many users thus far and found to work rather well. This is a major feature if you plan to transcode 4K video content and do not have an Intel CPU with onboard GPU (VAAPI acceleration). I would like to have this thread become the support thread for this topic as more users test the feature so we all can get the best working patch for us all.
EDIT: Credit where it is due, the contributors to the feature request thread have all made this possible thus far. The feature request thread can be found here to add this support natively: Hardware Accelerated Decode (Nvidia) for Linux
Here’s a copy of the readme for reference:
This patch is designed to enable NVDEC functions on Linux installations of Plex Media Server version 1.15.1.791 and later. This is a stopgap patch to enable the feature until Plex officially supports the feature natively.
Requirements
Plex Media Server must be a least version 1.15.1.791
Copy the plex-nvdec-patch.sh to your Plex server in any convenient to use directory.
Enable execution of the script by running: chmod +x ./plex-nvdec-patch.sh
Execute the script with sudo: sudo bash -c ./plex-nvdec-patch.sh
Note that you must rerun this patch every time PMS is updated.
If you need to remove the script, you can either manually reinstall PMS or run the script with the --uninstall parameter.
So to follow up with a few notes and history. This patch will insert the ‘-hwaccel nvdec’ attribute to transcodes when calling the Plex Transcoder.
From the prior thread, this will insert said attribute for all source files except mpeg4 format. mpeg4 has reportedly had decode issues running through nvdec, but I personally have not tested this myself to verify.
When it comes to 4K content on HVEC, you should expect approx. 1GB of VRAM to be used per transcode, so your VRAM will very likely be a limit if you expect to do multiple streams. H264 content is much less intense on the VRAM in this instance if you are willing to tolerate a lack of HDR and a 25% increase in file size.
Another common limitation at this point with 4K content is usually audio transcoding. Audio transcodes are limited to a single thread/CPU. So, if a 7 channel TRUEHD codec cannot be directly streamed to your player, then PMS will have to transcode it and will likely choke due to not being able to multi-thread the audio transcode.
I do appreciate all other comment here so we can all get the best info together to enable this feature to the fullest and we all can be killing it with 4K content in our libraries!
Nice work on making this an easy to install script!
If there are people who want to make this script even better, maybe consider making some install options.
For example, in my usecase. I have plenty of CPU horses to do all h264 transcodes on my cpu (and have better quality output compared to HW transcoding). But I want to run my HEVC content off of my GPU. Since I have a handful of 4K HEVC 10bit movies/tv-shows. I don’t want all transcodes to slow down, when someone fires this 4K movie up with hardware that needs transcoded output. So I’m now testing the script as follows:
#!/bin/bash
marap=$(cut -c 10-14 <<<"$@")
if [ $marap == "hevc" ]; then
exec /usr/lib/plexmediaserver/Plex\ Transcoder2 -hwaccel nvdec "$@"
else
exec /usr/lib/plexmediaserver/Plex\ Transcoder2 "$@"
fi
As also discussed in original thread. This way all cpu intensive transcodes are handles by my Nvidia GPU and all normal H264 content is handles by my CPU with better quality and saving VRAM for other HEVC transcodes
You could for example use a --hevc-only parameter on the install script for if people want to use it for hevc only content.
I’m just a beginning engineer and don’t really trust myself into making these commits myself. I do like to help by submitting ideas
EDIT:
script above obviously only works for the decoder, in other words, everything HEVC will be decoded by the CPU and encoded by the GPU. Still not optimal, anyone a clue how I could get bash script for Plex to only use HW accelerated encode for HEVC streams?
That is a good call out. I have a vision to have the wrapper script parse the attributes for the ones we care to identify. I just need the time to do it!
A rollback function in the script would be a good idea as well… More on the todo
It may be ideal to reference and link to keylase’s patch which removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs: https://github.com/keylase/nvidia-patch
Thank you all for the feedback. I’ve pushed an update to the script today to account for a few items:
-Added help output
-Added arguments to define transcoder path
-Added logic to check if plex is in /usr/lib64 instead of /usr/lib
-Added logic to whitelist codecs to enable NVDEC for. Default codecs are now: h264, hevc, vp8, and vp9
Still on the TODO:
-Update wrapper to identify the codec via arugment as opposed to assuming by position
I’m not a developer, so I’m not sure what the licensing implications are by including this, but it is highly recommended. I’ll add a note to the readme
-Added logic to whitelist codecs to enable NVDEC for. Default codecs are now: h264, hevc, vp8, and vp9
Thanks!
I have been asking for this for a month, no one seemed to know/care how to white list them. Did it myself and ended up with a huge ugly script…
You want to add all these as they are the officially supported ones: MPEG-2, VC-1, H.264 (AVCHD), H.265 (HEVC), VP8, VP9