FFmpeg NVDEC硬件解码后CUDA帧格式与数据布局的技术咨询
FFmpeg NVDEC硬件解码后CUDA帧格式与数据布局的技术咨询
我现在基于FFmpeg的硬件解码示例代码做开发,解码后不把帧数据传输到主机内存,而是直接留在CUDA设备上,后续要配合CUDA代码处理(最终目标是拿到8-12位每通道的RGB格式数据)。
处理解码后帧的核心代码片段如下:
//after decoding/encoding status = avcodec_receive_frame(avctx, frame); if (status != AVERROR(EAGAIN) && status != AVERROR_EOF) LogMessage(L"frame timestamp: %i\n", (int)frame->best_effort_timestamp); if (status == AVERROR(EAGAIN) || status == AVERROR_EOF) { av_frame_free(&frame); return 0; } if (status < 0) { LogMessage(L"Error while decoding\n"); goto finish; } { auto descr = AVPixelFormatMap[(AVPixelFormat)frame->format]; std::wstring dsdescr(descr.begin(), descr.end()); LogMessage(L"Pixelformat: %s", dsdescr.c_str()); cudaPitchedPtr CUdeviceptr0{}; // !! hypothetical usage of cudaPitchedPtr !! CUdeviceptr0.ptr = frame->data[0]; CUdeviceptr0.pitch = frame->linesize[0]; //2048 == pitch ? CUdeviceptr0.ysize = frame->height; //1080 CUdeviceptr0.xsize = frame->width; //1920 cudaPitchedPtr CUdeviceptr1{}; CUdeviceptr1.ptr = frame->data[1]; CUdeviceptr1.pitch = frame->linesize[1]; CUdeviceptr1.ysize = frame->height; CUdeviceptr1.xsize = frame->width; }
目前我遇到了格式识别的瓶颈:解码后frame->format返回的是AV_PIX_FMT_CUDA,官方仅说明这是CUDA硬件加速专用格式,data[i]存储的是CUdeviceptr指针,但完全没有给出具体的像素格式细节——我推测是YUV格式,但无法确认更多参数。
另外我观察到frame的data数组有这些特征:
frame->data[0]:我将其作为单通道数据保存为黑白图像时,能正常识别出画面内容,初步判断是Y分量frame->data[1]:存在指针值,但没有有效图像数据frame->data[2]:为NULL指针
现在有几个关键问题想请教:
frame->data[0]和frame->data[1]分别对应什么数据?- 如果
frame->data[0]是YUV格式的Y分量,那U和V分量的数据存储在哪里? - 怎么才能获取到这个CUDA帧更详细的格式信息?比如具体是YUV还是RGB、每通道的位深、采样格式(如444/422/420这类)?
备注:内容来源于stack exchange,提问作者Soleil
相关产品推荐
相关产品推荐

