0

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.

Nat
  • 300
  • 3
  • 8
  • Possible duplicate of: http://stackoverflow.com/questions/9152075/wav-to-any-compressed-form-from-avassetwritter-ios – st. Jan 17 '16 at 02:48
  • Check out the answer in that link. – st. Jan 17 '16 at 02:48
  • @st - Thanks for that link. But, no joy! This is a video file, whose audio compression is resulting in a failure. – Nat Jan 17 '16 at 05:18
  • Well probably it's like something you're simply missing, or it is a bug which I don't think so. Can you share the whole function ? – st. Jan 17 '16 at 11:15
  • @st. Thanks for offering to help me. The basic question I want answered is, when I set up audioWriterInput as described above, and do a NSParameterAssert on mediaWriter, why am I getting the error (as provided above)? I have now updated my question above with my definition of the mediaWriter. – Nat Jan 18 '16 at 00:17
  • @Nat .. did you manage to solve this? @st. I think we must not pass nil to the `outputSetting` of `AVAssetWriterInput `, even if we want to keep the audio as is i.e uncompressed. – nr5 Jul 16 '17 at 13:15
  • 1
    @Nil - Sorry for my very delayed reply. You are correct that nil is not an accepted value. I solved it by catching nil value. – Nat Aug 09 '17 at 21:16

0 Answers0