Latest 0.2.0
Homepage https://github.com/lawrnce/GifCameraController
License MIT
Platforms ios 9.0, requires ARC
Authors

Gif Camera Controller

Gif Camera Controller is a camera output that takes successive photos to create GIFs.

Version
License
Platform

Features

  • Full camera functionality
  • Control frames per second

Usage

Instantiate a GifCameraController and run setupSession() in a do-catch statement. To see the camera’s preview use a GifCameraPreview view.
Note that GifCameraPreview is currently not supported in interface builder. You must instantiate in code.

var gifCamera: GifCameraController!
var previewView: GifCameraPreviewView!
self.gifCamera = GifCameraController()
do {
    if try self.gifCamera.setupSession() {
    self.gifCamera.setPreviewView(self.previewView)
    }
} catch let error as NSError {
    self.gifCamera = nil
    print(error.localizedDescription)
}

Then set the duration and frames per second.

self.gifCamera.maxDuration = 2.0
self.gifCamera.framesPerSecond = 3

Begin the capture session and start recording.

self.gifCamera.startSession()
self.gifCaemra.startRecording()

When recording finishes, the delegate will output the frames.

Documentation

Variables

var delegate: GifCameraControllerDelegate

The delegate for the camera controller. This must be set.

var maxDuration: Double

The maximum duration of the gif. Defaults to 4 seconds.

var framesPerSecond: Int

The capture rate of the camera. Defaults to 18 fps.

var currentDevicePosition: AVCaptureDevicePosition

The current device position. (read-only)

Methods

func setupSession() throws -> Bool

Setup the camera controller. This must be called before the sessiong begins.

func setPreviewView(view: GifCameraPreviewView)

Adds a preview view to the camera controller. You must instantiate GifCameraPreviewView in code.

func startSession()

Starts the capture session.

func stopSession()

Stops the capture session.

func isRecording() -> Bool

Returns if session is recording.

func startRecording()

Starts recording.

func pauseRecording() 

Pauses recording. Does not reset current parameters.

func cancelRecording()

Stops recording and resets all variables.

func stopRecording()

Ends the recording.

func toggleCamera()

Toggles between the front camera and the back. Note GifCameraController defaults to the front camera.

func toggleTorch(forceKill forceKill: Bool) -> Bool

Toggles the torch and returns if the torch is on. Set forceKill to true to turn off the torch.

Delegate

func cameraController(cameraController: GifCameraController, didFinishRecordingWithFrames frames: [CGImage], withTotalDuration duration: Double)

Returns to the delegate the bitmaps the frames along with the duration of the gif. This is called with stopRecording() or when maxDuration is reached.

func cameraController(cameraController: GifCameraController, didAppendFrameNumber index: Int)

Notifies the delegate that a frame was appended.

Demo

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 3.0+
  • iOS 9.0+

Installation

GifCameraController is available through CocoaPods. To install
it, simply add the following line to your Podfile:

use_frameworks!
pod "GifCameraController"

Author

Lawrence Tran

License

See the LICENSE file for more info.

Latest podspec

{
    "name": "GifCameraController",
    "version": "0.2.0",
    "summary": "Camera output that takes successive photos to create GIFs",
    "description": "Gif Camera Controller is an implementation of AVCaptureVideoDataOuput to takes successive photos.",
    "homepage": "https://github.com/lawrnce/GifCameraController",
    "license": "MIT",
    "authors": {
        "Lawrence Tran": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lawrnce/GifCameraController.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This