How to extract audio from recorded video file

2.5k Views Asked by At
  • Hello i am working on extract only audio from video file.
  • That is working in < iOS 8.0 version, but it is not working in >= iOS 8.0 version.
  • how to extract audio in >= iOS 8.0 version ?
1

There are 1 best solutions below

2
On

Use AVAssetExportSession to convert video file to audio. You may use this method.

- (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);
        }];
}

Handle the file at outputUrl for further use. :)