我正在尝试将我从 iPhone 的摄像机收到的 150 个 CMSampleBufferRef 收集到一个数组中。不知何故,相机在 13 个缓冲区后停止调用委托。我尝试使用 NSMutableArray、CFArray。没有任何帮助。我怀疑它与记忆有关,但我对记忆警告一无所知。
我很乐意为此提供帮助。
提前谢谢。
session = [[AVCaptureSession alloc]init];
//Quality Preset
if ([session canSetSessionPreset:AVCaptureSessionPresetLow]) {
session.sessionPreset = AVCaptureSessionPresetLow;
}
[session beginConfiguration];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *newVideoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
output.videoSettings = @{ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
[session addOutput:output];
[session addInput:newVideoDeviceInput];
AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];
if (conn.supportsVideoMinFrameDuration)
conn.videoMinFrameDuration = CMTimeMake(1, 10);
if (conn.supportsVideoMaxFrameDuration)
conn.videoMaxFrameDuration = CMTimeMake(1, 10);
[session commitConfiguration];
arr = CFArrayCreateMutable( NULL, 150, &kCFTypeArrayCallBacks );
counter=0;
[session startRunning];
那是我的 StartRecording 方法。
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
if (counter==150) {
[self StopRecording:nil];
return;
}
CFArrayInsertValueAtIndex(arr, counter, sampleBuffer);
counter= (counter+1)%150;
}
@end
这就是缓冲区收集方法。