Latest 0.1.8
License MIT
Platforms ios 8.0, requires ARC
Dependencies PGMTimer


CI Status
Carthage compatible

Swift library to provide all the configurations you need to create a camera view:

  • Start / pause / resume / stop recording
  • Video compression
  • Save / Fetch videos & images from the media library
  • Set max video duration threshold
  • Follow camera orientation change
  • Front and back camera
  • Flash modes
  • Video / still image modes
  • Output quality


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



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

pod "PGMCameraKit"

Installation with Carthage

Carthage is another dependency management tool written in Swift.

Add the following line to your Cartfile:

github "pablogm/CameraKit"

How to use

Init Camera Kit:

let cameraManager       = PGMCameraKit()

Init Camera Kit Helper (util functions to save images/videos, retrieve images/videos from media library and compress video output)

let helper              = PGMCameraKitHelper()

Ask user for camera permissions:

cameraManager.askUserForCameraPermissions({ [unowned self] permissionGranted in

    if permissionGranted {
    else {
        self.addCameraAccessDeniedPopup("Go to settings and grant acces to the camera device to use it.")

Set video time limit.

cameraManager.maxRecordedDuration = 4.0 // secs


// Errors
cameraManager.addCameraErrorListener( { error in


// Time progress
cameraManager.addCameraTimeListener( { time in

    print("Time elapsed: (time) seg")

// Video time limit
cameraManager.addMaxAllowedLengthListener({ [unowned self] (videoURL, error, localIdentifier) -> () in

    if let err = error {
        print("Error (err)")
    else {

        if let url = videoURL {

            print("Saved video from local url (url) with uuid (localIdentifier)")

            let data = NSData(contentsOfURL: url)!

            print("Byte Size Before Compression: (data.length / 1024) KB")


Start recording video:

cameraManager.startRecordingVideo( {(error)->() in

    if let err = error {
        print("Error ocurred: (err)")

Pause recording:


Resume recording:


Stop recording:

cameraManager.stopRecordingVideo( { (videoURL, error, localIdentifier) -> () in

    if let err = error {
        print("Error ocurred: (err)")
    else {
        print("Video url: (videoURL) with unique id (localIdentifier)")

Video compression:

// The compress file extension will depend on the output file type
self.helper.compressVideo(url, outputURL: self.cameraManager.tempCompressFilePath("mp4"), outputFileType: AVFileTypeMPEG4, handler: { session in

    if let currSession = session {

        print("Progress: (currSession.progress)")

        print("Save to (currSession.outputURL)")

        if currSession.status == .Completed {

            if let data = NSData(contentsOfURL: currSession.outputURL!) {

            print("File size after compression: (data.length / 1024) KB")

            // Play compressed video
            dispatch_async(dispatch_get_main_queue(), {

                let player  = AVPlayer(URL: currSession.outputURL!)
                let layer   = AVPlayerLayer(player: player)
                layer.frame = self.view.bounds

                print("Playing video...")
        else if currSession.status == .Failed
            print(" There was a problem compressing the video maybe you can try again later. Error: (currSession.error!.localizedDescription)")


Supports iOS8 and above. XCode 7.0 is required to build the latest code written in Swift 2.0


pablogm, [email protected]


CameraKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "PGMCameraKit",
    "version": "0.1.8",
    "summary": "Camera library to record video (inc pause and resume features), compress video and fully customize the camera.",
    "description": "Swift library to provide all the configurations you need to create a camera view: start / pause / resume / stop recording, video compression, max video duration threshold, it follows camera orientation change, front and back camera, flash modes, video / still image modes, output quality, etc...",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Pablo GM": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.8"
    "platforms": {
        "ios": "8.0"
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "CameraKit": [
    "dependencies": {
        "PGMTimer": []

Pin It on Pinterest

Share This