gpt4 book ai didi

ios - 使用 CVPixelBufferCreate 复制/复制 CVPixelBufferRef

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:33:24 45 4
gpt4 key购买 nike

我需要创建一个 CVPixelBufferRef 的副本,以便能够使用副本中的值以按位方式操作原始像素缓冲区。我似乎无法使用 CVPixelBufferCreateCVPixelBufferCreateWithBytes 实现此目的。

根据 this question , 它也可以用 memcpy() 来完成。但是,没有解释如何实现这一点,也没有说明无论如何都需要调用哪些核心视频库。

最佳答案

这似乎可行:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

// Get pixel buffer info
const int kBytesPerPixel = 4;
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
int bufferWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
int bufferHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
uint8_t *baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);

// Copy the pixel buffer
CVPixelBufferRef pixelBufferCopy = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, bufferWidth, bufferHeight, kCVPixelFormatType_32BGRA, NULL, &pixelBufferCopy);
CVPixelBufferLockBaseAddress(pixelBufferCopy, 0);
uint8_t *copyBaseAddress = CVPixelBufferGetBaseAddress(pixelBufferCopy);
memcpy(copyBaseAddress, baseAddress, bufferHeight * bytesPerRow);

// Do what needs to be done with the 2 pixel buffers

}

关于ios - 使用 CVPixelBufferCreate 复制/复制 CVPixelBufferRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37418517/

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