What is the pixel format of AV_PIX_FMT_CUDA in GPU memory and how to convert to BGR format in OpenCV?

372 views Asked by At

I an trying to decode a H264 RTSP stream using GPU hardware decoder and retrieve the image pointer in GPU memory and place it in cv::cuda::GpuMat to avoid CPU transfers.

I received the frame and the pixel format is AV_PIX_FMT_CUDA.

ret = avcodec_receive_frame(avctx, frame);
const char* gpu_pixfmt = av_get_pix_fmt_name((AVPixelFormat)frame->format); //AV_PIX_FMT_CUDA

Without knowing the image format, I am unable to display the image correctly.

cv::cuda::GpuMat dimage(sw_frame->height, sw_frame->width, CV_8UC2, frame->data[0]);
cv::Mat himage;
dimage.download(himage);
cv::cvtColor(himage, himage, cv::COLOR_YUV2BGR_UYVY);
cv::imshow("image", himage);

Any idea what is the pixel format and how to decode it correctly to BGR using opencv?

Thanks in advance.

0

There are 0 answers