Skip to content

Instantly share code, notes, and snippets.

@dhilipsiva
Created August 12, 2012 02:46
Show Gist options
  • Save dhilipsiva/3329218 to your computer and use it in GitHub Desktop.
Save dhilipsiva/3329218 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad {
[super viewDidLoad];
[self setSession:[[AVCaptureSession alloc] init]];
[_session setSessionPreset:AVCaptureSessionPresetHigh];
[self setViewLayer:self.vPreview.layer];
[self setCaptureVideoPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:_session]];
[_captureVideoPreviewLayer setFrame:[_vPreview bounds]];
if ([_captureVideoPreviewLayer isOrientationSupported]) {
[_captureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}
[_captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[_vPreview.layer addSublayer:_captureVideoPreviewLayer];
[self setDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]];
NSError *error = nil;
[self setInput:[AVCaptureDeviceInput deviceInputWithDevice:_device error:&error]];
if (!_input) {
NSLog(@"ERROR: trying to open camera: %@", error);
}
[_session addInput:_input];
[self setStillImageOutput:[[AVCaptureStillImageOutput alloc] init]];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];
[_session addOutput:_stillImageOutput];
[_session startRunning];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment