ffmpeg AVFrame 转 opencv Mat
现将YUV数据转到Mat中 AVFrame *frame; int width = frame->width, height = frame->height; cv::Mat tmp_img = cv::Mat::zeros( height*3/2, width, CV_8UC1 ); memcpy( tmp_img.data, frame->data[0], width*height ); memcpy( tmp_img.data + width*height, frame->data[1], width*height/4 ); memcpy( tmp_img.data + width*height*5/4, frame->data[2], width*height/4 ); cv::imshow( "yuv_show", tmp_img ); cv::Mat bgr; cv::cvtColor( tmp_img, bgr, CV_YUV2BGR_I420 ); cv::imshow( "bgr_show", bgr ); cv::waitKey(1); 需要讲解的是:Mat的rows是frame->heigth的 3/2倍,cols等于frame->width,单通道; 如果要转换成BGR显示,用CV_YUV2BGR_I420; 因为rtsp流就是IYUV(I420)格式;