【问题标题】:initWithCVPixelBuffer failed because the CVPixelBufferRef is not non-IOSurface backedinitWithCVPixelBuffer 失败,因为 CVPixelBufferRef 不是非 IOSurface 支持的
【发布时间】:2012-04-16 04:33:12
【问题描述】:

我收到 YUV 帧 (kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange),当从 CVPixelBufferRef 创建 CIImage 时,我得到:

initWithCVPixelBuffer 失败,因为 CVPixelBufferRef 不是非 IOSurface 支持的。

CVPixelBufferRef pixelBuffer;

size_t planeWidth[] = { width, width / 2 };
size_t planeHeight[] = { height, height / 2};
size_t planeBytesPerRow[] = { width, width / 2 };

CVReturn ret = CVPixelBufferCreateWithBytes(
kCFAllocatorDefault, width, height, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
data, bytesPerRow, 0, 0, 0, &pixelBuffer
);

if (ret != kCVReturnSuccess)
{
    NSLog(@"FAILED");

    CVPixelBufferRelease(pixelBuffer);

    return;
}

CVPixelBufferLockBaseAddress(pixelBuffer, 0);

// fails
CIImage * image = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer];

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

CVPixelBufferRelease(pixelBuffer);

[image release];

【问题讨论】:

  • 你能解决这个问题吗?

标签: ios core-image


【解决方案1】:

我假设问题是:“为什么会出现这个错误?”

要支持 CVPixelBuffer IOSurface,您需要在创建时设置 CVPixelBuffer 的属性。现在,您正在传递“0”作为 CVPixelBufferCreateWithBytes 中倒数第二个参数。

在 CVPixelBufferCreate(因为您不能将 kCVPixelBufferIOSurfacePropertiesKey 与 CVPixelBufferCreateWithBytes 一起使用)中传递一个带有 kCVPixelBufferIOSurfacePropertiesKey 键的字典和一个空字典的值(使用默认的 IOSurface 选项,其他未记录),复制正确的字节到创建的 CVPixelBuffer (不要忘记字节对齐)。这就是你如何让它支持 IOSurface。

虽然我不确定它是否会因为像素格式而为您消除所有错误。我的理解是,GPU 必须能够以该像素格式保存纹理才能用作 IOSurface,尽管我不确定 100%。

注意:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange 的正确复制像素字节可以在this SO answer 中找到。

【讨论】:

    猜你喜欢
    • 2017-07-27
    • 2016-10-07
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 2015-10-27
    相关资源
    最近更新 更多