I’m trying to build an encoding application. I’m using the nvenc documentation provided in the video codec sdk. I’ve hit a roadblock when attempting to open encode session. I’ve set the value of version to the #define const as said in the comments in nvEncodeAPI.h .Still i’m getting status 15 which means i’ve used wrong struct version (according to nvEncodeAPI.h). Any help in this regard is greatly appreciated
Here are the versions of toolkit i’m using
windows 10
visual studio 2019
Cuda toolkit: 10.2
video codec sdk: 9.1
i simplified the program for quick understanding
nvencfix.c
#include <nvEncodeAPI.h>
#include <stdio.h>
#include <stdint.h>
#include <cuda.h>
int main() {
cuInit(0);
int count;
cuDeviceGetCount(&count);
printf("%d is count\n",count); // output: 1 is count
// needed for initializing session
CUdevice dev;
CUcontext ctx;
NV_ENCODE_API_FUNCTION_LIST instance;
// geting above parameters
int status = cuDeviceGet(&dev, 0);
printf("%d is cuDeviceGet\n", status);
status = cuCtxCreate_v2(&ctx, 0, dev);
printf("%d is cuCtxCreate_v2\n", status);
status = NvEncodeAPICreateInstance(&instance);
printf("%d is createInstance\n", status);
// parameters for opening encoding session
NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS params = {
NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER
};
params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
params.device = dev;
params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
// calling the nvEncOpenEncodeSessionEx
void* encoder = NULL;
printf("%p is ENC before\n", encoder); // output: 000000000000000 is ENC before
status = instance.nvEncOpenEncodeSessionEx(¶ms, &encoder);
printf("%d is openEncodeSession\n", status); // output: 15 is openEncodeSession
printf("%p is ENC after\n", encoder); // output: 000000000000000 is ENC after
status = cuCtxDestroy_v2(ctx);
printf("%d is ctxDestroy\n", status); // output: 0 is ctxDestroy
}