# Guide: NVDEC Hardware Acceleration Patch for Plex Media Server on Linux

**URL:** <https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322>\
**Category:** Plex Media Server\
**Tags:** server-linux\
**Created:** [March 23, 2019, 8:02pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322 "2019-03-23T20:02:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 23, 2019, 8:02pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/1 "2019-03-23T20:02:41Z")

</div>

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](https://github.com/revr3nd/plex-nvdec/blob/master/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 - #329 by tijmenvn](https://forums.plex.tv/t/hardware-accelerated-decode-nvidia-for-linux/233510/329)

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
- You must have a NVIDIA card and drivers installed with support for NVDEC (see [https://developer.nvidia.com/video-encode-decode-gpu-support-matrix](https://developer.nvidia.com/video-encode-decode-gpu-support-matrix) for a list of supported cards)

## Installation

To install this patch perform the following:

1. Copy the plex-nvdec-patch.sh to your Plex server in any convenient to use directory.
2. Enable execution of the script by running: chmod +x ./plex-nvdec-patch.sh
3. 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.

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 23, 2019, 8:33pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/2 "2019-03-23T20:33:27Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![tijmenvn](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tijmenvn/32/96481_2.png) [@tijmenvn](https://forums.plex.tv/u/tijmenvn)\
**Post date:** [March 23, 2019, 9:50pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/3 "2019-03-23T21:50:43Z")

</div>

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:

```auto
#!/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?

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 24, 2019, 7:47pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/4 "2019-03-24T19:47:58Z")

</div>

An override attribute to the patch is a pretty good idea. I’ll work on that this week and get it merged in to the script

---

<div class="post-metadata">

**Author:** ![stringybird](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@stringybird](https://forums.plex.tv/u/stringybird)\
**Post date:** [March 25, 2019, 4:52am UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/5 "2019-03-25T04:52:36Z")

</div>

You mention 1 gig per stream for 4K but around how much would a regular 1080p h264 transcode take?

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 25, 2019, 3:24pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/6 "2019-03-25T15:24:03Z")

</div>

From a quick test, transcoding to 1080p h264 using both NVENC and NVDEC:  
1080p h265: 225MB  
1080p h265 10-bit: 358MB  
2160p (4K) h265 10-bit: 1386MB

Note this is all tested on a Quadro M2000

EDIT: Most devices can direct stream h264, but I’m seeing this also uses about 225MB of VRAM when forcing conversions with a 1080p h264 source.

---

<div class="post-metadata">

**Author:** ![grock1722](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/grock1722/32/97445_2.png) [@grock1722](https://forums.plex.tv/u/grock1722)\
**Post date:** [March 29, 2019, 2:58am UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/7 "2019-03-29T02:58:40Z")

</div>

For a rank amateur-- where does this script need to be put at on the Plex server? Any particular directory?

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 29, 2019, 3:11am UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/8 "2019-03-29T03:11:33Z")

</div>

Any directory. The script is standalone and not dependent on where it is saved or run from.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [March 29, 2019, 6:32am UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/9 "2019-03-29T06:32:05Z")

</div>

One word of caution if I may?

There is work being done on the transcoder so please don’t forget where you put that script.  
The new work may be negated by the option set there.

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 29, 2019, 6:35am UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/10 "2019-03-29T06:35:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bad-robot](https://avatars.discourse-cdn.com/v4/letter/b/e480ec/32.png) [@bad-robot](https://forums.plex.tv/u/bad-robot)\
**Post date:** [March 29, 2019, 9:48am UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/11 "2019-03-29T09:48:07Z")

</div>

this is a nice try , I like it.

---

<div class="post-metadata">

**Author:** ![wasylyna](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/wasylyna/32/3275_2.png) [@wasylyna](https://forums.plex.tv/u/wasylyna)\
**Post date:** [March 29, 2019, 3:03pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/12 "2019-03-29T15:03:01Z")

</div>

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](https://github.com/keylase/nvidia-patch)

---

<div class="post-metadata">

**Author:** ![modem7](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@modem7](https://forums.plex.tv/u/modem7)\
**Post date:** [March 30, 2019, 5:35pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/13 "2019-03-30T17:35:18Z")

</div>

I’m getting the following when I try to run it:

plex-nvdec-patch.sh: line 3: warning: command substitution: ignored null byte in input  
Patch has already been applied!

I’ve had to change /usr/lib/plexmediaserver etc to /usr/lib64/plexmediaserver as that’s where my install is.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [March 30, 2019, 10:46pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/14 "2019-03-30T22:46:59Z")

</div>

Which distro placed Plex in **/usr/lib64**?

---

<div class="post-metadata">

**Author:** ![modem7](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@modem7](https://forums.plex.tv/u/modem7)\
**Post date:** [March 31, 2019, 5:54pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/15 "2019-03-31T17:54:38Z")

</div>

Fedora in this case, but specifically the Amahi install of Plex, so there’s a chance they changed the install dir

I’ve posted the issue here: [https://github.com/revr3nd/plex-nvdec/issues/1](https://github.com/revr3nd/plex-nvdec/issues/1) as github should probably be a more apt location for issues

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 31, 2019, 8:29pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/16 "2019-03-31T20:29:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 31, 2019, 10:40pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/17 "2019-03-31T22:40:57Z")

</div>

> [@tijmenvn](#):
>
> 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?

You can do this now by defining -c hvec when calling the script. That will whitelist only hvec to use NVDEC.

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 31, 2019, 10:42pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/18 "2019-03-31T22:42:09Z")

</div>

> [@wasylyna](#):
>
> 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](https://github.com/keylase/nvidia-patch)

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

---

<div class="post-metadata">

**Author:** ![NiclasU](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/niclasu/32/92396_2.png) [@NiclasU](https://forums.plex.tv/u/NiclasU)\
**Post date:** [March 31, 2019, 10:56pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/19 "2019-03-31T22:56:20Z")

</div>

> -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**

Thanks!

---

<div class="post-metadata">

**Author:** ![revr3nd](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@revr3nd](https://forums.plex.tv/u/revr3nd)\
**Post date:** [March 31, 2019, 11:11pm UTC](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322/20 "2019-03-31T23:11:53Z")

</div>

From the help text. The options with nvdec support are:

```auto
Available codec options are:
  h264 (default) H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  hevc (default) H.265 / HEVC (High Efficiency Video Coding)
  mjpeg Motion JPEG
  mpeg1video MPEG-1 video
  mpeg2video MPEG-2 video
  mpeg4 MPEG-4 part 2
  vc1 SMPTE VC-1
  vp8 (default) On2 VP8
  vp9 (default) Google VP9

```

[Next page](https://forums.plex.tv/t/guide-nvdec-hardware-acceleration-patch-for-plex-media-server-on-linux/391322.md?page=2)
