This encoder offers the best latency, which is most noticeable at higher resolutions.

# Hardware

This encoder requires a supported NVIDIA graphics card:

- a "professional" Quadro 4000 card (no license key required)
- a consumer card and a license key or a patch to work around the artificial context limit which can be debilitating

# Software Requirements

You must have PyCUDA installed (it is included in the official xpra repositories), and a recent enough version of the nvidia drivers. It is not compatible with the `nouveau` driver.

How you install those drivers is entirely up to you, here are some options for Fedora / RHEL:

- nvidia installers
- negativo17 repository
- rpmfusion
- elrepo etc..

If your CUDA (`libcuda.so`) or NVENC (`libnvidia-encode.so`) libraries are installed in an unusual location, it is your responsibility to ensure they can be loaded at runtime, usually by adding the directory to the `LD_LIBRARY_PATH`.

## Using NVENC

If the codec loads properly, it will be used ahead of the other software encoders automatically.

You can verify the video encoder currently in use with:

    xpra info | grep "encoder="

Important: the video encoder is only used when needed, usually when there is a stream of screen updates.

## Debugging

To force xpra to use nvenc exclusively as video encoder, you can use the `--video-encoders=` command line option:

    xpra seamless :10 --video-encoders=nvenc

To debug the availability of video encoders and GPUs:

    xpra encoding
    xpra video
    xpra nvinfo

Once nvenc is running, you can debug the encoding process step with:

    xpra seamless -d nvenc ...

## License Keys

You can store the license keys in `nvenc.keys`, either globally in `/etc/xpra/` or per-user in `~/.xpra/`.

Or you can also use the environment variable:

    XPRA_NVENC_CLIENT_KEY="0A1B2C3D-4E5F-6071-8293-A4B5C6D7E8F9" xpra ...

Newer SDK versions may not support keys, or just not the same set of keys, in which case the number of sessions will be limited when using consumer cards unless you patch the library.

## Building

- download and install the CUDA SDK
- install PyCuda - it is included in the official repositories for Fedora and RHEL
- download the NVENC SDK, aka "NVIDIA VIDEO CODEC SDK" and install it somewhere (ie: just unzip into `/opt/`)
- create a `pkgconfig` file matching your SDK version and location, you can use nvenc.pc as template.
- when building xpra, nvenc support should be auto-detected, but you can try forcing it to verify, ie:

    ./setup.py build --with-nvenc

## Caveats

- you may need to adjust some paths
- if CUDA refuses to build and complains about `Installation Failed. Using unsupported Compiler` run the CUDA installer with `--override`
- there are undocumented incompatibilities between kernel versions, nvidia driver versions and nvenc SDK versions. If possible, install the driver version bundled with the nvenc SDK - these may manifest itself as undecipherable errors at runtime (`incompatible structure version errors`, etc)
- to adapt to new versions of the SDK and new architectures, one must add compile options to the build file - see Matching SM architectures (CUDA arch and CUDA gencode) for various NVIDIA cards