AVAssetReaderAudioMixOutput, presumably poor configuration

AVAssetReaderAudioMixOutput seems incredibly picky.

Let's say I have two MP4s (well-formed, playback is 100% excellent in various environments created with the following settings on the iPhone (AVCaptureData ...)):

NSDictionary *settings = @{
    AVFormatIDKey: @(kAudioFormatMPEG4AAC),
    AVNumberOfChannelsKey: @(1),
    AVSampleRateKey:  @(44100.0),
    AVEncoderBitRateKey: @(64000),
    AVChannelLayoutKey: currentChannelLayoutData // pulled from CMSampleBuffer/etc
};

All is well, so I believe. Now let me say that I take these two MP4s and I want to combine them with the entire MutableComposition drill - if I export this composition / videoComposition / audioMix, say using AVAssetExportSession, it works perfectly and flawlessly.

Now for various reasons, I do not want to use AVAssetExportSession; thus, we conclude something similar to the following (all experience writing assets around this is pretty standard):

NSError *error;
_assetReader = [AVAssetReader assetReaderWithAsset:_composition error:&error];
NSArray *videoTracks = [_assetReader.asset tracksWithMediaType:AVMediaTypeVideo];

_videoOutput = [AVAssetReaderVideoCompositionOutput
                assetReaderVideoCompositionOutputWithVideoTracks:videoTracks
                videoSettings:@{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}];
_videoComposition.renderScale = 1.0f;
_videoOutput.alwaysCopiesSampleData = NO;
_videoOutput.videoComposition = _videoComposition;

if([_assetReader canAddOutput:_videoOutput])
    [_assetReader addOutput:_videoOutput];
else
    SNLog(@"Could not add video reader");

NSArray *audioTracks = [_composition tracksWithMediaType:AVMediaTypeAudio];
_audioOutput = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:audioTracks audioSettings:@{AVFormatIDKey: [NSNumber numberWithUnsignedInt:kAudioFormatLinearPCM]}];
_audioOutput.alwaysCopiesSampleData = NO;
if(_audioMix)
    _audioOutput.audioMix = _audioMix;


if([_assetReader canAddOutput:_audioOutput])
    [_assetReader addOutput:_audioOutput];
else
    SNLog(@"Could not add audio mix output");

startWriting :

**Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo=0x16df24d0 {NSLocalizedDescription=Cannot Open, NSUnderlyingError=0x16deecb0 "The operation couldn’t be completed. (OSStatus error -12413.)", NSLocalizedFailureReason=This media format is not supported.}**

? ; , , , . , .

, , , . , . , .

iOS7, iPhone 5 , . / AudioSesson - PlayAndRecord/etc; AVAssetWriter/co , . / /etc.

+4

All Articles