gpt4 book ai didi

ios - 从支持 IOSurface 的 YUV 创建 CVPixelBuffer

转载 作者:可可西里 更新时间:2023-11-01 03:08:08 25 4
gpt4 key购买 nike

所以我从网络回调(voip 应用程序)中获取 3 个单独数组中的原始 YUV 数据。根据我的理解,您不能根据 here 使用 CVPixelBufferCreateWithPlanarBytes 创建 IOSurface 支持的像素缓冲区

Important: You cannot use CVPixelBufferCreateWithBytes() or CVPixelBufferCreateWithPlanarBytes() with kCVPixelBufferIOSurfacePropertiesKey. Calling CVPixelBufferCreateWithBytes() or CVPixelBufferCreateWithPlanarBytes() will result in CVPixelBuffers that are not IOSurface-backed

因此您必须使用 CVPixelBufferCreate 创建它,但是如何将数据从调用传回您创建的 CVPixelBufferRef

- (void)videoCallBack(uint8_t *yPlane, uint8_t *uPlane, uint8_t *vPlane, size_t width, size_t height, size_t stride yStride,
size_t uStride, size_t vStride)
NSDictionary *pixelAttributes = @{(id)kCVPixelBufferIOSurfacePropertiesKey : @{}};
CVPixelBufferRef pixelBuffer = NULL;
CVReturn result = CVPixelBufferCreate(kCFAllocatorDefault,
width,
height,
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
(__bridge CFDictionaryRef)(pixelAttributes),
&pixelBuffer);

我不确定之后要做什么?最后我想把它变成一个 CIImage 然后我可以使用我的 GLKView 来渲染视频。当您创建数据时,人们如何将数据“放入”缓冲区?

最佳答案

我想通了,这很微不足道。下面是完整的代码。唯一的问题是我收到 BSXPCMessage received error for message: Connection interrupted 视频显示需要一段时间。

NSDictionary *pixelAttributes = @{(id)kCVPixelBufferIOSurfacePropertiesKey : @{}};
CVPixelBufferRef pixelBuffer = NULL;
CVReturn result = CVPixelBufferCreate(kCFAllocatorDefault,
width,
height,
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
(__bridge CFDictionaryRef)(pixelAttributes),
&pixelBuffer);

CVPixelBufferLockBaseAddress(pixelBuffer, 0);
uint8_t *yDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
memcpy(yDestPlane, yPlane, width * height);
uint8_t *uvDestPlane = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
memcpy(uvDestPlane, uvPlane, numberOfElementsForChroma);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

if (result != kCVReturnSuccess) {
DDLogWarn(@"Unable to create cvpixelbuffer %d", result);
}

CIImage *coreImage = [CIImage imageWithCVPixelBuffer:pixelBuffer]; //success!
CVPixelBufferRelease(pixelBuffer);

我忘了添加交错两个 U 和 V 平面的代码,但这应该不会太糟糕。

关于ios - 从支持 IOSurface 的 YUV 创建 CVPixelBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31823673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com