piemonte/PBJVision


📸 iOS Media Capture – features touch-to-record video, slow motion, and photography

http://pbj.vision

License: MIT

Language: Objective-C

Keywords: avfoundation, camera, capture, ios, media, objective-c, photography, recording, snapchat, video, vine


PBJVision

PBJVision

PBJVision is a camera library for iOS that enables easy integration of special capture features and camera interface customizations in your iOS app. Next Level is the Swift counterpart.

Build Status Pod Version

Features

  • touch-to-record video capture
  • slow motion capture (120 fps on supported hardware)
  • photo capture
  • customizable user interface and gestural interactions
  • ghosting (onion skinning) of last recorded segment
  • flash/torch support
  • white balance, focus, and exposure adjustment support
  • mirroring support

Capture is also possible without having to use the touch-to-record gesture interaction as the sample project provides.

About

This library was originally created at DIY as a fun means for kids to author video and share their skills. The touch-to-record interaction was pioneered by Vine and Instagram.

Thanks to everyone who has contributed and helped make this a fun project and community.

Quick Start

PBJVision is available and recommended for installation using the dependency manager CocoaPods.

To integrate, just add the following line to your Podfile:

pod 'PBJVision'

Usage

Import the header.

#import "PBJVision.h"

Setup the camera preview using [[PBJVision sharedInstance] previewLayer].

    // preview and AV layer
    _previewView = [[UIView alloc] initWithFrame:CGRectZero];
    _previewView.backgroundColor = [UIColor blackColor];
    CGRect previewFrame = CGRectMake(0, 60.0f, CGRectGetWidth(self.view.frame), CGRectGetWidth(self.view.frame));
    _previewView.frame = previewFrame;
    _previewLayer = [[PBJVision sharedInstance] previewLayer];
    _previewLayer.frame = _previewView.bounds;
    _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [_previewView.layer addSublayer:_previewLayer];

If your view controller is managed by a Storyboard, keep the previewLayer updated for device sizes

- (void)viewDidLayoutSubviews
{
    _previewLayer.frame = _previewView.bounds;
}

Setup and configure the PBJVision controller, then start the camera preview.

- (void)_setup
{
    _longPressGestureRecognizer.enabled = YES;

    PBJVision *vision = [PBJVision sharedInstance];
    vision.delegate = self;
    vision.cameraMode = PBJCameraModeVideo;
    vision.cameraOrientation = PBJCameraOrientationPortrait;
    vision.focusMode = PBJFocusModeContinuousAutoFocus;
    vision.outputFormat = PBJOutputFormatSquare;

    [vision startPreview];
}

Start/pause/resume recording.

- (void)_handleLongPressGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
    switch (gestureRecognizer.state) {
      case UIGestureRecognizerStateBegan:
        {
            if (!_recording)
                [[PBJVision sharedInstance] startVideoCapture];
            else
                [[PBJVision sharedInstance] resumeVideoCapture];
            break;
        }
      case UIGestureRecognizerStateEnded:
      case UIGestureRecognizerStateCancelled:
      case UIGestureRecognizerStateFailed:
        {
            [[PBJVision sharedInstance] pauseVideoCapture];
            break;
        }
      default:
        break;
    }
}

End recording.

    [[PBJVision sharedInstance] endVideoCapture];

Handle the final video output or error accordingly.

- (void)vision:(PBJVision *)vision capturedVideo:(NSDictionary *)videoDict error:(NSError *)error
{   
    if (error && [error.domain isEqual:PBJVisionErrorDomain] && error.code == PBJVisionErrorCancelled) {
        NSLog(@"recording session cancelled");
        return;
    } else if (error) {
        NSLog(@"encounted an error in video capture (%@)", error);
        return;
    }

    _currentVideo = videoDict;
    
    NSString *videoPath = [_currentVideo  objectForKey:PBJVisionVideoPathKey];
    [_assetLibrary writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoPath] completionBlock:^(NSURL *assetURL, NSError *error1) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Video Saved!" message: @"Saved to the camera roll."
                                                       delegate:self
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"OK", nil];
        [alert show];
    }];
}

To specify an automatic end capture maximum duration, set the following property on the 'PBJVision' controller.

    [[PBJVision sharedInstance] setMaximumCaptureDuration:CMTimeMakeWithSeconds(5, 600)]; // ~ 5 seconds

To adjust the video quality and compression bit rate, modify the following properties on the PBJVision controller.

    @property (nonatomic, copy) NSString *captureSessionPreset;

    @property (nonatomic) CGFloat videoBitRate;
    @property (nonatomic) NSInteger audioBitRate;
    @property (nonatomic) NSDictionary *additionalCompressionProperties;

Community

Contributions and discussions are welcome!

Project

Related Projects

Resources

License

PBJVision is available under the MIT license, see the LICENSE file for more information.

Project Statistics

Sourcerank 11
Repository Size 2.09 MB
Stars 1,868
Forks 339
Watchers 77
Open issues 49
Dependencies 0
Contributors 31
Tags 29
Created
Last updated
Last pushed

Top Contributors See all

patrick piemonte misslester Danny Espinoza Josh Sklar Yury Korolev Ward van Teijlingen Ryan Romanchuk Max Sysenko Jeff Burt Paul Taykalo Wil Gieseler Felix New Antoine Marcadet Ben Cherry Yunarta Kartawahyudi Carlos David Rios Vertel Pete Adam Proschek Alex Bobrikovich jhk115

Packages Referencing this Repo

PBJVision
iOS camera engine, supports touch-to-record video, slow motion video, and photo capture.
Latest release 0.5.2 - Updated - 1.87K stars

Recent Tags See all

0.6.1 February 23, 2019
0.6.0 December 18, 2018
0.5.2 April 19, 2017
0.5.1 December 08, 2016
0.5.0 August 10, 2016
v0.4.2 May 29, 2015
v0.4.1 April 16, 2015
v0.4.0 December 24, 2014
v0.3.5 November 11, 2014
v0.3.4 October 20, 2014
v0.3.3 September 24, 2014
v0.3.2 August 26, 2014
v0.3.1 July 08, 2014
v0.3.0 July 04, 2014
v0.2.4 June 06, 2014

Interesting Forks See all

rFlex/PBJVision
iOS camera engine, features touch-to-record video, slow motion video, and photo capture
Objective-C - MIT - Updated - 2 stars
denivip/PBJVision
iOS camera engine, features touch-to-record video, slow motion video, and photo capture
Objective-C - MIT - Last pushed - 1 stars
gabrielPeart/PBJVision
iOS camera engine, features touch-to-record video, slow motion, and photo capture
Objective-C - Updated - 1 stars
peterkinalex/PBJVision
iOS camera engine, features touch-to-record video, slow motion video, and photo capture
MIT - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2018-10-23 22:28:46 UTC

Login to resync this repository