gpt4 book ai didi

objective-c - 为什么唯一可用的 AVAssetExportSession.outputFileType = AVFileTypeQuickTimeMovie

转载 作者:可可西里 更新时间:2023-11-01 05:31:15 24 4
gpt4 key购买 nike

我设置了一个 AVAssetExportSession,只有 2 个音频轨道,没有视频,它在 AVPlayer 中播放时就像我想要的那样 - 但是当我开始的时候要导出它,唯一可用的 outputFileTypeAVFileTypeQuickTimeMovie - 为什么我不能选择音频格式?

当我 NSLog(@"%@", [session supportedFileTypes]); 我得到;

[51330:c07] (
"com.apple.quicktime-movie"
)

这是我的代码;

- (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;
}
}];
}

最佳答案

啊对了所以它只给我 quicktime 电影选项的原因是因为我的预设设置为 AVAssetExportPresetMediumQuality 我猜这是一个视频预设。我将我的预设设置为 AVAssetExportPresetAppleM4A 并将输出文件类型设置为 AVFileTypeAppleM4A 并且导出成功!

关于objective-c - 为什么唯一可用的 AVAssetExportSession.outputFileType = AVFileTypeQuickTimeMovie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12165297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com