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

1 objective-c avassetexportsession avmetadataitem ios8

  • 你好,我是唯一的工作提上audiovideo文件。
  • 这在< iOS 8.0版本中有效,但在版本中无效>= iOS 8.0
  • 如何提取>= iOS 8.0版本中的音频?

jar*_*ora 5

使用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);
        }];
}
Run Code Online (Sandbox Code Playgroud)

在outputUrl处处理文件以备将来使用。:)