TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Kirill Kunst.
BDCamera is a simple video and photo camera with AVFoundation.
platform :ios, '7.0'
pod "BDCamera", "~> 0.1"
Drag the BDCamera folder to your project. This library must be ARC enabled.
At first import class for photo
#import "BDStillImageCamera.h"
or video
#import "BDCamera.h"
Make property for your camera
@property (nonatomic, strong) BDStillImageCamera *camera;
// or
@property (nonatomic, strong) BDCamera *camera;
Next, all you need is a UIView container in your controller for camera preview layer.
UIView *cameraView = [[UIView alloc] initWithFrame:self.view.bounds];
self.camera = [[BDStillImageCamera alloc] initWithPreviewView:self preset:AVCaptureSessionPresetPhoto];
//or
self.camera = [[BDCamera alloc] initWithPreviewView:self preset:AVCaptureSessionPreset1280x720];
[self.camera startCameraCapture];
[self.view addSubview:cameraView];
Make a photo
[self.camera captureImageWithCompletion:^(UIImage *capturedImage, NSError *error) {
// your captured image
}];
Video Camera has a delegate that gives you url for your recorded video. You need to set a videoDelegate for camera.
self.camera.videoDelegate = self;
Start record video
NSURL *movieURL = //url for video output file
self.camera startRecordingWithURL:movieURL];
Stop recording
[self.camera stopRecording];
Video output will we sended in videoDelegate
- (void)didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL error:(NSError *)error
{
// here you can save your recorded video to Photos, for example.
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary writeVideoAtPathToSavedPhotosAlbum:outputFileURL completionBlock:^(NSURL *assetURL, NSError *error) {
[[NSFileManager defaultManager] removeItemAtURL:url error:nil];
[self showSuccessAlert];
}];
}
Examples of using BDCamera included in example project.
You can recording slow motion videos with switching output FPS. Max FPS for iPhone 5 - 60. Max FPS for iPhone 5S - 120. iPhone 5S: BDCamera recording video with AVCaptureMovieFileOutput and you can control your slow-motion videos in Photos.
[self.camera switchFPS:120.f];
BDCamera has a functionality of live previews.
/*
Every item in this array should be BDLivePreview for render live preview
*/
@property (nonatomic, strong) NSMutableArray *displayedPreviews;
BDLivePreview is a subclass of GLKView. You can create BDLivePreview with videoCamera EAGLContext.
//You need to enable sample buffer capturing
[self.camera captureSampleBuffer:YES];
// then create preview views
CGRect frame = //some frame
BDLivePreview *preview = [[BDLivePreview alloc] initWithFrame:frame context:self.camera.eaglContext];
self.camera.displayedPreviews addObject:preview];
[self.view addSubview:preview];
That's all. I have tested BDCamera on 9 live previews.
BDCamera is available under the MIT license. See the LICENSE file for more info.