使用AVFoundation暂停视频录制

时间:2017-07-04 01:03:51

标签: ios swift xcode camera avfoundation

我创建了一个到目前为止完美运行的自定义相机。我可以录制视频并停止录制,没有错误或错误。我想要添加到此相机的功能是暂停录制的功能。

经过大量的在线研究后,我发现解决方案是在点击暂停按钮时实际停止录制,并在单击恢复按钮时开始另一次录制。之后,您应该将视频合并在一起。

我不确定如何合并视频,我在线看了很多东西,但却找不到解决方案。

谢谢!

这是我的录制按钮功能

@IBAction func recordVideoButtonPressed(sender:AnyObject) {

    if self.movieFileOutput.isRecording {
        isRecording = false
        self.movieFileOutput.stopRecording()
    } else {
        isRecording = true
        self.movieFileOutput.connection(withMediaType: AVMediaTypeVideo).videoOrientation = self.videoOrientation()
        self.movieFileOutput.maxRecordedDuration = self.maxRecordedDuration()
        self.movieFileOutput.startRecording(toOutputFileURL: URL(fileURLWithPath: self.videoFileLocation()), recordingDelegate: self)
    }

    self.updateRecordButtonTitle()

}

这是我的暂停按钮功能

 func pauseVideo() {
    if isRecording {
        if isPaused == false {
            isPaused = true
            recordButton.isEnabled = false
            recordButton.backgroundColor = UIColor.wetAsphalt
            recordButton.setTitle("Paused", for: .normal)
        } else {
            isPaused = false
            recordButton.isEnabled = true
            recordButton.backgroundColor = UIColor.red
            updateRecordButtonTitle()
        }
    } else {
        return
    }
}

1 个答案:

答案 0 :(得分:1)

您可以使用AVAssetWriter编写所有帧。您需要使用AVCaptureVideoDataOutput从相机中获取帧。 Here你可以找到一个例子。

或者,如果您想合并视频结帐this教程。