问题
I am creating and app where I want the user to be able to record a video but have audio from a pre-recorded audio file. I have implemented the video capture and can even play the audio while recording, but I do not want the microphone on, I would like the audio to come from a file.
I am currently adding the audio input device like so:
let audioInputDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
do
{
let audioInput = try AVCaptureDeviceInput(device: audioInputDevice)
if captureSession.canAddInput(audioInput)
{
captureSession.addInput(audioInput)
}
else
{
// can't add audio
}
}
catch let error
{
print("error getting AVCaptureDeviceInput: \(error)")
}
and I am configuring the session as follows:
let audioCaptureDevice = AVCaptureDevice.default(for: AVMediaType.audio)
do
{
let audioCaptureDeviceInput = try AVCaptureDeviceInput(device: audioCaptureDevice!)
if captureSession.canAddInput(audioCaptureDeviceInput)
{
captureSession.addInput(audioCaptureDeviceInput)
}
else
{
// can't add audio input
}
}
catch let error
{
print("error getting AVCaptureDeviceInput: \(error)")
}
So are my questions?
1) Is there any way to specify the input device as an audio file?
2) Should this be done with, AVAssetWriter or another method?
3) Does anyone have any clues where to find any examples of this?
Thanks for any help!!!
来源:https://stackoverflow.com/questions/57927318/ios-record-video-with-audio-from-a-file