ios - Access Images and Audio with AVFoundation -
i using avfoundation accessing images , audio making video. problem when adding device audio like.
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);
and camera images.
avcapturedevice *cameradevice = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo]; //putting on input. avcapturedeviceinput *captureinput = [avcapturedeviceinput deviceinputwithdevice:cameradevice error:nil]; //selecting 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);
and after getting raw data through delegates
- (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];}
the speed of getting images raw data slow around 2 images per second. how can improve because looking around 10-12 images/second. please help
i using avfoundation accessing images , audio making video. problem when adding device audio like. and camera images. and after getting raw data through delegates the speed of getting images raw data slow around 2 images per second. how can improve because looking around 10-12 images/second. please help | ||||
[self sendvideoraw:samplebuffer]
? – steve mcfarlin jul 7 '12 @ 19:12if(captureoutput == audio_output)
. have careful iskindofclass. can return may not expecting. occurs container classes. see post discussion. 1 last think. not need use 2 different capture sessions audio , video. both av io classes can added same session. – steve mcfarlin jul 7 '12 @ 19:23[self sendvideoraw:samplebuffer]
thought perhaps code blocking capture queue long enough allow 2fps. if uncomment code fps get. i'll assume still 2fps. may configuration issue, without more code can not tell. might take @ avcamdemo project apple. – steve mcfarlin jul 10 '12 @ 17:57