I am trying to record the Audio using AVAssetWriter. But when in plays the File it plays 2 times slower than the origninal audio. What i have done is creating a AVAssetWriter in Following way..
_writer = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeMPEG4 error:nil];
AudioChannelLayout acl;
bzero( &acl, sizeof(acl));
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
NSDictionary *audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[ NSNumber numberWithInt: kAudioFormatMPEG4AAC ], AVFormatIDKey,
[ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,
[ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
[ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
[ NSData dataWithBytes: &acl length: sizeof( acl ) ], AVChannelLayoutKey,
nil];
_audioWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioOutputSettings];
_audioWriterInput.expectsMediaDataInRealTime=YES;
[_writer addInput:_audioWriterInput];
and after that i start appending the buffer in the data as follows
if (_audioWriterInput.readyForMoreMediaData == YES) {
[_audioWriterInput appendSampleBuffer:sampleBuffer];
return YES;
}
What i am doing is getting the mic output using the AVCapureSession in the following delegate function
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
and passing the sampleBuffer directly to avassetWriter to write to file.
Can somebody please let me know why it is writing the audio data to file so slower.. has anybody else faces the similar problem ? and what could be the possible resolution for the issue..
Got the issue..
I was adding the mic capture to the same session in which i am capturing the camera.. Separated both the sessions and now things seems to be working fine..