【发布时间】:2013-02-21 21:21:27
【问题描述】:
我在YUVJ420P 中有一个FFMPEG AVFrame,我想用CVPixelBufferCreateWithBytes 将它转换为CVPixelBufferRef。我想这样做的原因是使用 AVFoundation 来显示/编码帧。
我选择了kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange 并尝试对其进行转换,因为 AVFrame 的数据位于三个平面中
Y480Cb240Cr240。根据我的研究,这与选定的kCVPixelFormatType 匹配。由于是双平面的,我需要将其转换为包含 Y480 和 CbCr480 Interleaved 的缓冲区。
我试图用 2 个平面创建一个缓冲区:
-
frame->data[0]在第一架飞机上, -
frame->data[1]和frame->data[2]在第二个平面上交错。
但是,我收到来自CVPixelBufferCreateWithBytes 的返回错误-6661 (invalid 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)
帧是AVFrame,带有来自 FFMPEG 解码的 rawData。
【问题讨论】:
-
cvPixelBufferSample是 CVPixelBufferRef 吗?如果是这样,CVPixelBufferCreateWithBytes()中的最后一个参数需要是&cvPixelBufferSample,以允许通过引用返回指向新像素缓冲区的指针。
标签: ios ffmpeg avfoundation yuv