GithubHelp home page GithubHelp logo

0k1019 / scnrecorder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gorastudio-ceo/scnrecorder

0.0 0.0 0.0 32.52 MB

The best way to record your AR experience!

License: MIT License

Swift 92.58% Objective-C 3.24% Ruby 0.89% C 1.30% Metal 1.99%

scnrecorder's Introduction

SCNRecorder

GitHub license Platforms Swift Cocoapods compatible Carthage compatible

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.

Sample

Requirements

  • iOS 11.0+
  • Xcode 11.5+
  • Swift 4.2+

Installation

CocoaPods

pod 'SCNRecorder', '~> 2.4'

Carthage

github "gorastudio/SCNRecorder"

Usage

Import the SCNRecorder module.

import SCNRecorder

Call sceneView.prepareForRecording() at viewDidLoad.

@IBOutlet var sceneView: SCNView!

override func 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. */
  let controller = 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.

Audio capture

ARSCNView

To capture video with audio from ARSCNView enable audio in the ARConfiguration.

let configuration = ARWorldTrackingConfiguration()
configuration.providesAudioData = true
sceneView.session.run(configuration)

SCNView

To capture audio from SCNView you have to implement it by yourself.

var captureSession: AVCaptureSession?

override func viewDidLoad() {
  super.viewDidLoad()
  sceneView.prepareForRecording()
  
  guard let recorder = sceneView.recorder else { return }
  let captureSession = AVCaptureSession()
  
  guard let captureDevice = AVCaptureDevice.default(for: .audio) else { return }
  
  do {
    let captureInput = try AVCaptureDeviceInput(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

var captureSession: AVCaptureSession?

override func viewDidLoad() {
  super.viewDidLoad()
  sceneView.prepareForRecording()
  
  captureSession = try? .makeAudioForRecorder(sceneView.recorder!)
}

RealityKit

To support recording RealityKit content copy ARView+MetalRecordable.swift and ARView+SelfSceneRecordable.swift files to your project. Then look at ARViewController.swift for usage.

That's it!

Look at the Example project for more details.

Author

Thanks to Fedor Prokhorov and Dmitry Yurlov for testing, reviewing and inspiration.

License

This project is licensed under the MIT License - see the LICENSE file for details

scnrecorder's People

Contributors

v-grigoriev avatar relax94 avatar gorastudio-ceo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.