Capturing video in full screen with AVCaptureSession

I need my app to show a preview of what the front camera is doing, and the dimensions of this video stream must fit the screen size of the device.

But there are black bars appearing at the top and bottom of the preview screen ... enter image description here

How can I capture and view a full screen video? Note. I don't want to resize the video!

Below is my code:

session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];

[session addInput:input];

UIView *cameraPreviewView = [[UIView alloc] initWithFrame:self.view.frame] ;
[self.view addSubview:cameraPreviewView];

AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[session addOutput:output];

dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];

AVCaptureVideoPreviewLayer *cameraPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
cameraPreviewLayer.frame = cameraPreviewView.bounds;

[cameraPreviewView.layer addSublayer:cameraPreviewLayer];
[cameraPreviewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
[cameraPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspect];

[session startRunning];

      

+3
ios iphone avfoundation


source to share


No one has answered this question yet

Check out similar questions:

487
How to develop or migrate iPhone 5 screen resolution apps?
440
Capturing an image using captureStillImageAsynchronouslyFromConnection without shutter sound
328
Capture iOS Simulator to View Apps
21
iPhone SDK 4 AVFoundation - How to use captureStillImageAsynchronouslyFromConnection correctly?
ten
Cropping the image captured by AVCaptureSession
five
Full video capture with video background and overlay playback
2
AVCaptureSession error -11819 when capturing video
1
How do I create an AVAsset with a UIImage captured from a camera?
0
Problem with modalViewController appearing
0
AVCaptureSession no decompression



All Articles
Loading...
X
Show
Funny
Dev
Pics