如何从录制的视频文件中提取音频

时间:2015-02-21 08:35:12

标签: objective-c ios8 avassetexportsession avmetadataitem

  • 您好我正在处理audio文件中仅提取video
  • 这在< iOS 8.0版本中有效,但在>= iOS 8.0版本中无效。
  • 如何在>= iOS 8.0版本中提取音频?

1 个答案:

答案 0 :(得分:4)

使用AVAssetExportSession将视频文件转换为音频。 您可以使用此方法。

- (void)convertVideoToAudioWithInputURL:(NSURL*)inputURL
                                   outputURL:(NSURL*)outputURL
                                     handler:(void (^)(AVAssetExportSession*))handler
{
    AVURLAsset* asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    self.exportSession = [[AVAssetExportSession alloc] initWithAsset:asset
                                                          presetName: AVAssetExportPresetPassthrough];
    self.exportSession.outputURL = outputURL;
    self.exportSession.outputFileType = AVFileTypeAppleM4A; //For audio file
    self.exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]);

        [self.exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
            handler(self.exportSession);
        }];
}

处理outputUrl中的文件以供进一步使用。 :)

相关问题