iOS Record video with audio from a file

狂风中的少年 提交于 2020-02-07 03:34:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!