1
  • 您好,我正在研究仅从audio文件video中提取。
  • 那在< iOS 8.0版本中有效,但在版本中无效>= iOS 8.0
  • 如何提取>= iOS 8.0版本中的音频?
4

1 回答 1

6

使用 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 处处理文件以供进一步使用。:)

于 2015-02-21T16:09:45.893 回答