我正在使用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