NVENC encoding -- keep getting version error

I’m trying to start a simple NVENC encoding session.

int main () {

NV_ENCODE_API_FUNCTION_LIST *pNVFunctionList;
pNVFunctionList = (NV_ENCODE_API_FUNCTION_LIST *) malloc(sizeof(NV_ENCODE_API_FUNCTION_LIST));
memset(pNVFunctionList, 0, sizeof(NV_ENCODE_API_FUNCTION_LIST));

CUresult result = cuInit(0);
printf(“cuInit result %d\n”,result);

int count;
result = cuDeviceGetCount(&count);
printf(“Counted %d devices returned %d\n”,count,result);

pNVFunctionList->version = NV_ENCODE_API_FUNCTION_LIST_VER;
NVENCSTATUS nvencCreateInstanceResult = NvEncodeAPICreateInstance(pNVFunctionList);
printNVENCErrorsAndExit((char *) “CreateInstance Error”, nvencCreateInstanceResult);

CUdevice dev;
int status = cuDeviceGet(&dev, 0);
printf(“cuDeviceGet status %d Device \n”,status,dev);

CUcontext pctx;
result = cuCtxCreate_v2 ( &pctx, 0, dev);
printf(“cuCtxCreate status %d\n”,result);

NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS encParams = { 0 } ;
encParams.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
encParams.apiVersion = NVENCAPI_VERSION;
encParams.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
encParams.device = &pctx;
encParams.reserved = 0;

void * encoder;
NVENCSTATUS nvencOpenEncodeSessionResult = pNVFunctionList->nvEncOpenEncodeSessionEx(&encParams,(void **) &encoder);
printf(“OpenEncode status %d NVENCAPIVERSION %x NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER %x\n”,nvencOpenEncodeSessionResult,NVENCAPI_VERSION,NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER);

return 0;

}

g++ BasicNvenc.cpp -o BasicNvenc -I /usr/local/cuda-10.2/include/ -lcuda
-I~/Video_Codec_SDK_11.0.10/Interface
~/Video_Codec_SDK_11.0.10/Lib/linux/stubs/x86_64/libnvidia-encode.so

Here is what I get:

cuInit result 0
Counted 1 devices returned 0
CreateInstance Error = 0 SUCCESS
cuDeviceGet status 0 Device
cuCtxCreate status 0
OpenEncode status 15 NVENCAPIVERSION b NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER 7001000b

Error 15 is NV_ENC_ERR_INVALID_VERSION

I’ve checked the apiVersion, the version, and the function list version. I also made sure I was linking against the same library I was compiling the header for. Card is a RTX4000 and I know it’s working. I’m baffled. Any thoughts on what I may be doing wrong here?

Running CENTOS on x86_64 if it makes a difference.

Any ideas what I may be doing wrong here?

Thanks,

Roger

Figured it out… I had a slightly older nvidia driver.

nvidia-smi told me which driver I needed… I cross-checked with Read_Me.pdf from the Video Codec SDK and I had version 440.xx but needed version 455.27 or later.

1 Like

Dear @roger.p

Glad to know that you have figured out the problem. If your issue is resolved, could you please mark your own answer as a solution, so that this post can be considered as resolved?

Thank you.
NVAPI Forum Moderator