

This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs.
This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs.
 
This patch removes restriction on maximum number of simultaneous NVENC video encoding sessions imposed by Nvidia to consumer-grade GPUs.
Main target operating system is **GNU/Linux**, but for **Windows** support see [**win**](win).
The patch for Nvidia drivers to remove NVENC session limit
-s Silent mode (No output)
-r Rollback to original (Restore lib from backup)
-h Print this help message
-c VERSION Check if version VERSION supported by this patch.
Returns true exit code (0) if version is supported.
-l List supported driver versions
```
## Step-by-Step guide
Examples are provided for driver version ${example_driver_version}. All commands executed as root.
### Download and install driver
Skip this step if you already have installed driver with version supported by this patch (from distro packages, for example).
Make sure you have kernel headers and compiler installed before running Nvidia driver installer. Kernel headers and compiler are required to build nvidia kernel module. Recommended way to do this is to install `dkms` package, if it is available in your distro. This way `dkms` package will pull all required dependencies to allow building kernel modules and kernel module builds will be automated in a reliable fashion.
```bash
mkdir /opt/nvidia && cd /opt/nvidia
wget ${example_driver_url}
chmod +x ./${example_driver_file}
./${example_driver_file}
```
### Check driver
```bash
nvidia-smi
```
Output should show no errors and details about your driver and GPU.
### Patch driver
This patch performs backup of original file prior to making changes.
```bash
bash ./patch.sh
```
You're all set!
## Rollback
If something got broken you may restore patched driver from backup:
```bash
bash ./patch.sh -r
```
## Docker support
It is possible to use this patch with nvidia-docker containers, even if host machine hasn't patched drivers. See `Dockerfile` for example.
Essentially all you need to do during build is:
* `COPY` the `patch.sh` and `docker-entrypoint.sh` files into your container.
* Make sure `docker-entrypoint.sh` is invoked on container start.
`docker-entrypoint.sh` script does on-the-fly patching by means of manipulating dynamic linker to workaround read-only mount of Nvidia runtime. Finally it passes original docker command to shell, like if entrypoint was not restricted by `ENTRYPOINT` directive. So `docker run --runtime=nvidia -it mycontainer echo 123` will print `123`. Also it can be just invoked from your entrypoint script, if you have any.
## Benchmarks
* [Plex Media Server: nVidia Hardware Transcoding Calculator for Plex Estimates](https://www.elpamsoft.com/?p=Plex-Hardware-Transcoding) - useful benchmark of achieved simultaneous transcodes with various stream quality and hardware with patched drivers.
* [Original post in Russian](https://habr.com/post/262563/)
* [3rd party English translation](https://weekly-geekly.github.io/articles/262563/index.html)
If you experience `CreateBitstreamBuffer failed: out of memory (10)`, then you have to lower buffers number used for every encoding session. If you are using `ffmpeg`, see option `-surfaces` ("Number of concurrent surfaces") and try value near `-surfaces 8`.
3. Save appropriate patch(es) from [Version Table](#version-table) using direct link to the patch (Right Click -> Save as...). Alternatively you may checkout repo using git or download it as ZIP archive and then locate corresponding .1337 patch file in `win` directory.
4. Apply x64 library patch to corresponding file in `%WINDIR%\system32\` with the Win\_1337\_Apply\_Patch tool. File name of patched object is specified in first line of .1337 patch. If x86 (32 bit) library patch is also available, apply it to same file in `%WINDIR%\SysWOW64\`.
E.g, for 64bit Windows 10 running driver version $latest_geforce_version use `win10_x64/$latest_geforce_version/nvcuvid64.1337` against `C:\WINDOWS\system32\nvcuvid.dll` and `win10_x64/$latest_geforce_version/nvcuvid32.1337` against `C:\WINDOWS\SysWOW64\nvcuvid.dll`.
~~There are additional steps may be required for Plex and 32bit apps users. See [corresponding section below](#d3d11-and-32-bit-apps-encoding-sessions).~~ We hope this is obsoleted by new additional x86 (32bit) library patch.
A video tutorial is also available. Credits to designator2009. (*Covers pre-x86 patches. Now we probably don't need to autorun executable if x86 library patch applied*)
* [Plex Media Server: nVidia Hardware Transcoding Calculator for Plex Estimates](https://www.elpamsoft.com/?p=Plex-Hardware-Transcoding) - useful benchmark of achieved simultaneous transcodes with various stream quality and hardware with patched drivers.
## See also
* Genesis in [related issue](https://github.com/keylase/nvidia-patch/issues/9)
### D3D11 and 32-bit apps encoding sessions
This section is actual only for D3D11 encoders and earlier driver versions (before 440.97).
This patch for earlier driver versions (those which do not have additional 32bit library patch) wasn't covering 32bit driver libraries and for this reason 32bit applications were limited unless limit is not raised by some 64bit applications. But once usage limit was exceeded, it persists for all kinds of apps until system reboot. So, for example, you may once open 10 sessions with 64bit version of `ffmpeg` and limit will get raised to 10 for all rest types of apps until reboot. You may follow these steps to achieve this automatically and have all limits raised (assuming patch above already applied):
#### Method 1 (recommended)
1. Download and run [latest release](https://github.com/jantenhove/NvencSessionLimitBump/releases) of [NvencSessionLimitBump](https://github.com/jantenhove/NvencSessionLimitBump).
2. (Optional) Add it to autostart programs.
By default this application raises limit to 32 encoding sessions. Credits to @jantenhove.
#### Method 2 (alternative)
1. Download 64bit FFmpeg for Windows: https://ffmpeg.zeranoe.com/builds/
2. Unpack it somewhere.
3. Get [`ffmpeg_null_10streams.cmd`](ffmpeg_null_10streams.cmd) from this repo.
4. Edit `ffmpeg_null_10streams.cmd` and set executable path to real location of your unpacked ffmpeg.
5. (Optional) Add `ffmpeg_null_10streams.cmd` to autostart programs.
**Bonus**: you may use [this AutoIt script](silent_bump.au3) from @wazerstar for silent startup of console applications bumping sessions.
Also you may use these methods to check if patch applied correctly and limit was raised. Use them when nothing works and you are in doubt.