Save sampleBuffer in array (AVFoundation)

感情迁移 提交于 2019-12-03 19:40:15

问题


I try to save the sample buffer instead of an UIImage to an array, to convert it later on. This to speed up the image capturing and maybe not get memory warnings. I just can't figure out how to save it to the array and then use it again to call [self imageFromSampleBuffer:sampleBuffer]. I tried something like this, but how do I convert the data back to a CMSampleBufferRef object?

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
    didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
   fromConnection:(AVCaptureConnection *)connection { 
// Create a UIImage from the sample buffer data
//      UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
//      [arrCaptures addObject:image];

[arrImageBuffer addObject:[NSData dataWithBytes:sampleBuffer length:sizeof(sampleBuffer)] ];}

回答1:


Why not just use a CFArray and directly put the CMSampleBufferRef objects in there?




回答2:


You can use CFArray but you should remember that the CMSampleBufferRef is not retained, and that the "captureOutput:didOutputSampleBuffer:fromConnection:" uses a memory pool - and when you don't release the memory it stops sending new samples (that is why you get only 13 samples) as you can read in:captureOutput:didOutputSampleBuffer:fromConnection:



来源:https://stackoverflow.com/questions/7674892/save-samplebuffer-in-array-avfoundation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!