PBJVision
is an iOS camera engine library that supports touch-to-record video, slow motion video (120 fps on supported hardware), and photo capture.
The library supports features such as onion skinning (ghosting), flash/torch usage, white balance adjustment, focus adjustment, exposure adjustment, and image mirroring. Pause and resume video capture is also possible without having to use the touch gesture interactions as the sample project provides.
I created this library 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 also adopted by Instagram. Thanks to everyone who has contributed and helped make this a fun project and community.
If you need a video player, check out PBJVideoPlayer (obj-c) and Player (Swift).
Please review the release history for a summary of the latest changes and more information.
Contributions are welcome!
CocoaPods is the recommended method of installing PBJVision, just add the following line to your Podfile
:
pod 'PBJVision'
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 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;
- Need help? Use Stack Overflow with the tag 'pbjvision'.
- Questions? Use Stack Overflow with the tag 'pbjvision'.
- Found a bug? Open an issue.
- Feature idea? Open an issue.
- Want to contribute? Submit a pull request.
- AV Foundation Programming Guide
- PBJVideoPlayer, a simple iOS video player in Objective-C
- Player, a simple iOS video player in Swift
PBJVision is available under the MIT license, see the LICENSE file for more information.