Skip to content

Camera framework facilitating capturing photo & video on iOS

License

Notifications You must be signed in to change notification settings

macistador/CameraKit

Repository files navigation

CameraKit

Camera framework facilitating capturing photo & video on iOS

Features

  • Video capture
  • Photo capture
  • Supports filters
  • Builtin background removal filter with fast preview & accurate recording quality
  • Builtin SwiftUI preview view
  • Lightweight

Requirements

  • iOS 15.0+
  • Xcode 12.0+
  • Swift 5.5+

Installation

SwiftPackageManager

dependencies: [
    .package(url: "https://github.com/macistador/CameraKit", from: "0.0.2")
]

Usage

Preview

With SwiftUI

        VStack {
            CameraPickerView(cameraSessionDelegate: viewModel,
                             captureMode: .video,
                             cameraDirection: .front,
                             captureResolution: .fullHd,
                             videoFilter: .removeBackground) { controller in
                cameraController = controller
            }
            
            Circle()
                .fill(.red)
                .frame(width: 70, height: 70)
                .onTapGesture {
                    cameraController.recordVideoTapped()
                }
        }

With UIKit

    func setupCamera() {
        let cameraViewController = CameraViewController(captureMode: .photo,
                                                        cameraDirection: .back,
                                                        captureResolution: .uhd4K, 
                                                        videoFilter: .none,
                                                        delegate: self)
        self.cameraController = cameraViewController
        addChild(cameraViewController)
        cameraViewController.view.frame = view.frame
        view.addSubview(cameraViewController.view)
        cameraViewController.didMove(toParent: self)
    }

Callbacks

Your object needs to conforms CameraSessionDelegate

extension DemoCameraView: CameraSessionDelegate {
    
    func isReadyToRecord() {
        self.state = .readyToRecord
    }
    
    func didStartRecording() {
        self.state = .recording
    }
    
    // Video
    func didCapture(videoURL: URL) {
        self.state = .recorded
        self.videoUrl = videoURL
        presentPreview = true
    }
    
    // Photo
    func didCapture(imageData: Data) {
        self.state = .recorded
        self.photoData = imageData
        presentPreview = true
    }
    
    func failed(withError error: any Error) {
        self.state = .failed
        self.errorMessage = error.localizedDescription
    }
}

For more details you may take a look at the sample project.

Other packages

Meanwhile this library works well alone, it is meant to be complementary to the following app bootstrap packages suite:

Credits

CameraKit is developed and maintained by Michel-André Chirita. You can follow me on Twitter at @Macistador for updates.

License

CameraKit is released under the MIT license. See LICENSE for details.

About

Camera framework facilitating capturing photo & video on iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages