VideoEncoder* CreateX264Encoder(int fps, int width, int height, int quality, CTSTR preset, CTSTR ProFile,bool bUse444, ColorDescription &colorDesc, int maxBitRate, int bufferSize, bool bUseCFR,bool bUesBackConfig) { VideoEncoder *Encoder = new X264Encoder(fps, width, height, quality, preset, ProFile, bUse444, colorDesc, maxBitRate, bufferSize, bUseCFR, bUesBackConfig); if (Encoder && Encoder->InitEncoder()) { return Encoder; } else if (Encoder) { delete Encoder; } return NULL; }
// This is our main application code int main(int argc, char *argv[]) { HRESULT hr = S_OK; int retvalue = -1; printf("Starting cudaEncode...\n"); // NVCUVENC data structures and wrapper class VideoEncoder *pCudaEncoder = NULL; NVEncoderParams sEncoderParams = {0}; NVVE_CallbackParams sCBParams = {0}; // CUDA resources needed (for CUDA Encoder interop with a previously created CUDA Context, and accepting GPU video memory) CUcontext cuContext; CUdevice cuDevice; CUvideoctxlock cuCtxLock = 0; CUdeviceptr dptrVideoFrame = 0; unsigned int Pitch, Height, WidthInBytes, ElementSizeBytes; void *pData = NULL; // First we parse the input file (based on the command line parameters) // Set the input/output filenmaes if (!ParseInputParams(argc, argv, &sEncoderParams)) { printHelp(); exit(EXIT_SUCCESS); } // Create the NVCUVENC wrapper class for handling encoding pCudaEncoder = new VideoEncoder(&sEncoderParams); pCudaEncoder->InitEncoder(&sEncoderParams); pCudaEncoder->SetEncodeParameters(&sEncoderParams); // Create the timer for frame time measurement sdkCreateTimer(&frame_timer); sdkResetTimer(&frame_timer) ; sdkCreateTimer(&global_timer); sdkResetTimer(&global_timer) ; // This is for GPU device memory input, and support for interop with another CUDA context // The NVIDIA CUDA Encoder will use this CUDA context to be able to pass in shared device memory if (sEncoderParams.iUseDeviceMem) { HRESULT hr = S_OK; printf(">> Using Device Memory for Video Input to CUDA Encoder << \n"); // Create the CUDA context checkCudaErrors(cuInit(0)); checkCudaErrors(cuDeviceGet(&cuDevice, sEncoderParams.iForcedGPU)); checkCudaErrors(cuCtxCreate(&cuContext, CU_CTX_BLOCKING_SYNC, cuDevice)); // Allocate the CUDA memory Pitched Surface if (sEncoderParams.iSurfaceFormat == UYVY || sEncoderParams.iSurfaceFormat == YUY2) { WidthInBytes =(sEncoderParams.iInputSize[0] * sSurfaceFormat[sEncoderParams.iSurfaceFormat].bpp) >> 3; // Width Height = sEncoderParams.iInputSize[1]; }