Coder Social home page Coder Social logo

yippeeapp / pbjvision Goto Github PK

View Code? Open in Web Editor NEW

This project forked from piemonte/pbjvision

0.0 3.0 0.0 3.42 MB

iOS camera engine, features touch-to-record video, slow motion video, and photo capture

License: MIT License

Ruby 0.42% Objective-C 99.58%

pbjvision's Introduction

PBJVision

PBJVision

PBJVision is an iOS camera engine library that allows easy integration of special capture features and camera customization in your iOS app.

Build Status Pod Version

Features

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

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

If you need a video player, check out PBJVideoPlayer (obj-c) and Player (Swift).

Contributions are welcome!

About

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

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

Installation

CocoaPods

PBJVision is available and recommended for installation using the Cocoa 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];

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

Resources

License

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

pbjvision's People

Contributors

piemonte avatar despinoza avatar yury avatar rromanchuk avatar wvteijlingen avatar jeffaburt avatar paultaykalo avatar wilg avatar amarcadet avatar bcherry avatar maxrandom avatar petec avatar lexmiln avatar riosc avatar ethanjdiamond avatar finbarr avatar nolegirl avatar autresphere avatar cacheflowe avatar n-studio avatar

Watchers

Chew Chit Siang avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.