问题
I am attempting to use RPScreenRecorder.shared().startCapture to save a screen recording to firebase. I know how to save videos from AVCapture but cant figure out how to process The CMSampleBuffer to create a file to save to firebase. Please help I cant find documentation on this anywhere yet, here is the method call:
let recorder = RPScreenRecorder.shared()
if #available(iOS 11.0, *) {
recorder.startCapture(handler: { (videoBuffer, bufferType, error) in
print(videoBuffer)
print(bufferType)
}, completionHandler: { (error) in
})
} else {
// Fallback on earlier versions
}
Even being pointed in the right direction would be helpful, I am lost at how to save THE sample BUFFER as a file that can be played as a video
回答1:
RPScreenRecorder.shared().startCapture(handler: { (sample, bufferType, error) in
if CMSampleBufferDataIsReady(sample)
{
self.showOverlayWindow()
if self.assetWriter.status == AVAssetWriterStatus.unknown
{
self.assetWriter.startWriting()
self.assetWriter.startSession(atSourceTime: CMSampleBufferGetPresentationTimeStamp(sample))
}
if self.assetWriter.status == AVAssetWriterStatus.failed {
print("Error occured, status = \(self.assetWriter.status.rawValue), \(self.assetWriter.error!.localizedDescription) \(String(describing: self.assetWriter.error))")
return
}
if (bufferType == .video)
{
if self.videoInput.isReadyForMoreMediaData
{
self.videoInput.append(sample)
}
}
}
}) { (error) in
debugPrint(error)
}
Details of code can be found here
来源:https://stackoverflow.com/questions/46945152/saving-a-screen-recording-with-rpscreenrecorder-start-capture