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

时间:2012-08-28 18:28:35

标签: objective-c ios avfoundation avassetexportsession

我设置了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;
        }
    }];
}

2 个答案:

答案 0 :(得分:6)

啊,这就是为什么它只给我一个quicktime电影选项的原因是因为我的预设被设置为AVAssetExportPresetMediumQuality这是我猜的视频预设。我将预设设置为AVAssetExportPresetAppleM4A,输出文件类型设置为AVFileTypeAppleM4A,导出成功!

答案 1 :(得分:0)

您可以将这些设置用于128kbps

预设时间:AVAssetExportPresetMediumQuality

OutputfileType AVFileTypeMPEG

格式:mp4