- Notifications
You must be signed in to change notification settings - Fork323
📸 iOS Media Capture – features touch-to-record video, slow motion, and photography
License
piemonte/PBJVision
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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.
- Looking for a Swift version? Check outNext Level.
- Looking for a video player? Check outPlayer (Swift) andPBJVideoPlayer (obj-c).
- touch-to-record video capture
- slow motion capture (120 fps onsupported 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.
This library was originally created atDIY as a fun means for kids to author video and share theirskills. The touch-to-record interaction was pioneered byVine andInstagram.
Thanks to everyone who has contributed and helped make this a fun project and community.
PBJVision
is available and recommended for installation using the dependency managerCocoaPods.
To integrate, just add the following line to yourPodfile
:
pod'PBJVision'
Import the header.
#import"PBJVision.h"
Setup the camera preview using[[PBJVision sharedInstance] previewLayer]
.
// preview and AV layer _previewView = [[UIViewalloc]initWithFrame:CGRectZero]; _previewView.backgroundColor = [UIColorblackColor];CGRect previewFrame = CGRectMake(0,60.0f, CGRectGetWidth(self.view.frame), CGRectGetWidth(self.view.frame)); _previewView.frame = previewFrame; _previewLayer = [[PBJVisionsharedInstance]previewLayer]; _previewLayer.frame = _previewView.bounds; _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [_previewView.layeraddSublayer:_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 thePBJVision
controller, then start the camera preview.
- (void)_setup{ _longPressGestureRecognizer.enabled =YES; PBJVision *vision = [PBJVisionsharedInstance]; vision.delegate = self; vision.cameraMode = PBJCameraModeVideo; vision.cameraOrientation = PBJCameraOrientationPortrait; vision.focusMode = PBJFocusModeContinuousAutoFocus; vision.outputFormat = PBJOutputFormatSquare; [visionstartPreview];}
Start/pause/resume recording.
- (void)_handleLongPressGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer{switch (gestureRecognizer.state) {case UIGestureRecognizerStateBegan: {if (!_recording) [[PBJVisionsharedInstance]startVideoCapture];else [[PBJVisionsharedInstance]resumeVideoCapture];break; }case UIGestureRecognizerStateEnded:case UIGestureRecognizerStateCancelled:case UIGestureRecognizerStateFailed: { [[PBJVisionsharedInstance]pauseVideoCapture];break; }default:break; }}
End recording.
[[PBJVisionsharedInstance]endVideoCapture];
Handle the final video output or error accordingly.
- (void)vision:(PBJVision *)vision capturedVideo:(NSDictionary *)videoDict error:(NSError *)error{if (error && [error.domainisEqual:PBJVisionErrorDomain] && error.code == PBJVisionErrorCancelled) {NSLog(@"recording session cancelled");return; }elseif (error) {NSLog(@"encounted an error in video capture (%@)", error);return; } _currentVideo = videoDict;NSString *videoPath = [_currentVideoobjectForKey:PBJVisionVideoPathKey]; [_assetLibrarywriteVideoAtPathToSavedPhotosAlbum:[NSURLURLWithString:videoPath]completionBlock:^(NSURL *assetURL,NSError *error1) { UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"Video Saved!"message:@"Saved to the camera roll."delegate:selfcancelButtonTitle:nilotherButtonTitles:@"OK",nil]; [alertshow]; }];}
To specify an automatic end capture maximum duration, set the following property on the 'PBJVision' controller.
[[PBJVisionsharedInstance]setMaximumCaptureDuration:CMTimeMakeWithSeconds(5,600)];// ~ 5 seconds
To adjust the video quality and compression bit rate, modify the following properties on thePBJVision
controller.
@property (nonatomic, copy)NSString *captureSessionPreset; @property (nonatomic)CGFloat videoBitRate; @property (nonatomic)NSInteger audioBitRate; @property (nonatomic)NSDictionary *additionalCompressionProperties;
Contributions and discussions are welcome!
- Need help? UseStack Overflow with the tag 'pbjvision'.
- Questions? UseStack Overflow with the tag 'pbjvision'.
- Found a bug? Open anissue.
- Feature idea? Open anissue.
- Want to contribute? Submit apull request.
- Next Level, rad media capture in Swift
- Player, a simple iOS video player in Swift
- PBJVideoPlayer, a simple iOS video player in Objective-C
- iOS Device Camera Summary
- AV Foundation Programming Guide
- AV Foundation Framework Reference
- objc.io Camera and Photos
- objc.io Video
- Cameras, ecommerce and machine learning
PBJVision is available under the MIT license, see theLICENSE file for more information.
About
📸 iOS Media Capture – features touch-to-record video, slow motion, and photography