我尝试从didOutputSampleBuffer中保存CMSampleBuffer,作为iOS开发人员文档,我将其复制到CFArrayRetainCallBack中,就像打击一样:
static const void * ObjectRetainCallBack(CFAllocatorRef allocator, const void *value) {
CMSampleBufferRef buffer = (CMSampleBufferRef)value;
if (buffer) {
CMSampleBufferRef new = NULL;
OSStatus status = CMSampleBufferCreateCopy(kCFAllocatorDefault, buffer, &new);
if (status == noErr) {
return new;
}
return NULL;
}
return NULL;
}
static void ObjectReleaseCallBack(CFAllocatorRef allocator, const void *value) {
if (value) {
CFRelease(value);
}
}
CFMutableArrayRef CreateDispatchHoldingArray() {
CFArrayCallBacks callBacks = {
0,
ObjectRetainCallBack,
ObjectReleaseCallBack,
NULL,
NULL
};
return CFArrayCreateMutable(kCFAllocatorDefault, 0, &callBacks);
}
我使用如下的数组:
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CFArrayAppendValue(_pixelArray, sampleBuffer);
}
有人有更好的方法来做这个或任何建议吗?
非常感谢。
答案 0 :(得分:0)
CMSampleBufferCreateCopy是浅层副本
使用新的pixelbuffer重新创建samplebuffer。然后我可以缓存样本缓冲区。
但是这种方式需要资源,我不能在内存中容纳过多的CMSampleBufferRef(每个都需要大约3MB),深度复制的过程浪费时间。