- Notifications
You must be signed in to change notification settings - Fork52
The best way to record your AR experience!
License
gorastudio-git/SCNRecorder
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
SCNRecorder allows you to record videos and to capture images from ARSCNView, SCNView and ARView (RealityKit) without sacrificing performance. It gives you an incredible opportunity to share the media content of your augmented reality app or SceneKit based game.
Starting version 2.2.0 SCNRecorder supports Metal only.
- iOS 12.0+
- Xcode 12.0+
- Swift 5.0+
pod'SCNRecorder','~> 2.9'
github"gorastudio/SCNRecorder"
Import the SCNRecorder module.
import SCNRecorder
CallsceneView.prepareForRecording()
atviewDidLoad
.
@IBOutletvarsceneView:SCNView!overridefunc viewDidLoad(){ super.viewDidLoad() sceneView.prepareForRecording()}
And now you can use new functions to capture videos.
try sceneView.startVideoRecording()
sceneView.finishVideoRecording{(videoRecording)in /* Process the captured video. Main thread. */letcontroller=AVPlayerViewController() controller.player=AVPlayer(url: recording.url)self.navigationController?.pushViewController(controller, animated:true)}
To capture an image it is enough to call:
sceneView.takePhoto{(photo:UIImage)in /* Your photo is now here. Main thread. */}
or
sceneView.takePhotoResult{(result:Result<UIImage,Swift.Error>)in /* Result is here. Main thread. */}
Look at the Example project for more details.
To capture video with audio fromARSCNView
enable audio in theARConfiguration
.
letconfiguration=ARWorldTrackingConfiguration()configuration.providesAudioData=truesceneView.session.run(configuration)
To capture audio fromSCNView
you have to implement it by yourself.
varcaptureSession:AVCaptureSession?overridefunc viewDidLoad(){ super.viewDidLoad() sceneView.prepareForRecording()guardlet recorder= sceneView.recorderelse{return}letcaptureSession=AVCaptureSession()guardlet captureDevice=AVCaptureDevice.default(for:.audio)else{return}do{letcaptureInput=tryAVCaptureDeviceInput(device: captureDevice)guard captureSession.canAddInput(captureInput)else{return} captureSession.addInput(captureInput)}catch{print("Can't create AVCaptureDeviceInput:\(error)")}guard captureSession.canAddRecorder(recorder)else{return} captureSession.addRecorder(recorder) captureSession.startRunning()self.captureSession= captureSession}
or, simply
varcaptureSession:AVCaptureSession?overridefunc viewDidLoad(){ super.viewDidLoad() sceneView.prepareForRecording() captureSession=try?.makeAudioForRecorder(sceneView.recorder!)}
Instead of capturing audio using microphone you can play music and add it to video at the same time.
letauidoEngine=AudioEngine()overridefunc viewDidLoad(){ super.viewDidLoad() sceneView.prepareForRecording()do{ audioEngine.recorder= sceneView.recorder // If true, use sound data from audioEngine if any // If false, use sound data ARSession/AVCaptureSession if any sceneView.recorder?.useAudioEngine=trueletplayer=tryAudioEngine.Player(url: url) audioEngine.player= player player.play()}catch{print(\(error))}}
To support recording RealityKit, copyARView+MetalRecordable.swift andARView+SelfSceneRecordable.swift files to your project.Then look atRealityKitViewController.swift for usage.
Look at the Example project for more details.
Thanks toFedor Prokhorov andDmitry Yurlov for testing, reviewing and inspiration.
Made with magic 🪄 atGORA Studio
This project is licensed under the MIT License - see theLICENSE file for details
About
The best way to record your AR experience!