我正在尝试收集我从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
Tha是缓冲区收集方法.
最佳答案 你想做什么?
AVFoundation将CMSampleBuffer传递给硬件编码器.我的理论是当它没有检测到传入的帧时,它只是停止传递你的帧.
相反,尝试将CVPixelBufferRef存储在CVPixelBufferPool中.
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);