Ok, the problem. This is not related to the above code, as it works fine. The problem was that AVAssetTracks for sound other than the first track were not included. To enable them, you had to recreate the asset using AVMutableComposition:
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"movie" withExtension:@"mp4"]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil]; AVMutableComposition *composition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; NSError* error = NULL; [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset.duration) ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0] atTime:kCMTimeZero error:&error]; NSArray *allAudio = [asset tracksWithMediaType:AVMediaTypeAudio]; for (int i=0; i < [allAudio count]; i++) { NSError* error = NULL; AVAssetTrack *audioAsset = (AVAssetTrack*)[allAudio objectAtIndex:i]; AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset.duration) ofTrack:audioAsset atTime:kCMTimeZero error:&error]; NSLog(@"Error : %@", error); }
source share