我想为用户添加一项功能,以记录他们的ARKit
体验。我正在使用capturedImage
提供的ARFrame
session(_ session: ARSession, didUpdate frame: ARFrame)
并将其连接成视频。
不幸的是,ARFrame.capturedImage
显示了相机捕获的视频帧,但不包含ARKit放置的节点。
有没有办法捕获来自ARSCNView
的视频?
我已经尝试了this library,但它有很大的错误(没有阴影,在录制开始时有大的口吃)。我也不想在这个项目中使用ReplayKit。
以下是我使用ARFrame.capturedImage
转换为UIImage
以及随后的视频。
extension UIImage {
convenience init(pixelBuffer: CVPixelBuffer) {
let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
let size = CGSize(width: CVPixelBufferGetWidth(pixelBuffer), height: CVPixelBufferGetHeight(pixelBuffer))
let tempContext = CIContext()
let image = tempContext.createCGImage(ciImage, from: CGRect(origin: CGPoint.zero, size: size))!
// This assumes we're using an iPhone in portrait.
self.init(cgImage: image, scale: 1, orientation: .right)
}
}
答案 0 :(得分:0)
我实际上找到了一个库来执行此操作。这是SceneKitVideoRecorder。
我还不完全了解其工作原理,但重要的代码位于SceneKitVideoRecorder.swift。
答案 1 :(得分:-1)
您可以尝试使用 ReplayKit 。我在AR应用程序中使用ReplayKit来记录何时将模型放置到场景中等等。
试试这个我的代码:
import ReplayKit
class YourController: UIViewController, RPPreviewViewControllerDelegate {
@IBAction func shotVideo(_ sender: UIButton) {
print("Video")
if !isRecording {
startRecording()
} else {
stopRecording()
}
}
func startRecording() {
guard recorder.isAvailable else {
print("The recording isn't available now.")
return
}
recorder.isMicrophoneEnabled = false
recorder.startRecording{ [unowned self] (error) in
guard error == nil else {
print("Trouble with starting this recording.")
return
}
print("Recording started with success.")
self.isRecording = true
}
}
func stopRecording() {
recorder.stopRecording { (preview, error) in
print("The recording is stopped")
guard preview != nil else {
print("The preview controller isn't available.")
return
}
let alert = UIAlertController(title: "End Recording", message: "Want to edit or delete this recording?", preferredStyle: .alert)
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action: UIAlertAction) in
self.recorder.discardRecording(handler: { () -> Void in
print("Recording suffessfully deleted.")
})
})
let editAction = UIAlertAction(title: "Edit", style: .default, handler: { (action: UIAlertAction) -> Void in
preview?.previewControllerDelegate = self
self.present(preview!, animated: true, completion: nil)
})
alert.addAction(editAction)
alert.addAction(deleteAction)
self.present(alert, animated: true, completion: nil)
self.isRecording = false
}
}
// RPPreviewViewControllerDelegate
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
dismiss(animated: true)
}
}
这是我的代码,我希望我有所帮助:)。