Coder Social home page Coder Social logo

mscaptureview's Introduction

MSCaptureView - NSView subclass to capture video/audio from a Mac internal camera & microphone.

AVFoundation provides all the tools a programmer needs to capture video & audio generated by the Camera and Microphone of a Mac or IOS program. AVCaptureView, part of AVKit, provides a View for displaying the video input and capturing the output to a file. The developer still has to write considerable code to connect the two parts. On the iOS side, Apple provides the often used UIImagePickerController class to combine all the components required to capture video and audio. Surprisingly, there is no such View or Controller on the Mac platform.

Now there is.

MSCaptureView can be used to give simple movie capture ability to any Mac program. Only a few calls are needed to set up the capture. All the functionality is encapsulated with the View, with simple calls to turn the capture on or off.

Installation

Since MSCaptureView is a Swift Package, the IDE or Make file of a project must reference MSCaptureView's repository:

https://github.com/magesteve/MSCaptureView

To clone MSCaptureView, the following Terminal command should be used:

% git clone https://github.com/magesteve/MSCaptureView.git

Platform Specific Usage

MSCaptureView is a NSVIew class; thus it must be added to a programs NSVIewController or NSWindowController. Use Interface Builder to add a generic NSView to the Interface of the App (XIB or Storyboard files). Then change the Views type to MSCaptureView. Create an IBOutlet reference between the view and its controller.

When the program starts, invoke the requestCaptureAuthorization() function so that app asks the user for permission to use the Camera & Microphone. When the view appears, call the showPreview() function to start the video preview. At some point, use the use(url) function to set the output location for the movie to be created. The startCapture() function starts recording to the movie file, while the stopCapture() function halts it. Swift closures can be used to inform the app of state changes by the view (ex: Authorization succeeded, start Movie recording, stop Movie recording).

Documentation

All public classes, protocols, properties & functions have inline documentation (DOxygen style). Further explanation of the Framework, refer to the MSCaptureView-Demo repository or any example projects.

https://github.com/magesteve/MSCaptureView-Demo

Requirements

MSCaptureView requires specific changes to the MacOS program it is running within.

  1. Add NSCameraUsageDescription & NSMicrophoneUsageDescription to Info.plist. (ex: "This app requires the Camera for video capture.")
  2. Add AVFoundation Framework.
  3. Add Sandbox access to Hardware Camera and Audio Input,
  4. Add Sandbox access File Access for the Movie Folder set to Read/Write.

Versions

1.0.0 Initial Release

Future

I would like to add an optional HUD so that start and stop can be done directly within the preview.

Steve Sheets, [email protected]

Originally from Silicon Valley, Steve has been embedded in the software industry for over 35 years. As an expert in user interface and design, he started developer desktop applications for companies like Apple and AOL, moved into mobile development, and is now working in the virtual reality and Augment Reality space. He has taught Objective-C & Swift development classes (MoDev, Learning Tree), as well as given talk on variety of developer topics (DC Mac Dev group, Capital One Swift Conference). He is an avid game player, swordsman and an occasional game designer.

License

MSCaptureView is available under the MIT license. The intent of the project is to be always Open Source and freely available. Please keep me informed of any interesting uses!

mscaptureview's People

Contributors

magesteve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.