使用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处处理文件以备将来使用。:)
使用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处处理文件以备将来使用。:)