[英]Exporting Audio+Video with AVAssetExportSession, but audio not being played in iphone4 4.2.1
I'm exporting audio.caf audio file with video.mp4 video and creating a new output.mp4 composition. 我正在导出带有video.mp4视频的audio.caf音频文件,并创建一个新的output.mp4合成。 It works fine with iOS 5.0, but with an iPhone4 4.2.1, the composition doesn't play the audio. 它在iOS 5.0上可以正常工作,但在iPhone4 4.2.1上,合成无法播放音频。
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. 我已经检查了这部iPhone的原始音轨,而且都没问题,只有乐曲没有添加音频。
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 它适用于许多iOS5设备:S
Thanks in advance! 提前致谢!
我将音频更改为.m4a音频,并且现在可以正常工作!
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). 我发现我需要将文件扩展名更改为'mov',然后进行导出(即使用PassThrough预设),然后将其更改回mp3(在我的情况下)。 Seems like a bug.... 好像是个错误...。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.