Was*_*sim 4 objective-c avfoundation ios avassetexportsession
我已经设置了一个AVAssetExportSession只有2个音轨和没有视频的音轨,它就像我想要的那样播放AVPlayer- 但是当我去导出它时,唯一可用的outputFileType是AVFileTypeQuickTimeMovie- 为什么我不能选择音频格式?
当我NSLog(@"%@", [session supportedFileTypes]);得到;
[51330:c07] (
"com.apple.quicktime-movie"
)
Run Code Online (Sandbox Code Playgroud)
这是我的代码;
- (AVMutableComposition *)getComposition {
AVAsset *backingAsset = [AVAsset assetWithURL:self.urlForEightBarAudioFile];
AVAsset *vocalsAsset = [AVAsset assetWithURL:self.recorder.url];
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionBackingTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionVocalTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *backingAssetTrack = [backingAsset.tracks objectAtIndex:0];
AVAssetTrack *vocalsAssetTrack = [vocalsAsset.tracks objectAtIndex:0];
CMTimeRange timeRange = CMTimeRangeFromTimeToTime(kCMTimeZero, backingAsset.duration);
[compositionBackingTrack insertTimeRange:timeRange ofTrack:backingAssetTrack atTime:kCMTimeZero error:nil];
[compositionVocalTrack insertTimeRange:timeRange ofTrack:vocalsAssetTrack atTime:kCMTimeZero error:nil];
return composition;
}
- (IBAction)acceptRecording:(id)sender {
AVAssetExportSession * session = [[AVAssetExportSession alloc] initWithAsset:[self getComposition] presetName:AVAssetExportPresetMediumQuality];
NSURL *output = [self.urlForPathToEightBarRecordings URLByAppendingPathComponent:@"mix.mov"];
session.outputURL = output;
session.outputFileType = AVFileTypeQuickTimeMovie;
NSLog(@"%@", [session supportedFileTypes]);
[session exportAsynchronouslyWithCompletionHandler:^() {
switch (session.status) {
case AVAssetExportSessionStatusCompleted:
NSLog(@"It's done...hallelujah");
break;
default:
break;
}
}];
}
Run Code Online (Sandbox Code Playgroud)
啊对,所以它之所以只给我选择快速电影的原因是因为我的预设设置为AVAssetExportPresetMediumQuality我想的视频预设.我将我的预设设置为AVAssetExportPresetAppleM4A,输出文件类型为AVFileTypeAppleM4A和导出成功!