I am using the jetson_multimedia_api
interface to decode video files in the MP4 format. Then, I am rendering the video data through OPENGL ES. The memory format I am using for the capture plane is DMA. Currently, I can decode the video data (stored in a DMA ID). I use the NvBufSurfaceFromFd
and NvBufSurfaceMapEglImage
interfaces to obtain a variable of type EGLImageKHR
. Afterward, I use cuGraphicsEGLRegisterImage
and cuGraphicsResourceGetMappedEglFrame
to obtain a variable of type CUeglFrame
, from which I can retrieve the video’s memory pointer, eglFrame.frame.pPitch
.
On the other hand, I take the OpenGL-created 2D texture ID and convert it into an EGLImageKHR
variable using the eglCreateImageKHR
interface. Then, by using the cuGraphicsEGLRegisterImage
and cuGraphicsSubResourceGetMappedArray
interfaces, I transform the texture ID into a variable of type CUarray
. Finally, through the cuMemcpy2D
interface, I copy the data from the CUeglFrame
variable to the CUarray
variable, indirectly updating the data of the 2D texture. The process does not result in any errors. However, the texture data remains unchanged, meaning it has no effect.
Below is the copy function:
void CopyEglFrameToCuArray(const CUeglFrame& eglFrame, CUarray& cuArray) {
// Step 1: Get image data and information
const void* eglImageData = eglFrame.frame.pPitch[0];
int imageWidth = eglFrame.width;
int imageHeight = eglFrame.height;
// Get other image format information
// Step 2: Create CUarray object
CUDA_ARRAY_DESCRIPTOR arrayDesc;
memset(&arrayDesc, 0, sizeof(arrayDesc));
arrayDesc.Width = imageWidth;
arrayDesc.Height = imageHeight;
arrayDesc.Format = CU_AD_FORMAT_UNSIGNED_INT8; // Assuming image format is 8-bit unsigned integer
cuArrayCreate(&cuArray, &arrayDesc);
// Step 3: Use CUDA memory copy functions for data transfer
CUDA_MEMCPY2D copyDesc;
memset(©Desc, 0, sizeof(copyDesc));
copyDesc.srcMemoryType = CU_MEMORYTYPE_DEVICE; // Source memory type is device memory
copyDesc.srcDevice = eglImageData; // Source data pointer
copyDesc.srcPitch = eglFrame.frame.pitch; // Assuming image data pitch information is in pitch
copyDesc.dstMemoryType = CU_MEMORYTYPE_ARRAY; // Destination memory type is array
copyDesc.dstArray = cuArray; // Destination array object
copyDesc.WidthInBytes = imageWidth * 4; // Assuming each pixel is 4 bytes (RGBA)
cuMemcpy2D(©Desc);
}