Question

I'm exporting audio.caf audio file with video.mp4 video and creating a new output.mp4 composition. It works fine with iOS 5.0, but with an iPhone4 4.2.1, the composition doesn't play the audio.

NSURL *outputURL = [NSURL fileURLWithPath:outputPath];
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
_assetExport.outputURL = outputURL;
_assetExport.timeRange = CMTimeRangeMake(CMTimeMakeWithSeconds(0.25, 600), videoAsset.duration);
_assetExport.shouldOptimizeForNetworkUse = YES;

[_assetExport exportAsynchronouslyWithCompletionHandler:^{

I've checked the original tracks in this iphone and both are ok, only the composition doesn't add the audio.

This is how I'm adding the audio track to the composition:

NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioURL options:nil];
CMTimeRange audio_timeRange = CMTimeRangeMake(CMTimeMake(startRecording_,1), 
                                              audioAsset.duration);

AVMutableCompositionTrack *b_compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

[b_compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:&error];

It worked in many iOS5 devices :S

Thanks in advance!

Was it helpful?

Solution

I changed audio to .m4a audio and it's working now!

OTHER TIPS

I found that I needed to change the file extension to 'mov' then do my export (im using PassThrough preset), then change it back to mp3 (in my case). Seems like a bug....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top