我正在使用AVFoundation访问用于制作视频的图像和音频。问题是当我加入像音频设备。使用AVFoundation访问图像和音频
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
AVCaptureDeviceInput * microphone_input = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];
AVCaptureAudioDataOutput * audio_output = [[AVCaptureAudioDataOutput alloc] init];
[self.captureSession2 addInput:microphone_input];
[self.captureSession2 addOutput:audio_output];
dispatch_queue_t queue2;
queue2 = dispatch_queue_create("Audio", NULL);
[audio_output setSampleBufferDelegate:self queue:queue2];
dispatch_release(queue2);
和相机的图像。
AVCaptureDevice *cameraDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//putting it on the input.
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:cameraDevice error:nil];
//selecting the Output.
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
[self.captureSession addInput:captureInput];
[self.captureSession addOutput:captureOutput];
dispatch_queue_t queue;
queue = dispatch_queue_create("cameraQueue", 0);
[captureOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
毕竟通过代表
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
if ([captureOutput isKindOfClass:[AVCaptureAudioDataOutput class]])
[self sendAudeoRaw:sampleBuffer];
if ([captureOutput isKindOfClass:[AVCaptureVideoDataOutput class]])
[self sendVideoRaw:sampleBuffer];}
获取图像原始数据的速度大约为每秒2图像非常缓慢得到原始数据。我如何改善它,因为我正在寻找10-12图像/秒。 请帮助
什么是'[self sendVideoRaw:sampleBuffer]'? – 2012-07-07 19:12:08
另外,你可以在你的captureOutput代码中简单地比较指针,而不是使用isKindOfClass。例如'if(captureOutput == audio_output)'。你必须小心isKindOfClass。它可以返回一些你可能没有想到的东西。这通常只发生在容器类中。查看此[post](http://stackoverflow.com/questions/1096772/is-it-safe-to-use-iskindofclass-against-an-nsstring-instance-to-determine-type)进行讨论。最后一个想法。您不需要为音频和视频使用两个不同的捕捉会话。两个AV IO类都可以添加到同一个会话中。 – 2012-07-07 19:23:04
@SteveMcFarlin分离音频和图像原始数据进行处理。 – 2012-07-09 05:38:46