비디오 제작을 위해 이미지 및 오디오에 액세스 할 때 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]'란 무엇입니까? –
또한 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 클래스는 동일한 세션에 추가 될 수 있습니다. –
@SteveMcFarlin 처리를 위해 오디오 및 이미지 원시 데이터를 분리합니다. –