keylase / nvidia-patch

This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs.
3.5k stars 274 forks source link

[Question] Support for Windows #9

Closed justinglock40 closed 5 years ago

justinglock40 commented 6 years ago

Any chance this patch can make its way to Windows? If so that would be greatly appreciated and well received. Primarily, plex doesn't allow decode on HW in LInux only encodes, but on windows you can encode/decode on HW with plex. So unlocked transcodes there would be awesome!

Snawoot commented 6 years ago

Take a look at this repo. I'm not sure if it is maintained now, but you can ask author.

tasoss commented 6 years ago

Any news on that @justinglock40 ? Thanks!

justinglock40 commented 6 years ago
No I was hoping that there was going to be. I found a gothic for windows, but it doesn’t have clear instructions and doesn’t seem to have support.

On Oct 18, 2018 at 17:37, <tasoss (mailto:notifications@github.com)> wrote:

Any news on that @justinglock40 (https://github.com/justinglock40) ? Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (https://github.com/keylase/nvidia-patch/issues/9#issuecomment-431187287), or mute the thread (https://github.com/notifications/unsubscribe-auth/AWD90Yvgrdn6NuikABGoz5k9RNKZEJeVks5umQKggaJpZM4XjMwQ).

tasoss commented 6 years ago

Thanks @justinglock40 I will let you know if case i find something useful.

niXta1 commented 5 years ago

@justinglock40 I'm also looking for that. I tried: https://github.com/sk1080/nvidia-kvm-patcher But I couldn't get past 2 streams anyway.

I've found a way to get NVDEC working in theory, compiling ffmpeg with the correct arguments. It's over my head, but someone in the plex forum got it to work. He was gonna add HDR to SHR tonemapping and put it up on GitHub but I haven't heard anything more after that.

justinglock40 commented 5 years ago

@justinglock40 I'm also looking for that. I tried: https://github.com/sk1080/nvidia-kvm-patcher But I couldn't get past 2 streams anyway.

I've found a way to get NVDEC working in theory, compiling ffmpeg with the correct arguments. It's over my head, but someone in the plex forum got it to work. He was gonna add HDR to SHR tonemapping and put it up on GitHub but I haven't heard anything more after that.

You look at this if you're trying to convert items: https://github.com/Collisionc/sickbeard_mp4_automator

niXta1 commented 5 years ago

I think it needs to be compiled with the exact same settings plex originally uses except for the enabling of NVDEC.

Edit: Oh, convert? No, I’m gonna use the capability I have to transcode if needed.

justinglock40 commented 5 years ago

What’s the link to the Plex forum that you mentioned ?

niXta1 commented 5 years ago

https://forums.plex.tv/t/hardware-accelerated-decode-nvidia-for-linux/233510?page=4

Snawoot commented 5 years ago

@justinglock40 @tasoss @niXta1

Let's try something. Assuming Win10 x64.

Option 1

  1. Download Nvidia driver 417.35.
  2. Download latest Win_1337_Apply_Patch tool
  3. Download this patch.
  4. Apply patch to C:\WINDOWS\system32\nvcuvid.dll using Win_1337_Apply_Patch tool
  5. Reboot

Option 2

  1. Get your C:\WINDOWS\system32\nvcuvid.dll to any Linux box and make backup.
  2. Run command sed -i.bk -e 's/\xff\x90\x80\x00\x00\x00\x84\xc0\x74\x08/\xff\x90\x80\x00\x00\x00\x84\xc0\x90\x90/g' nvcuvid.dll against your library.
  3. Place modified file back to your windows installation.
  4. Reboot

Option 2 may also work with other driver version with similar codebase.

Snawoot commented 5 years ago

Also, please report back your results.

justinglock40 commented 5 years ago

I’m not currently any windows right now

niXta1 commented 5 years ago

I’m guessing you will need to disable driver verification at boot also?

Snawoot commented 5 years ago

@niXta1 I didn't disabled anything at boot, so probably not. Maybe nvcuvid.dll is a user-space library and is not a part of actual device driver or signature is not verified for already installed files. Can't say for sure.

jaylex32 commented 5 years ago

I just tested the option 1 but no go!! thanks for trying to get this working in Windows 10

Snawoot commented 5 years ago

@jaylex32 Please provide more details what went wrong. Also have you tried to reboot system?

jaylex32 commented 5 years ago

@jaylex32 Please provide more details what went wrong. Also have you tried to reboot system?

I already had that same version installed in my pc and I just did the option 1 and then I reboot my pc then I try to transcode more than 3 movies with plex but after the second one it wont use the graphic card. can I run a different test?

Snawoot commented 5 years ago

@jaylex32 Thanks! I'm not familiar with Plex, but it might be internal Plex limitations applied to fit into usual NVENC limits. I run my tests with ffmpeg directly, so probably we need to consult Plex source code. Which Plex version do you use?

jaylex32 commented 5 years ago

@jaylex32 Thanks! I'm not familiar with Plex, but it might be internal Plex limitations applied to fit into usual NVENC limits. I run my tests with ffmpeg directly, so probably we need to consult Plex source code. Which Plex version do you use?

Im using plex server 1.14.1.5488 and plex does work with a graphic card that dont have limitations like the quatro!

jaylex32 commented 5 years ago

plex test it seems like is working now! edit never mind it still dont work!

justinglock40 commented 5 years ago

Nope!

Snawoot commented 5 years ago

Works for me with ffmpeg, so probably Plex should work also. Please make sure windows didn't restored patched .dll. I have System Restore disabled on my test VM. Screenshot

jaylex32 commented 5 years ago

Can you please do a test with Plex media server to see if we can find a fix for it? I have system restore off as well andthe patched file it's still there. Also there's not another location where theres a file nvcuvid.dll on? Thanks in advance!!

Snawoot commented 5 years ago

@jaylex32 I installed version 1.14.1.5488 and I have no "Use hardware acceleration when available" option in "Transcoder" settings. Probably Plex hides it if detects VM:

Hardware-Acceleration Streaming is not currently possible inside of virtual machines, as virtual machine hosts do not expose low-level video hardware to the guest operating system. While some virtual machines expose generic 3D acceleration to the guest OS as a virtual driver, this does not include support for accelerated video decoding or encoding.

(Source)

Despite my VM has real GPU, full access to it and ffmpeg works fine.

I suggest to download ffmpeg and run three transcoding sessions in order to distinguish clearly what is happening.

Sample command for ffmpeg transcoding using NVENC:

ffmpeg.exe -i Sample.avi -c:v h264_nvenc out.mp4
Snawoot commented 5 years ago

Or, using single ffmpeg instance, something like this:

ffmpeg -i input.avi -s 1280x720 -v:c h264_nvenc output1.mp4 -s 640x480 -v:c h264_nvenc output2.mp4 -s 320x240 -v:c h264_nvenc output3.mp4
jaylex32 commented 5 years ago

Thank you sir will do when I get home!!

niXta1 commented 5 years ago

Plex works fine inside VM's, dockers, etc., problem is, you have to have Plex Pass to get the hw transcoding option. I tried to patch the .dll both ways, and neither made Plex use more than two hw encodes.

Then I tried ffmpeg directly: ffmpeg -i input.mkv -s 320x240 -c:v h264_nvenc output1.mkv -s 640x480 -c:v h264_nvenc output2.mkv -s 320x240 -c:v h264_nvenc output3.mkv I'm gonna restore the .dll to make sure I get the error without the pach.

P.S. You can either sign up for a 30-day trial and get plex pass or use this build: https://1drv.ms/u/s!Avyoutvw3h6c3TJfpC4bwcl7RYVj I't will probably let you use hw transcoding

jaylex32 commented 5 years ago

Thanks! niXta1

niXta1 commented 5 years ago

I didn't get any errors but I did see the filesize of the output of the two first increasing, the third only got written when using the patched .dll. I could even hot-swap it and get the same results. It is not part of the core driver.

So the problem is now that Plex somehow identifies the capabilities without testing and determains that only two streams should be encoded at a time. I would argue that Plex should just test the capability instead of guessing, but it could possibly get it wrong if any encoding happend in the background. Still, unlimited encoding could be tested, if it fails, fall back to identification and guess.

Thanks to @Snawoot 👍 for your work on getting this to work on Windows.

jaylex32 commented 5 years ago

I know that if you use a NVIDIA Quadro P2000 it works fine with Plex without limitations but then again that video card is not nvenc lock so maybe Plex see that is for example a GTX 970 and it just locks the hw transcoding to 2!!

Snawoot commented 5 years ago

@jaylex32 AFAIK Plex users on Linux report success with nvidia-patch. Turns out Plex on Linux actually tests GPU real capabilities or old builds have no proactive thread limit.

Anyway it's a subject for Plex support forum then.

niXta1 commented 5 years ago

Hold your horses! It's working. I thought about it and why would you test the capability every time you run? You'd test/check at first start and if no hw changes after that you'd just assume it's the same. Makes sense. So I had a look around and found a few interesting reg entries and flag files.

So after you apply the patch do the following:

  1. Uninstall Plex Media Server.
  2. Delete the "Plex Media Server" folder in %UserProfile%\AppData\Local.
  3. Delete the registry entry "Plex Media Server" in Computer\HKEY_CURRENT_USER\Software\Plex, Inc.
  4. Reboot for good measure (I didn't).
  5. Install Plex Media Server.
  6. Profit.

nvencx3

Snawoot commented 5 years ago

@niXta1 Amazing! Thank you!

niXta1 commented 5 years ago

You can probably just remove a single/few reg entries/files to get it to work too, but I don't have time to find out. If someone wants to save their current library (untested), remove the reg: "MachineIdentifier", "ProcessedMachineIdentifier", "AnonymousMachineIdentifier". And delete everything in %UserProfile%\AppData\Local\Plex Media Server except for media, Metadata and Plug-ins.

And remember, always do backups.

jaylex32 commented 5 years ago

Hold your horses! It's working. I thought about it and why would you test the capability every time you run? You'd test/check at first start and if no hw changes after that you'd just assume it's the same. Makes sense. So I had a look around and found a few interesting reg entries and flag files.

So after you apply the patch do the following:

  1. Uninstall Plex Media Server.
  2. Delete the "Plex Media Server" folder in %UserProfile%\AppData\Local.
  3. Delete the registry entry "Plex Media Server" in Computer\HKEY_CURRENT_USER\Software\Plex, Inc.
  4. Reboot for good measure (I didn't).
  5. Install Plex Media Server.
  6. Profit.

nvencx3

With this method I will loose all my Plex data and is like starting fresh right? Thanks in advance!!

Snawoot commented 5 years ago

Delivered to master via #25

Snawoot commented 5 years ago

Closing issue since initial topic already covered.

Snawoot commented 5 years ago

@jaylex32 Yes, very much like fresh install. Probably someone can locate more specifically piece of data responsible for storing info about encoding capabilities, but it's a little bit out of scope.

Anyway, you may post here contents of your registry folder "Plex Media Server" and maybe someone will take a look. Don't forget to zap your private data like keys, IDs, etc on screenshot.

jaylex32 commented 5 years ago

Thank you for everything man!!!

jaylex32 commented 5 years ago

ok so I started fresh and did everything in the instructions and still doesnt work! now I lost my data and the mod doesnt work with plex

Snawoot commented 5 years ago

@jaylex32 Do ffmpeg test then and confirm if it is capable to encode more than two streams.

Svendsen18 commented 5 years ago

Seem to have a problem downloading the patch in option one, i only get a text box, do i need to replace nvcuvid.dll with that text or something ?

Snawoot commented 5 years ago

@Svendsen18 Right click on patch link and select "Save as...". Use resulting file with the Win_1337_Apply_Patch tool

Svendsen18 commented 5 years ago

Holy fucking shit i've just max'd my gtx 1070 out in emby for the first time ever, seems to work!

jaylex32 commented 5 years ago

Holy fucking shit i've just max'd my gtx 1070 out in emby for the first time ever, seems to work!

Did you save the patch as a txt file or as a 1337 format file? Thanks in advance!

Svendsen18 commented 5 years ago

"Download this patch." i just right clicked on "this patch" and used save link as and threw it on the desktop, used the tool patcher on that filer, then the apply patcher needs the nvcuvid.dll file which is in under C:\WINDOWS\system32\ Reboot.

jaylex32 commented 5 years ago

Could it be my graphics card? I have a GTX 970

Svendsen18 commented 5 years ago

couldn't say - im not very smart in this area :D

Snawoot commented 5 years ago

@jaylex32 It's unlikely. Very first version of nvidia-patch was developed and tested on GTX 970 (on Linux, but it doesn't matter).

niXta1 commented 5 years ago

Hey guys! I just did a quick check again, I might gotten tricked by a glitch in the Plex Dashboard :( I can't reproduce the 3 hw transcodings. Sorry all. I should have tried with more than 3 and for a longer time. The plex debug logs also gives a lot of information and it looks like it does test the capabilities before every stream starts. Another thing that I realized is that Plex is using an old version of ffmepeg and not nvenc but dxva2(/mf). We need to check if dxva2 follows suit with unlimited encodings.

Emby does use new ffdshow with nvenc, so that works exacly like the ffdshow nvenc tests we did.

Edit: dxva2 decoding uses: -hwaccel dxva2 Not sure if that includes mf encoding or if there's another switch to enable that?