Error Initializing nvEncoder

Hello All,

I’m encountering an exception error when initializing the NvEncoder::CreateEncoder. nvEncInitializeEncoder return error code 8.

Video Input Information
Codec : AVC/H.264
Frame rate : 0/0 = -nan(ind) fps
Sequence : Progressive
Coded size : [1280, 720]
Display area : [0, 0, 1280, 720]
Chroma : YUV 420
Bit depth : 8
Video Decoding Params:
Num Surfaces : 20
Crop : [0, 0, 0, 0]
Resize : 1280x720
Deinterlace : Weave

Here are my Encoding Parameters:

[INFO ][13:00:41] Encoding Parameters:
codec : h264
preset : default
profile : (default)
chroma : yuv420
bitdepth : 8
rc : cbr_hq
fps : 60/1
gop : INF
bf : 0
size : 1280x720
bitrate : 1000000000
maxbitrate : 0
vbvbufsize : 0
vbvinit : 0
aq : disabled
temporalaq : disabled
lookahead : disabled
cq :
qmin : P,B,I=0,0,0
qmax : P,B,I=0,0,0
initqp : P,B,I=0

Encoder Capability

GPU H264 H264_444 H264_ME H264_WxH HEVC HEVC_Main10 HEVC_Lossless HEVC_SAO HEVC_444 HEVC_ME HEVC_WxH

0 Tesla T4 + + + 4096x4096 + + + + + + 8192x8192

±----------------------------------------------------------------------------+
| NVIDIA-SMI 451.48 Driver Version: 451.48 CUDA Version: 11.6 |
|-------------------------------±---------------------±---------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla T4 TCC | 00000000:B1:00.0 Off | 0 |
| N/A 36C P8 11W / 70W | 1MiB / 15205MiB | 0% Default |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
±----------------------------------------------------------------------------+

Any ideas as to what could be causing this issues?

Hello @tim.wooldridge and welcome to the NVIDIA developer forums!

Error code 8 corresponds to NV_ENC_ERR_INVALID_PARAM which would indicate that one of your parameters in NvEncoder::CreateEncoder() is incorrect. Please check with the sample code and see if there might be some mismatch.

I hope this helps!

Hi Markus, thanks for your feedback. What confusing is this code works fine on the RTX 2080. However, when I run the code on a T4, I encounter the error 8.

Now you have me intrigued.

Would it be possible for you to upgrade the NVIDIA driver version?

And could you share the part of your code where you encounter the error? And ideally a stacktrace in case you have debugging capabilities? To analyse further we would need some idea of what the passed values are in the function that fails.

Hi, we occasionally encounter an exception error when initializing NvEncoder::CreateEncoder. nvEncInitializeEncoder returns error code 8 (NV_ENC_ERR_INVALID_PARAM).

Our GPU is T4 and we run on NVIDIA driver version 470.57.02 in Ubuntu 20.04.

This crash happens infrequently and is difficult to reproduce.

I am getting the same crash when reconfiguring the encoder too and that is where we recorded the latest crash.

NVENC_API_CALL(m_nvenc.nvEncReconfigureEncoder(m_hEncoder, const_cast<NV_ENC_RECONFIGURE_PARAMS*>(pReconfigureParams)));
NVENC_API_CALL(m_nvenc.nvEncInitializeEncoder(m_hEncoder, &m_initializeParams));

I will provide a reduced set of NVEnc parameters because I do not have all of them immediately available:
Codec : H.264
codec : h264
rc : cbr_hq
fps : 60/1
gop : INF
bf : 0
Encoding size : 1920x1080
Display size : 1920x1080

Reconfigure parameters:
NV_ENC_CODEC_H264_GUID;
NV_ENC_PRESET_P4_GUID;
NV_ENC_TUNING_INFO_ULTRA_LOW_LATENCY
NVENC_INFINITE_GOPLENGTH;
frameIntervalP = 1;
rateControlMode = NV_ENC_PARAMS_RC_CBR;
averageBitRate = 16556000; // variable bitrate last value before crash, it is fairly low
vbvBufferSize = averageBitRate * 5;

For your information, I filed an NVIDIA bug detailing the issue here:

https://developer.nvidia.com/nvidia_bug/3729599

I’m also hitting this fairly regularly (but seemingly at random) on an NVIDIA RTX 2080 with driver version 516.59 on Windows 10.

Our application creates/deletes encoders as clients connect and/or change parameters such as frame rate and resolution. It works for a while, and then we encounter this error.

It would be nice if nvEncGetLastErrorString returned more information. In this instance it just gives an empty string which isn’t very useful. (Obviously something in the driver knows what’s wrong. Why can’t it tell us?)

Ok, I found out what our problem was.

NV_ENC_INITIALIZE_PARAMS::encodeWidth has to be divisible by four, and NV_ENC_INITIALIZE_PARAMS::encodeHeight must be divisible by two.

These limitations don’t appear to exist on Linux, but I may have just been lucky when testing.

It would be nice if limitations such as these were documented here:
https://docs.nvidia.com/video-technologies/video-codec-sdk/nvenc-video-encoder-api-prog-guide/

Cheers,
James