keylase / nvidia-patch

This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unraid / Docker

Norrox opened this issue · comments

Hello!
Is this something we can use with UnRaid / Docker ?

It's not tested, but most likely this patch can be used with any Linux system, where Nvidia Driver can be installed. Speaking of Docker, you probably will have to patch driver on a host system.

So, it worth trying.

Ok, i have PLEX Inc docker working on Unraid 6.7.0-rc3 with Unraid-Nvidia Plugin mentionned above. I also create a script to enable NVDEC on PLEX since it's not yet supported (found on PLEX forum). Now, I would like to patch, but I got this error

./patch.sh Detected nvidia driver version: 410.78 d244655474572t252462463462 /opt/nvidia/libnvidia-encode-backup/libnvidia-encode.so.410.78 ./patch.sh : line 120: /usr/lib/x86_64-linux-gnu/libnvidia-encode.so.410.78: Read-Only File system

@pducharme It looks like patch.sh successfully made backup before library edit, but failed to apply changes because /usr filesystem is read-only. I'm not familiar with docker, but I think if /usr actually belong to host system (on top which docker is runned), you should run patch on host. If /usr belongs to immutable docker image, you have to edit image or create overlay.

In other words, you have to make /usr writable.

But there is always another option:

  1. Modify script a little, get patched library at some new location where creating files possible.
  2. Use mount --bind inside container to overlap it over according file in /usr. Probably there is docker-way to make such mount persistent or use /etc/fstab

I know this response pretty vague, but I have no unraid/docker instance and can only guess.

Ok, i have PLEX Inc docker working on Unraid 6.7.0-rc3 with Unraid-Nvidia Plugin mentionned above. I also create a script to enable NVDEC on PLEX since it's not yet supported (found on PLEX forum). Now, I would like to patch, but I got this error ...

@pducharme did you run this command on a container or on the host?

Did you try to do it inside the nvidia-plugin container? I think it should work there.

They does not want us to ask questions on the forum that can trigger nvidia to shutdown their driver plugin, so I guess we have to continue the discussion here :-)

It worked when I ran it on the host. Confirmed with 5 concurrent transcode on my Plex server 😀

Just found this news! https://forums.unraid.net/topic/77813-plugin-linuxserverio-unraid-nvidia/

That's the exact same plugin? Right? :)

@niXta1 sorry got alittle carried away :)

commented

It worked when I ran it on the host. Confirmed with 5 concurrent transcode on my Plex server grinning

Nice! Have you set this up in the user scripts plugin?

@rix1337 No, I just ran the patch.sh from the SSH on my Unraid host. Should I use this with User Scripts plugin? I thing it survive reboots, no?

Anyone know of any overviews of how many sessions are actually supported by each card? Wondering if I should use a 980 or a 1060, my box is coloed so don't have too much time to fiddle around with it.

Hi! See this link (also referenced on top page of this repo). 1060 has newer nvenc chip and supports more codec formats

@Snawoot I was thinking of a list over unlocked cards to see how many streams they would handle ^^ But yeah 1060 would probably be a good choice based on the wider support alone.

@Snawoot I was thinking of a list over unlocked cards to see how many streams they would handle ^^ But yeah 1060 would probably be a good choice based on the wider support alone.

@jimlei it’s hard to say unless you use the exact same video files. They handle between ~5-100 streams I guess.
H264 1080p 15000kbps ~15-30x depending on the card.
You can compare it to P2000. From maybe half of it to a few more. It all depends on codecs and bitrates.

It worked when I ran it on the host. Confirmed with 5 concurrent transcode on my Plex server 😀

How did you get it to install? I get

The kernel header file 'user/src/linux-4.19.20-unraid/include/linux/kernel.h' does not exist.

@jimlei 1050, 1060, 1070 does perform similar in encoding / decoding, not sure about 1080. Byt they share the same nvenc processor as i understand, and that is separate from the core gpu

@jimlei 1050, 1060, 1070 does perform similar in encoding / decoding, not sure about 1080. Byt they share the same nvenc processor as i understand, and that is separate from the core gpu

@Norrox ram also play a role.

@niXta1 ah yeah, i just saw somewhere a transcoding benchmark where the performance was very similar, I think it read that you will do alright with 2 gig or more ram on the gpu, I myself have ordered a 1050 ti with 4 gb to be sure, when I get my server up and running I will post some benchmarking results :-)

@niXta1 ah yeah, i just saw somewhere a transcoding benchmark where the performance was very similar, I think it read that you will do alright with 2 gig or more ram on the gpu, I myself have ordered a 1050 ti with 4 gb to be sure, when I get my server up and running I will post some benchmarking results :-)

Yes, you will be alright, but different video transcodings take different amounts of ram. This makes the ram run out sooner or later.
I also run a GTX1050Ti. It's pretty much amazing with the patch, doing 10 h264 like a walk in the park and plenty overhead and 2 4k h265 with less than 50% usage.
When it comes to h265, decoding is actually harder than encoding h264 many times.

Hey guys. I'm not getting this patch to work either... I get an error saying the following.

ERROR: Unable to find the development tool cc in your path; please make sure that you have the package 'gcc' installed. If gcc is installed on your system, then please check that cc is in your PATH.

Any ideas?

Wait, I'm an idiot. I was failing to install the original Drivers, when I'd already installed them via unraid.

Use unraid plugin to install the drivers, then run the script. Don't try to reinstall the drivers !

(Leaving original message below)
(Edited:Stupidity)
@EmmanuelZapata there is a DevTools plugin that will allow you to add the required packages. (gcc, binUtils etc)

However I get past that only to hit the Kernel issue reported above.
"The kernel header file 'user/src/linux-4.19.20-unraid/include/linux/kernel.h' does not exist."

Anyone any tips on how to get past this?

(Edited:Spellings)

Hello,

It seems these issues related to nvidia driver installation and kernel module build and unrelated to this patch. I'd recommend this video guide about Plex and Emby on Unraid with Nvidia Unraid plugin. There are also related post on Reddit.

Hello,
I recently started to tinker with unraid with plex in a docker. i was able to get nvidia transcoding to work and was able to apply the patch to allow more hardware transcodes but it doesn't survive reboot. i assume it has something to do with how unraid loads and runs from ram so changes do not get directly written to the flash drive. i cant seem to find how to make it stick does anyone have any knowledge with this

thanks

thanks i will check that out

commented

I just updated to unRaid 6.6.7 - I'm assuming I would have to apply the patch.sh file again? This won't survive a upgrade of the OS/Nvidia plugin?

@usafle As far as I know, if it is not added to your "userscripts", it doesn't even survives reboot. If it is added, it applies patch on every boot (since changes on docker filesystem are not persistent).

commented

@Snawoot I didn't even know (until now) that it wouldn't survive a reboot. Are there instructions somewhere about adding it to the userscript? I can't even remember how I applied this thing the first time I should have paid more attention to what I was doing....

It was fairly easy to add to a script , add new script , set it to at first array start only . Then you click on the script name it will give you the option to edit the script file then you open the patch.sh with sublime/notepad and copy the whole thing into the script file and save it . I think you can do a test run

Please, be careful with notepad - it is known to corrupt line endings #75

Yeah notepad is bad, it was supposed to be notepad ++

commented

I just went here and copied and pasted from within that instead of opening it up in Notepad++

Hopefully it works. Going to test it out now.

Update: Thanks @Snawoot and @Rooster237 for the help. It worked... apparently.

Just make sure your first line is not doubled.... it pre adds the #!/bin/bash

  • driver 418.43
  • quadro p400
  • unraid 6.6.7
  • linuxserverio plex docker

I have no issues patching the driver, have plex configured correctly and hardware transcoding enabled, nvidia-smi shows two process -- but then cpu takes over starting on the third stream (so patch isn't working). Is there anything I can do to diagnose this?

That's correct, you probably should add patch invokation into your "userscripts".

I have not restarted the server yet. I patched and then immediately tried plex.

Is there any way I can verify the session limit has been removed other than starting streams on plex? IE something I can do on the host (unraid) to check?

Yeah notepad is bad, it was supposed to be notepad ++

I used notepad++ and still had problems. I ended up having to download a script editor to copy/paste in to userscripts and it runs at Array Start flawlessly now.

Is there any way I can verify the session limit has been removed other than starting streams on plex? IE something I can do on the host (unraid) to check?

run the smi-nvidia command and it will show you if the driver is running, but unfortunately, to see if the patch.sh was successfully applied, the only way to tell is to see if you have 3+ streams running with (hw) at the end. If there's another way, I'm not aware of it.

@cannonf0dder thanks for the reply.

@usafle did you have to do anything other than applying the patch to get the sessions limit lifted?

@FoxxMD

You will need to get in to Plex and enable "Use hardware acceleration when available." but other than that, there's no additional config necessary that I'm aware of.

@cannonf0dder I have done that as well. I have no issues with hardware transcoding -- I see sessions running in nvidia-smi. But I'm still stuck on a max of 2 sessions. On the third stream no more sessions are shown in nvidia-smi and I see my cpu usage increase.

@FoxxMD

Have you checked the dashboard, where it shows all the concurrent streams? If you have three+ streams running, all of them should have (hw) at the end if they are using the hardware encoder.

@cannonf0dder thanks for tip. I will verify hw status on concurrent streams this evening (EST). I appreciate the help.

@FoxxMD

My pleasure! Feel free to ping me with any questions you may have. I'm not a developer or anything, just been using plex and unraid for a while, so just trying to help a fellow user. :)

Once you enable HW in plex settings go open up some browsers and incodneto tabs as well and log into your server and start a show and make it transcode it , I use two or more PCs to see how may I could get going but one pc with 4 or so tabs steaming should show you . Once you have them going you can just check your dashboard and it should show the streams and if they are HW transcoding or not , then bring up a terminal for the server and do the watch Nvidia-smi your should see all your streams there. I got mine working but I’m not sure how much is actually passed off to the gpu, I’ve had 7 streams going and all showed up as HW transcoding as well as when I displayed the watch nvida command only thing is my gpu never got over 20% usage while my cpu was rocking usage that could be audio transcoding but I would still have expected more handed off to the gpu, I have a 1070 in there so it’s beefy card haha

@cannonf0dder thanks for the offer. are you running 6.6.7? what card are you using?

@Rooster237 that's basically what I was doing to test as well. Are you running 6.6.7?

@FoxxMD

Version: 6.7.0-rc6 and a 1050TI.

Yeah I’m on 6.6.7

Remember, decoding uses the CPU if you don’t use the nvdec script.

@niXta1

The what now?

Yeah I stumbled upon that yesterday but can’t get that script to work in the docker container in unraid ...I tried most of the day playing with it and everything I did would just break streaming

commented

@cannonf0dder and @Rooster237 try this script. The "original" one never worked for me either. The one I just linked however, worked perfectly.

I finally got to give something back! :)

@usafle

I looked at that and the pathing is wrong for my deployment and for the life of me I can't find a folder named "Plex Transcoder". I might mess around with it tonight and see if I can make it work and not break stuff.

@niXta1 are you referring to the PMS forum linked in the readme? I was under the impression that was only needed for earlier builds of PMS. I am running 1.15.3.858 which should have ffmpeg with nvenc support?

I think I may need to take a closer look at this thread..

commented

@cannonf0dder you just plug that script into the user scripts - make a new script. It automatically searches your unraid install for the required files and makes the changes. Unless you're running some crazy docker version of Plex, it should work fine...

@usafle, I'm running linuxserver.io docker for Plex.

it will just find the running docker if i add it to the user scripts ?

commented

@cannonf0dder then it should work Just make a new script in the user script plugin. Copy/Paste and run it. You are the first person that I know of that is having an issue with that script....

@usafle, well I'm kind of a *nix noobie. I've messed around with some Ubuntu in the past, but never mesed with scripts or anything. This is the first time I've tried to add a script. I'll give that one a try tonight. :)

@usafle thanks for the heads up. I see that script is modified from the script in the PMS for unraid. I think this is the missing piece for me! Will test this evening...

NOTE: there is an updated script for unraid based on an updated script from the PMS thread that only attempts hw decoding if the codec is supported. unraid forum reference

Thanks going to check this out tonight

@niXta1 are you referring to the PMS forum linked in the readme? I was under the impression that was only needed for earlier builds of PMS. I am running 1.15.3.858 which should have ffmpeg with nvenc support? ...

@FoxxMD you have nvDEC and nvENC support in v15, but only nvENC is enabled in Plex by default.

To get nvDEC, which you really want (hevc decoding is often heavier than encoding for Plex), you need a script.
There are a few available, the best one is where you specify codecs, for ex. GTX1050Ti: "h264" "vc1" "hevc" "mpeg2video" “vp9”.
Look at the nvidia matrix too see DECODING support for your card.

There’s also a pre scripted docker container: https://hub.docker.com/r/adnanklink/plex-norelay-hwdecoding/
I hope it will be updated with a whitelist instead of the static script.

Can confirm using the script from here gets everything working. I had 6 concurrent sessions listed on nvidia-smi and all plex shows on dashboard had (hw) on them. Thanks for all the help everyone :) hopefully this will help someone else out!

@FoxxMD - awesome man!

Also, I tried the hwdecode script and it says it completed successfully, so thanks to @niXta1 and @usafle!

commented

@FoxxMD I'm confused now. The script that YOU linked, is that the same script that I linked just "tweaked" for codec specific?

@usafle yes, that's correct.

@usafle @FoxxMD

Excellent information. Worked flawlessly for me (I cross checked on unRaid forum thread as well...).

Thank you

commented

So there is a new version out of unraid/nvidia and the patch now fails, stating that the driver is not supported. Anyone else seeing this issue?

I can't freaking remember where I dropped the patch.sh in on my Unraid system initially. Anyone know where the patch.sh file goes for the Nvidia drivers? I'm currently searching my entire system for "patch.sh" via Krusader docker but it's taking forever and a day....

@usafle not sure where you put it, but I have it in 'settings -> user scripts' to run on array start.

commented

Thanks, but I'm looking for the actual location on the Unraid OS to put the 'patch.sh' file so I can run the command:

bash ./patch.sh

I forgot where the file goes.... sorry if I wasn't clear enough earlier... it was late, I was annoyed LoL

Go to settings -> user scripts, create a new script, paste the content, and manage it from there.

commented

I already have the user script... I need to run the place the patch.sh file in the same directory of the nvidia drivers to patch them.... that's what I'm asking.. where the NVidia drivers are located to patch on an Unraid OS....

Or am I really not doing this correctly at all?

You can run it from anywhere.

commented

Soon as I tried to run it from 'anywhere' on the OS, I got this:

./patch.sh: line 7: syntax error near unexpected token newline' ./patch.sh: line 7: '

When I did it the first time (and I wasn't paying attention to HOW I was doing it) I placed it next to the Nvidia drivers in Unraid. It worked.

you need to copy the rawfile and that text only. Sounds like you have bad characters in the content

i have 6.7.2 and all is working fine , i use two scrips the first one unlocks the driver and the second one is supposed to have the plex docker to use the transcoder2 so it will use the nvidia card for encode and decode at least thats how i understand it

#!/bin/bash
# halt on any error for safety and proper pipe handling
set -euo pipefail ; # <- this semicolon and comment make options apply
# even when script is corrupt by CRLF line terminators (issue #75)
# empty line must follow this comment for immediate fail with CRLF newlines

backup_path="/opt/nvidia/libnvidia-encode-backup"
silent_flag=''
rollback_flag=''

print_usage() { printf '
SYNOPSIS
       patch.sh [OPTION]...
DESCRIPTION
       The patch for Nvidia drivers to increase encoder sessions
       -s    Silent mode (No output)
       -r    Rollback to original (Restore lib from backup)
       -h    Print this help message
'
}

while getopts 'rsh' flag; do
  case "${flag}" in
    r) rollback_flag='true' ;;
    s) silent_flag='true' ;;
    *) print_usage
       exit 1 ;;
  esac
done

if [[ $silent_flag ]]; then
    exec 1> /dev/null
fi

declare -A patch_list=(
    ["375.39"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
    ["390.77"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
    ["390.87"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
    ["396.24"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["396.26"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["396.37"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g' #added info from https://github.com/keylase/nvidia-patch/issues/6#issuecomment-406895356
    # break nvenc.c:236,layout asm,step-mode,step,break *0x00007fff89f9ba45
    # libnvidia-encode.so @ 0x15a45; test->sub, jne->nop-nop-nop-nop-nop-nop
    ["396.54"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.48"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.57"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.73"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.78"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.79"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.93"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["410.104"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
    ["415.18"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x40\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["415.25"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x40\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["415.27"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x40\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["418.30"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x40\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["418.43"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x40\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["418.56"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x40\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["418.74"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x0f\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["430.09"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x0f\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
    ["430.14"]='s/\x00\x00\x00\x84\xc0\x0f\x84\x0f\xfd\xff\xff/\x00\x00\x00\x84\xc0\x90\x90\x90\x90\x90\x90/g'
)

declare -A object_list=(
    ["375.39"]='libnvidia-encode.so'
    ["390.77"]='libnvidia-encode.so'
    ["390.87"]='libnvidia-encode.so'
    ["396.24"]='libnvidia-encode.so'
    ["396.26"]='libnvidia-encode.so'
    ["396.37"]='libnvidia-encode.so'
    ["396.54"]='libnvidia-encode.so'
    ["410.48"]='libnvidia-encode.so'
    ["410.57"]='libnvidia-encode.so'
    ["410.73"]='libnvidia-encode.so'
    ["410.78"]='libnvidia-encode.so'
    ["410.79"]='libnvidia-encode.so'
    ["410.93"]='libnvidia-encode.so'
    ["410.104"]='libnvidia-encode.so'
    ["415.18"]='libnvcuvid.so'
    ["415.25"]='libnvcuvid.so'
    ["415.27"]='libnvcuvid.so'
    ["418.30"]='libnvcuvid.so'
    ["418.43"]='libnvcuvid.so'
    ["418.56"]='libnvcuvid.so'
    ["418.74"]='libnvcuvid.so'
    ["430.09"]='libnvcuvid.so'
    ["430.14"]='libnvcuvid.so'
)

NVIDIA_SMI="$(which nvidia-smi)"

if ! driver_version=$("$NVIDIA_SMI" --query-gpu=driver_version --format=csv,noheader,nounits | head -n 1) ; then
    echo 'Something went wrong. Check nvidia driver'
    exit 1;
fi

echo "Detected nvidia driver version: $driver_version"

if [[ ! "${patch_list[$driver_version]+isset}" || ! "${object_list[$driver_version]+isset}" ]]; then
    echo "Patch for this ($driver_version) nvidia driver not found." 1>&2
    echo "Available patches for: " 1>&2
    for drv in "${!patch_list[@]}"; do
        echo "$drv" 1>&2
    done
    exit 1;
fi

patch="${patch_list[$driver_version]}"
object="${object_list[$driver_version]}"

declare -a driver_locations=(
    '/usr/lib/x86_64-linux-gnu'
    '/usr/lib/x86_64-linux-gnu/nvidia/current/'
    '/usr/lib64'
    "/usr/lib/nvidia-${driver_version%%.*}"
)

dir_found=''
for driver_dir in "${driver_locations[@]}" ; do
    if [[ -e "$driver_dir/$object.$driver_version" ]]; then
        dir_found='true'
        break
    fi
done

[[ "$dir_found" ]] || { echo "ERROR: cannot detect driver directory"; exit 1; }

if [[ $rollback_flag ]]; then
    if [[ -f "$backup_path/$object.$driver_version" ]]; then
        cp -p "$backup_path/$object.$driver_version" \
           "$driver_dir/$object.$driver_version"
        echo "Restore from backup $object.$driver_version"
    else
        echo "Backup not found. Try to patch first."
        exit 1;
    fi
else
    if [[ ! -f "$backup_path/$object.$driver_version" ]]; then
        echo "Attention! Backup not found. Copy current $object to backup."
        mkdir -p "$backup_path"
        cp -p "$driver_dir/$object.$driver_version" \
           "$backup_path/$object.$driver_version"
    fi
    sha1sum "$backup_path/$object.$driver_version"
    sed "$patch" "$backup_path/$object.$driver_version" > \
      "$driver_dir/$object.$driver_version"
    sha1sum "$driver_dir/$object.$driver_version"
    ldconfig
    echo "Patched!"
fi

and

#!/bin/bash

############################### DISCLAIMER ################################
# This script now uses someone elses work!                                #
# Please visit https://github.com/revr3nd/plex-nvdec/                     #
# for the author of the new transcode wrapper, and show them your support!#
# Any issues using this script should be reported at:                     #
# https://gist.github.com/Xaero252/9f81593e4a5e6825c045686d685e2428       #
###########################################################################

# This is the download location for the raw script off github. If the location changes, change it here
plex_nvdec_url="https://raw.githubusercontent.com/revr3nd/plex-nvdec/master/plex-nvdec-patch.sh"
patch_container_path="/usr/lib/plexmediaserver/plex-nvdec-patch.sh"

# This should always return the name of the docker container running plex - assuming a single plex docker on the system.
con="$(docker ps --format "{{.Names}}" | grep -i plex)"

# Uncomment and change the variable below if you wish to edit which codecs are decoded:
#CODECS=("h264" "hevc" "mpeg2video" "mpeg4" "vc1" "vp8" "vp9")

# Turn the CODECS array into a string of arguments for the wrapper script:
if [ "$CODECS" ]; then
	codec_arguments=""
	for format in "${CODECS[@]}"; do
		codec_arguments+=" -c ${format}"
	done
fi

echo -n "<b>Applying hardware decode patch... </b><br/>"
	
# Grab the latest version of the plex-nvdec-patch.sh from github:
echo 'Downloading patch script...'
wget -qO- --show-progress --progress=bar:force:noscroll "${plex_nvdec_url}" | docker exec -i "$con"  /bin/sh -c "cat > ${patch_container_path}" 

# Make the patch script executable.
docker exec -i "$con" chmod +x "${patch_container_path}"

# Run the script, with arguments for codecs, if present.

if [ "$codec_arguments" ]; then
	docker exec -i "$con" /bin/sh -c "${patch_container_path}${codec_arguments}"
else
	docker exec -i "$con" /bin/sh -c "${patch_container_path}"
fi

Sorry that didnt copy in how i thought it would

thanks that looks better . there are two scripts there the first one ends at the AND

If wget is present on your docker container, you may try to download latest patch.sh directly with following command:

wget -O patch.sh "https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh"

otherwise if curl is present on your docker container, you may download patch.sh like this:

curl -o patch.sh -s "https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh"
commented

I'm truly sorry all. I was trying to place the actual PATCH.SH file into my UnRaid OS and then from a terminal window run the command
bash ./patch.sh

I didn't realize that simply deleting the old user script I had set up and then copying pasting the "new" patch.sh contents into a new user script would allow me to accomplish the same thing.

Hopefully I'm making sense as to what I was attempting to do incorrectly so someone else reading this will understand that you DO NOT have to do that.

I've copied/pasted the contents of the patch.sh into a new user script and all is working...

No idea where I got the notion that I had to put the actual patch.sh file "next to" the Nvidia driver on the Unraid OS....

I should really go back and delete all my posts so I don't look that stupid. LoL

Has the plex decoding side of this changed recently? I ask because I installed the patch into my unraid as above, (it works first time thankyou). But I did not install the second patch which above is said to be for decode. Nevertheless when I run nvidia-smi -s u (which I'm told displays the encode and decode activity), it DOES list decode, which would seem to mean the GPU is handling the decoding also. Any thoughts?

e.g.

gpu sm mem enc dec

Idx % % % %

0     0     0     0     0
0     4     1     0     0
0     3     2     9    14
0     7     7    28    34
0     9    10    39    47
0     8     9    38    43
0     8     9    35    41
0     8     9    35    43
0     8     9    37    43
0     8     9    38    44
0    10    11    47    53
0    10    12    49    55
0    10    12    48    53
0     9    10    42    48
0     9     9    38    44

Has the plex decoding side of this changed recently? I ask because I installed the patch into my unraid as above, (it works first time thankyou). But I did not install the second patch which above is said to be for decode. Nevertheless when I run nvidia-smi -s u (which I'm told displays the encode and decode activity), it DOES list decode, which would seem to mean the GPU is handling the decoding also. Any thoughts?

Plex does native nvdec since recently

Great, so for completeness for the next reader, the second script above is no longer needed.

I had created a user script with this following that runs at Start Up of Array.
wget -O patch.sh "https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
bash ./patch.sh

This automatically grabs the latest patch script that has the newest drivers editions included so you don't have to manually copy and paste the latest script.

commented

That's great. So just copy/paste the above into a new user script and that's it?

Edit: Guess not because I did that, ran the script and got these errors (that I have no idea what they mean because I'm a NOOB!)


Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '//.wget-hsts'. HSTS will be disabled.
--2020-02-01 15:48:53-- https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10693 (10K) [text/plain]
Saving to: 'patch.sh'

0K .......... 100% 14.0M=0.001s

2020-02-01 15:48:53 (14.0 MB/s) - 'patch.sh' saved [10693/10693]

--2020-02-01 15:48:53-- http://bash/
Resolving bash (bash)... failed: Name or service not known.
wget: unable to resolve host address 'bash'
--2020-02-01 15:48:54-- http://./patch.sh
Resolving . (.)... failed: Name or service not known.
wget: unable to resolve host address '.'
FINISHED --2020-02-01 15:48:54--
Total wall clock time: 1.1s
Downloaded: 1 files, 10K in 0.001s (14.0 MB/s)

I had created a user script with this following that runs at Start Up of Array.
wget -O patch.sh "https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh" bash ./patch.sh

This automatically grabs the latest patch script that has the newest drivers editions included so you don't have to manually copy and paste the latest script.

Nice! good idea, instead of having to reupdate the user script at each new version!

That's great. So just copy/paste the above into a new user script and that's it?

Edit: Guess not because I did that, ran the script and got these errors (that I have no idea what they mean because I'm a NOOB!)


Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '//.wget-hsts'. HSTS will be disabled.
--2020-02-01 15:48:53-- https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10693 (10K) [text/plain]
Saving to: 'patch.sh'

0K .......... 100% 14.0M=0.001s

2020-02-01 15:48:53 (14.0 MB/s) - 'patch.sh' saved [10693/10693]

--2020-02-01 15:48:53-- http://bash/
Resolving bash (bash)... failed: Name or service not known.
wget: unable to resolve host address 'bash'
--2020-02-01 15:48:54-- http://./patch.sh
Resolving . (.)... failed: Name or service not known.
wget: unable to resolve host address '.'
FINISHED --2020-02-01 15:48:54--
Total wall clock time: 1.1s
Downloaded: 1 files, 10K in 0.001s (14.0 MB/s)

Yup. That should handle it all automatically so you shouldn't have to worry about it when updating to new Unraid Nvidia. It appears you may have an issue executing the bash command. you could try with this script.

wget https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
chmod +x patch.sh
./patch.sh

EDIT: I see my issue was with my originial comment having the bash command on the same line. The bash ./patch.sh should be on a new line.

commented

EDIT: I see my issue was with my originial comment having the bash command on the same line. The bash ./patch.sh should be on a new line.

Tried that, and got this:

Script location: /tmp/user.scripts/tmpScripts/Newest Nvidia Patch/script
Note that closing this window will abort the execution of this script
/tmp/user.scripts/tmpScripts/Newest Nvidia Patch/script: line 2: unexpected EOF while looking for matching `"'
/tmp/user.scripts/tmpScripts/Newest Nvidia Patch/script: line 4: syntax error: unexpected end of file

It appears you may have an issue executing the bash command. you could try with this script.

wget https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
chmod +x patch.sh
./patch.sh

Tried that and got this:


Script location: /tmp/user.scripts/tmpScripts/Newest Nvidia Patch/script
Note that closing this window will abort the execution of this script
Will not apply HSTS. The HSTS database must be a regular and non-world-writable file.
ERROR: could not open HSTS store at '//.wget-hsts'. HSTS will be disabled.
--2020-02-01 16:31:34-- https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10693 (10K) [text/plain]
Saving to: 'patch.sh.2'

0K .......... 100% 3.61M=0.003s

2020-02-01 16:31:34 (3.61 MB/s) - 'patch.sh.2' saved [10693/10693]

Detected nvidia driver version: 440.44
Backup exists and driver file differ from backup. Skipping patch.

Not sure what the initial errors are up top at the start of the script... but the end result looks like it works?

I had created a user script with this following that runs at Start Up of Array.
wget -O patch.sh "https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh" bash ./patch.sh
This automatically grabs the latest patch script that has the newest drivers editions included so you don't have to manually copy and paste the latest script.

Nice! good idea, instead of having to reupdate the user script at each new version!

To simplify & sooth OCD, add --no-hsts

wget --no-hsts -O patch.sh "https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh"
bash ./patch.sh

Re: unneeded errors in logs just waste io/stor, Stop the NOISE.