- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我需要创建一个 CVPixelBufferRef
的副本,以便能够使用副本中的值以按位方式操作原始像素缓冲区。我似乎无法使用 CVPixelBufferCreate
或 CVPixelBufferCreateWithBytes
实现此目的。
根据 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/
我正在将图像制作成视频。但总是因为内存警告而崩溃,CVPixelBufferCreate 分配过多。我不知道如何正确处理它。我看过很多类似的主题,但没有一个能解决我的问题。 这是我的代码: - (vo
我正在尝试重新创建 https://github.com/Lockerios/VideoFromImage 中的一些功能并在这篇文章中讨论:ASSETWriterInput for making Vi
您好,我正在尝试使用新的 GPUImage 设置编辑单个图像,但我遇到了以下错误。 2014-07-06 11:52:46.966 App[4314:9d07] *** Assertion failu
我需要创建一个 CVPixelBufferRef 的副本,以便能够使用副本中的值以按位方式操作原始像素缓冲区。我似乎无法使用 CVPixelBufferCreate 或 CVPixelBufferCr
我正在尝试使用这个很棒的库,但我遇到了一个问题,我无法修复它。我花了最后 5 个小时尝试,但我完全没有想法。 我使用 CocoaPods 添加了库,它给了我一个错误,所以我将它添加为一个静态库(考虑到
假设我想存储来自相机输出的帧 let imageBuffer:CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) some_list.
我是一名优秀的程序员,十分优秀!