AVFoundation Error Constant -11841 means that you have an invalid video composition. See this link if you want more information about error constants: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVFoundation_ErrorConstants/Reference/reference.html
While serious errors do not appear on me, I can suggest the following ways to narrow down the source of your problem.
First, instead of passing nil for the error parameter in these calls:
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, avAsset.duration) ofTrack:sourceVideoTrack atTime:kCMTimeZero error:nil]
create an NSError object and pass a reference to it as follows:
NSError *error = nil; [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, avAsset.duration) ofTrack:sourceVideoTrack atTime:kCMTimeZero error:&error];
Check the error to make sure your video and audio tracks are correctly inserted into the composition track. The error should be nil if everything goes well.
if(error) NSLog(@"Insertion error: %@", error);
You can also check your AVAsset composable and exportable and hasProtectedContent . If it is not YES, YES and NO, respectively, there may be a problem creating a new video file.
Sometimes I saw a problem when creating a time range for an audio track does not like the 600 time scale when used in a composition with a video track. You might want to create a new CMTime for the duration (avAsset.duration) in
CMTimeRangeMake(kCMTimeZero, avAsset.duration)
only to insert an audio track. In the new CMTime, use the 44100 timeline (or regardless of the sample rate of the audio track). The same goes for your videoComposition.frameDuration . Depending on the nominalFrameRate your video track, your time may not display correctly at nominalFrameRate scale.
Finally, there is a useful tool provided by Apple for debugging videos:
https://developer.apple.com/library/mac/samplecode/AVCompositionDebugViewer/Introduction/Intro.html
It gives a visual representation of your composition, and you can see where things don't look as they should.