Video and photo camera for iOS

Overview

version badge Lang platform SPM compatible SwiftLint Sindre codebeat badge Reviewed by Hound

img

Features:

Description
Records video πŸŽ₯
takes photos πŸ“·
Flash on/off ⚑
Front / Back camera ↕️
Hold to record video ✊
Tap to take photo πŸ‘‡
Tap to focus / set exposure πŸ”Ž
Pinch to zoom πŸ‘Œ
Looping video/photo preview πŸ”
Share button πŸ”—
Programatic UI πŸ€–
Doesn't stop Spotify 🎢
Stores files in temporary πŸ’Ύ
Throw oriented code πŸ’£
Persistent app authorisation 🚫
Animated record button πŸ”΄
Callback based πŸ“ž

Why use this camera framework

  • High codebeat GPA
  • Low class scoped variable count (In order to better handle overall state)
  • Setup errors can be handled from the POV of the initiator
  • Operation errors is handled in the onCapture completion block
  • Callback based (as oppose to delegate based) More info
  • Easily styleable (The camera view is separate from the UI view)
  • No third-party libraries or Sugar
  • Entirely programatic (No storyboard)
  • Thoroughly documented (Artifacts and sideEffects etc)
  • Uses Sindre-lint style guide
  • Small footprint, only ~750 LOC (Lines of code)

Notes:

  • In order to keep things simple, The UI is CGRect based. Use your own Autolayout distro like SnapKit etc when adding additional UI

Install:

  • SPM: .package(url: "https://github.com/eonist/HybridCamera.git", .branch("master"))
  • Manual: Open HybridCamera.xcodeproj

IMPORTANT: Make sure info.plist has these variables

Privacy - Microphone Usage Description   
Privacy - Camera Usage Description  
Privacy - Photo Library Additions Usage Description  

Example:

img

Example code:

self.view = HybridCamView()
view.camView.onPhotoCaptureComplete = { (image: UIImage?, url: URL?, error: Error?) in
   Swift.print("On photo capture complete \(url)")
}
hybridCamView.camView.onVideoCaptureComplete = { (url: URL?, error: Error?) in
   Swift.print("On Video capture complete \(url)")
}

Todo:

  • Add support for more orientation modes (Currently only supports portrait)
  • Add support for error resolution from the POV of initiating the camera
  • Make UI with AutoLayout πŸ‘ˆ
  • Make lib carthage support βœ…
  • Fix AudioBug βœ…
  • Fix FontCamera bug w/ IphoneX βœ…
  • Add Spatial, Chaplin as an option to HybridCam πŸ‘ˆ
  • Add CI-Travis πŸ‘ˆ

Contributors:

Comments
  • Memory leak

    Memory leak

    I discovered a memory leak by accident. If you record many videos and cancel all of them right after recording you can see how the memory slowly goes up - until the app crashes: Message from debugger: Terminated due to memory issue I've got to go to bed now so I didn't look into anything. Just wanted to open this issue so I don't forget it. I verified it with the "eonist" "master"

    opened by blurtime 54
  • Develop

    Develop

    This PR contains:

    1. reset zoom after recording
    2. switch between audio sessions such that audio has normal volume when replaying in processMediaView
    3. memory leak virtually fixed

    Regarding the memory leak:

    • I added a few further changes which have now reduced it even more (in VideoPlayerView.swift and ProcessView+Event.swift)
    • there are still some mallocs of a couple of hundred bytes leaking here and there but that's almost nothing

    Carthage still works fine and is building.

    Suggestion: You said you wanted to add animations. Maybe one could move the self.resetZoom into the .onExit closure as originally suggested and instead of suddenly resetting it, zoom out using animations. (I thought putting it outside would fix it. But now one sees how the zoom is suddenly reset shortly before (instead of after) being presented the process media view which I apparently didn't notice yesterday.)

    opened by blurtime 18
  • When will the CocoaPod be released?

    When will the CocoaPod be released?

    I'm feeling slightly embarrassed but I never had to work without CocoaPods yet and somehow cannot install it. I stumbled upon this pod on SO and seriously fell in love with it at first sight. Now I'm somewhat disappointed that I'm apparently too dumb to install the pod without my beloved CocoaPods. I tried downloading the project, opened the HybridCamera.xcodeproj but how do I get this installed to my project? I also wanted to just see what the VC.swift file looks like but I couldn't run it on my iPhone either (under HybridCameraTest it says No such module 'HybridCamLib' and under HybridCamLib it says Build input files cannot be found: ...). I would really appreciate if you could help me and I'm seriously sorry for wasting your time.

    opened by blurtime 17
  • Tapping on the

    Tapping on the "1.0x" button doesn't do anything

    I started running the sample code, and realized that tapping on "1.0x" to change cameras doesn't do anything (just refreshes the current view).

    opened by mathieut 12
  • Volume too low in CustomProcessView

    Volume too low in CustomProcessView

    I'm gonna go ahead and follow your advice of creating issues first and then PRs, so here a small suggestion. I already have the code written out and it works as it's supposed to. But I'm pretty tired now so I am gonna go to bed now and create the PR tomorrow. The issue:

    The videos' volumes seem very low when playing them in the CustomProcessView. The volume is higher, though, when you play them in the Photos app after saving them. Accordingly, I wrote some code to switch back and forth between the AVAudioSession.Categorys .playAndRecord & .playback (the latter for CustomProcessView) such that the volume is normal when playing the video after recording it.

    opened by blurtime 9
  • A couple of ideas

    A couple of ideas

    First things first, I changed the stabilization to .standard since I felt some videos looked pretty shaky with .auto. Moreover, I put all the "connection stuff" together in CamView+Action+Core.swift.

    Now regarding some major changes or rather ideas since I couldn't finish them because I have to prepare for a test in a few days:

    I added 2 gesture recognizers: First of all, I added the double-tap and took care of any issues that one might run into with both tap gestures. Many apps (I usually mean Snapchat, Instagram, etc.) use double-taps to flip the camera and pretty much everyone I know uses it rather than using the button. However, that's where I kind of had to stop due to lack of time. I think one needs to create a new public var holding the camera so that the flipButton and the double-tap gesture are on the same page. I wasn't sure though. I tried adding it in a way that resembles your code.

    Then, I added another gesture: a long press (and also some variables needed for this). Although this gesture isn't supposed to remain added to the previewView but rather to the recordButton (so that while recording you can move your "recording finger" up and it will zoom in with just this one finger; Snapchat uses this, too), I just wanted to see if it would work and therefore jsut tried adding it to the preview. And it does! However, something is very odd about this and this is also the reason why I didn't already add it to the recordButton: I had to use the x-value of the CGPoint even though it should definitely be the y-coordinate. When I used y, however, I would have to long press and then move my finger to the right. It seems like x- and y-coordinates are swapped! Any idea why this is occurring?

    Feel free to tell me if you like these ideas or even work out the rest if you would like to. Moreover, I'm very interested in why x- and y-coordinates seem to be swapped? Especially because I'm wondering now if the same applies to the videos being recorded?

    I won't have a lot of time to code the next 2 days but I'll do as much as I can.

    opened by blurtime 5
  • ResultSugar

    ResultSugar "pin" in `Package.resolved` points to a non-existing commit hash

    According to GitHub, the https://github.com/eonist/ResultSugar.git repo no longer includes this commit:

    https://github.com/eonist/HybridCamera/blob/69014ad7adaa345d0617f6d576e08ffe818562ab/Package.resolved#L9

    $ swift build
    Fetching https://github.com/eonist/ResultSugar.git from cache
    Fetched https://github.com/eonist/ResultSugar.git (0.62s)
    https://github.com/eonist/ResultSugar.git @ 62da1bb61e937dd491cc9cea40f8785a2dc92a08: error: could not find the commit 62da1bb61e937dd491cc9cea40f8785a2dc92a08 in https://github.com/eonist/ResultSugar.git
    

    Deleting Package.resolved resolves this (pun intended :).

    opened by agurtovoy 3
  • Long-press gesture .changed to zoom

    Long-press gesture .changed to zoom

    As I said, I hope there isn't too much further work to be done. carthage update works fine and it does what it's supposed to do.

    There's one small issue remaining, though, which I wasn't sure how or rather where to tackle: After recording a video, the recorded video is shown to the user. If he now saves it or cancels, he will go back to the still zoomed-in camera. But then the code doesn't work anymore as well. Therefore, both startingZoomFactorForLongPress and setZoom(zoomFactor: ) need to be reset (to 1). Still some small insecurities here and there, like I said πŸ™ƒπŸ˜… Hope you like the code πŸ˜ƒ

    opened by blurtime 3
  • Mirror front camera

    Mirror front camera

    This little one-liner mirrors the front camera videos which before didn't look like the preview while recording (what I was talking about in the issue): connection.isVideoMirrored = (connection.isVideoMirroringSupported && device.position == .front && mirrorFrontCamera) mirrorFrontCamera could be made accessible to the user but I didn't bother doing this since that would mean, one would also have to rewrite the createCamView() function, add this variable to the HybridCamView class and I only need it mirrored. Just an idea... Works without mirrorFrontCamera, too, of course.

    I also changed the standard camera to .front. But that's not important.

    opened by blurtime 2
  • Enable user to zoom via record button before actually recording

    Enable user to zoom via record button before actually recording

    I removed an unnecessary condition because it led to unintended errors when trying to zoom using the long-press gesture even though one wasn't yet actually recording.

    opened by blurtime 1
  • Microphone not working

    Microphone not working

    I have just recorded a video upto 30 seconds. When i tried to play video, was playing without audio. May i know, how many seconds i suppose to record? Either 5 or 10?

    opened by Sasi04 1
  • Misssing : platforms (iOS Development target)

    Misssing : platforms (iOS Development target)

    I get the following error when adding HybridCamera Package. On XCode (12.5.1) I have set "iOS Development target" to 12.1

    However, after adding HybridCamera Package, XCode reported an error as shown below, (ex : 'AVCapturePhotoOutput' is only available in iOS 10.0 or newer)

    image

    Did you not add the key platforms to determine the minimum iOS version that can use HybridCamera? How can I fix the above error ? Thanks

    opened by dongnv1991 1
  • Watermark on preview and recorded video

    Watermark on preview and recorded video

    Hi there, congrats on your amazing lib. I am looking to add a Watermark / Overlay on the preview and recorded videos. Could you point me in the direction to achieve something like that?

    opened by ndamofli 1
  • Missing grid view

    Missing grid view

    Hi @eonist , great job with this repo, it looks pretty neat. Apart from the possibility to add filters, one thing which is also missing is a grid view. I can't issue a PR right now, but here is the code:

    class GridView: UIView {
        
        @objc public var color: UIColor = UIColor.white.withAlphaComponent(0.5) {
            didSet {
                self.setNeedsDisplay()
            }
        }
        
        @objc public override init(frame: CGRect) {
            super.init(frame: frame)
            self.setupView()
        }
        
        @objc public required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            self.setupView()
        }
        
        private func setupView() {
            self.backgroundColor = UIColor.clear
        }
        
        private override func draw(_ rect: CGRect) {
            super.draw(rect)
            
            guard let context = UIGraphicsGetCurrentContext() else {
                return
            }
            
            context.setStrokeColor(self.color.cgColor)
            context.setLineWidth(1.0)
            
            let pairs: [[CGPoint]] = [
                [CGPoint(x: rect.width / 3.0, y: rect.minY), CGPoint(x: rect.width / 3.0, y: rect.maxY)],
                [CGPoint(x: 2 * rect.width / 3.0, y: rect.minY), CGPoint(x: 2 * rect.width / 3.0, y: rect.maxY)],
                [CGPoint(x: rect.minX, y: rect.height / 3.0), CGPoint(x: rect.maxX, y: rect.height / 3.0)],
                [CGPoint(x: rect.minX, y: 2 * rect.height / 3.0), CGPoint(x: rect.maxX, y: 2 * rect.height / 3.0)]
            ]
            
            for pair in pairs {
                context.addLines(between: pair)
            }
            
            context.strokePath()
        }
    }
    

    It is a rule-of-third grid, the most common we can find in any camera app.

    If added to the camera view as a subview should not interfere with any gesture recognizer. What's more, a simple UIButton can be used to hide or show the grid.

    Cheers!

    p.s I'm a master of crooked photos.

    opened by mnfro 1
Owner
AndrΓ© J
Building a decentralised password manager at @sentryco
AndrΓ© J
Library for iOS Camera API. CameraKit helps you add reliable camera to your app quickly.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales, and endless camera possibilities.

CameraKit 628 Dec 27, 2022
A simple, customizable camera control - video recorder for iOS.

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video recorder sc

Γ–mer Faruk GΓΌl 1.2k Dec 12, 2022
Easily take a photo or video or choose from library

FDTake Easily take a photo or video or choose from library ?? Author's tip jar: https://amazon.com/hz/wishlist/ls/EE78A23EEGQB Usage To run the exampl

William Entriken 322 Nov 30, 2022
BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience.

Description BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience. Barco

HyperRedink 1.6k Jan 7, 2023
NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally leverage AVFoundation or ARKit.

NextLevel 2k Jan 2, 2023
Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.

?? Warning This repository is DEPRECATED and not maintained anymore. Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS

Tudo Gostoso Internet 1.4k Dec 16, 2022
A fully customisable and modern camera implementation for iOS made with AVFoundation.

Features Extremely simple and easy to use Controls autofocus & exposure Customizable interface Code-made UI assets that do not lose resolution quality

Gabriel Alvarado 1.3k Nov 30, 2022
Fasttt and easy camera framework for iOS with customizable filters

FastttCamera is a wrapper around AVFoundation that allows you to build your own powerful custom camera app without all the headaches of using AVFounda

IFTTT 1.8k Dec 10, 2022
An iOS framework that uses the front camera, detects your face and takes a selfie.

TakeASelfie An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front camera and draws an green oval

Abdullah Selek 37 Jan 3, 2023
ALCameraViewController - A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

Alex Littlejohn 2k Dec 6, 2022
This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

null 0 Nov 2, 2021
A camera designed in Swift for easily integrating CoreML models - as well as image streaming, QR/Barcode detection, and many other features

Would you like to use a fully-functional camera in an iOS application in seconds? Would you like to do CoreML image recognition in just a few more sec

David Okun 868 Dec 29, 2022
iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing

SCRecorder A Vine/Instagram like audio/video recorder and filter framework in Objective-C. In short, here is a short list of the cool things you can d

Simon Corsin 3.1k Dec 25, 2022
A light weight & simple & easy camera for iOS by Swift.

DKCamera Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so the screen-

Bannings 86 Aug 18, 2022
Camera engine for iOS, written in Swift, above AVFoundation. :monkey:

?? The most advanced Camera framework in Swift ?? CameraEngine is an iOS camera engine library that allows easy integration of special capture feature

Remi ROBERT 575 Dec 25, 2022
A Snapchat Inspired iOS Camera Framework written in Swift

Overview SwiftyCam is a a simple, Snapchat-style iOS Camera framework for easy photo and video capture. SwiftyCam allows users to capture both photos

Andrew Walz 2k Dec 21, 2022
UIView+CameraBackground - Show camera layer as a background to any UIView.

UIView+CameraBackground Show camera layer as a background to any UIView. Features Both front and back camera supported. Flash modes: auto, on, off. Co

Yonat Sharon 63 Nov 15, 2022
Simple Swift class to provide all the configurations you need to create custom camera view in your app

Camera Manager This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. It follows orientatio

Imaginary Cloud 1.3k Dec 29, 2022
Mock UIImagePickerController for testing camera based UI in simulator

Mock UIImagePickerController to simulate the camera in iOS simulator.

Yonat Sharon 18 Aug 18, 2022