ios - 使用 AVFoundation 暂停视频录制

标签 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
    }
}

最佳答案

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

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

关于ios - 使用 AVFoundation 暂停视频录制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44895563/

相关文章:

ios - iphone 越狱开发与公共(public) API

ios - AdHoc Beta 测试的代码签名

swift 3 : Quickly playing sounds on AVAudioPlayerNode

ios - Storyboard "show"segue 在更新到 xcode7 后不起作用(仅在一种情况下)

ios - 当我尝试存档以提交 iOS 应用程序时,我遇到了配置设置冲突错误

ios - 在 Swift 中没有 ViewDidDisappear 的情况下如何调用 ViewWillDisappear

c++ - Direct2D 等效于 IOS OSX 开发

ios - 如何仅在获取数据完成时隐藏我的 UIRefreshControl(在 Swift 中)?

javascript - Typescript/Javascript 中的 Swift 闭包

ios - 在 Swift 中接受整数输入