Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将CMSampleBuffer保存到从didOutputSampleBuffer创建的CFArrayRef(或其他容器)中_Ios_Avcapture_Cmsamplebufferref - Fatal编程技术网

Ios 如何将CMSampleBuffer保存到从didOutputSampleBuffer创建的CFArrayRef(或其他容器)中

Ios 如何将CMSampleBuffer保存到从didOutputSampleBuffer创建的CFArrayRef(或其他容器)中,ios,avcapture,cmsamplebufferref,Ios,Avcapture,Cmsamplebufferref,我试图从didOutputSampleBuffer保存CMSampleBuffer,作为iOS开发者文档,我在CFArrayRetainCallBack中复制它,就像blow一样: static const void * ObjectRetainCallBack(CFAllocatorRef allocator, const void *value) { CMSampleBufferRef buffer = (CMSampleBufferRef)value; if (buffe

我试图从didOutputSampleBuffer保存CMSampleBuffer,作为iOS开发者文档,我在CFArrayRetainCallBack中复制它,就像blow一样:

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);
}
有人有更好的方法来做这件事或者有什么建议吗


非常感谢。

CMSampleBufferCreateCopy是浅拷贝,根据

使用新的pixelbuffer重新创建samplebuffer。然后我可以缓存样本缓冲区

但是这种方式需要消耗资源,我不能在内存中保存太多的cmSampleBufferRef(每个都需要3MB),而且深度复制的过程是浪费时间的