簡體   English   中英

如何將 CMSampleBuffer 保存到來自 didOutputSampleBuffer 的 CFArrayRef(或其他容器)

[英]How could save the CMSampleBuffer to a CFArrayRef (or other container) that from didOutputSampleBuffer

我試圖從 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);
}

有人有更好的方法來做到這一點或任何建議?

非常感謝。

CMSampleBufferCreateCopy是淺拷貝,根據how to deep copy pixelbuffer的答案

使用新的像素緩沖區重新創建樣本緩沖區。 然后我可以緩存樣本緩沖區。

但是這種方式會消耗資源,我不能在內存中容納太多的 CMSampleBufferRefs(每個大約需要 3MB),並且深復制的過程很浪費時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM