2017-07-04 94 views
0

我創建了一個自定義相機,迄今爲止完美。我可以錄製視頻並停止錄製,不會出現任何錯誤或錯誤。我想添加到此相機的功能是暫停錄製的功能。使用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 
    } 
} 
+0

你能提供:func captureOutput(_ captureOutput:AVCaptureOutput !, didOutputSampleBuffer sampleBuffer:CMSampleBuffer !,來自連接:AVCaptureConnection!)方法代碼? – ninjaproger

回答

1

您可以AVAssetWriter寫的所有幀。您需要使用AVCaptureVideoDataOutput才能從相機獲取相框。 Here你可以找到一個exmaple。

或者,如果你想合併視頻結帳this教程。