0

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.

talonmies
  • 70,661
  • 34
  • 192
  • 269
cyw
  • 163
  • 3
  • 11
  • I think the pixel format is `AV_PIX_FMT_CUDA` and not `AV_PIX_FMT_CUDA_YUV444P` for example, because in theory, different GPU devices may use different formats. In case you want us to try determine the specific format of `himage`, please share a sample image. Save a sample image as grayscale PNG. Make sure we can determine the colors from the shared image. Make sure SO doesn't convert your image to JPEG due to size limit. Alternatively, post an executable code sample that we can build and execute and get the image. – Rotem Jan 31 '23 at 20:57
  • It means the frame is or will be in "device", you can get actual format from `AVCodecContext::sw_pix_fmt`. – the kamilz Feb 01 '23 at 07:39

0 Answers0