When I have audioCompressionSettings as nil in the following code,
AVAssetWriterInput* audioWriterInput =
[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
outputSettings:nil
sourceFormatHint:(__bridge CMAudioFormatDescriptionRef)[[audioTrack formatDescriptions] objectAtIndex:0]];
everything works fine.
If I add outputSettings:audioCompressionSettings, my Video comes out as a 0-byte file in iOS 7, 8, 9. And in iOS 6, the following statement throws an error,
NSParameterAssert([mediaWriter canAddInput:audioWriterInput]);
My audioCompressionSettings is defined as follows,
AudioChannelLayout stereoChannelLayout = {
.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo,
.mChannelBitmap = 0,
.mNumberChannelDescriptions = 0
};
NSData *channelLayoutAsData = [NSData dataWithBytes:&stereoChannelLayout length:offsetof(AudioChannelLayout, mChannelDescriptions)];
NSDictionary *audioCompressionSettings = @{
AVFormatIDKey : [NSNumber numberWithUnsignedInt:kAudioFormatMPEG4AAC],
AVEncoderBitRateKey : [NSNumber numberWithInteger:128000],
AVSampleRateKey : [NSNumber numberWithInteger:44100],
AVChannelLayoutKey : channelLayoutAsData,
AVNumberOfChannelsKey : [NSNumber numberWithUnsignedInteger:2]
};
Please let me know what I am doing wrong.
With audioCompressionSettings nil, iOS 6 spits out this error:
*** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:
request:frame:decisionListener: delegate:
<NSInternalInconsistencyException> Invalid parameter not satisfying:
[mediaWriter canAddInput:audioWriterInput]
mediaWriter is defined as follows,
AVAssetWriter *mediaWriter = [[AVAssetWriter alloc] initWithURL:outputURL fileType:AVFileTypeMPEG4 error:&error];
mediaWriter.shouldOptimizeForNetworkUse = YES;
NSParameterAssert(mediaWriter);
I actually want the iOS 6 issue to be fixed as I really do not want to do any transformation of the audio but just have it pass through.