我有一个 FFMPEG AVFrame,YUVJ420P我想将它转换为CVPixelBufferRefwith CVPixelBufferCreateWithBytes。我想这样做的原因是使用 AVFoundation 来显示/编码帧。
我选择kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange并尝试转换它,因为 AVFrame 在三个平面上有数据
Y480 Cb240 Cr240。根据我的研究,这与选定的kCVPixelFormatType. 由于是双平面的,我需要将其转换为包含Y480和CbCr480交错的缓冲区。
我试图用 2 个平面创建一个缓冲区:
frame->data[0]在第一架飞机上,frame->data[1]并frame->data[2]在第二个平面上交错。
但是,我-6661 (invalid a)从以下位置收到返回错误CVPixelBufferCreateWithBytes:
"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)
该帧AVFrame带有来自 FFMPEG 解码的 rawData。