I want to process audio from videos using AVAudioEngine
, but I'm not sure how to read the audio from videos using AVAudioEngine
. I have the following code:
let videoURL = /// url pointing to a local video file.
let file = try AVAudioFile(forReading: videoURL)
It works fine on macOS but on iOS it fails with the error message:
[default] ExtAudioFile.cpp:193 about to throw 'typ?': open audio file
[avae] AVAEInternal.h:109 [AVAudioFile.mm:134:AVAudioFileImpl: (ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)): error 1954115647
Error Domain=com.apple.coreaudio.avfaudio Code=1954115647 "(null)" UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)}
Reading through the header files it seems that 'typ?' corresponds to kAudioFileUnsupportedFileTypeError
, so that tells me that the file type is supported on macOS but not on iOS.
So my question is: How can I work with audio from video files in an AVAudioEngine based setup? I already know that I could extract the audio from videos using something like AVAssetExportSession
, but that approach requires extra preprocessing time that I rather not spend.