我有一个FFMPEG中的AVFrame,格式为YUVJ420P,我想将其转换为CVPixelBufferRef,并使用CVPixelBufferCreateWithBytes。我这么做的原因是要使用AVFoundation来显示/编码帧。
我选择了kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange并尝试进行转换,因为AVFrame的数据在三个平面
我尝试创建一个具有2个平面的缓冲区: - frame->data[0]在第一个平面上, - frame->data[1]和frame->data[2]交错在第二个平面上。
但是,我从CVPixelBufferCreateWithBytes得到了返回错误-6661(无效a)。
我选择了kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange并尝试进行转换,因为AVFrame的数据在三个平面
Y480
Cb240
Cr240
中。根据我的研究,这与所选的kCVPixelFormatType
相匹配。由于是双平面,我需要将它转换为包含交错的Y480
和CbCr480
的缓冲区。我尝试创建一个具有2个平面的缓冲区: - frame->data[0]在第一个平面上, - frame->data[1]和frame->data[2]交错在第二个平面上。
但是,我从CVPixelBufferCreateWithBytes得到了返回错误-6661(无效a)。
"Invalid function parameter. For example, out of range or the wrong type."
我对图像处理完全没有专业知识,因此非常感谢任何指向可以帮我开始解决这个问题的文档。我的 C 技能也不是很高超,所以可能在这里犯了基本错误。
uint8_t **buffer = malloc(2*sizeof(int *));
buffer[0] = frame->data[0];
buffer[1] = malloc(frame->linesize[0]*sizeof(int));
for(int i = 0; i<frame->linesize[0]; i++){
if(i%2){
buffer[1][i]=frame->data[1][i/2];
}else{
buffer[1][i]=frame->data[2][i/2];
}
}
int ret = CVPixelBufferCreateWithBytes(NULL, frame->width, frame->height, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, buffer, frame->linesize[0], NULL, 0, NULL, cvPixelBufferSample)
这个框架是带有从FFMPEG解码中获得的原始数据的AVFrame
。
cvPixelBufferSample
是一个 CVPixelBufferRef 吗?如果是的话,那么CVPixelBufferCreateWithBytes()
中的最后一个参数应该是&cvPixelBufferSample
,以便通过引用返回新像素缓冲区的指针。 - Brad Larson