1

I am new in OpenCV as well as AVFoundation framework , I am trying to show the Video Preview captured from camera without writing it into a file. But when start button is pressed i need to write the video in to Document Folder . Here is the piece of code that i am trying to execute but when it runs it does not show any video Preview. Please help me.

    self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
    self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
    self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetMedium;
    self.videoCamera.defaultFPS = 15;
    self.videoCamera.grayscaleMode = NO;
    self.videoCamera.recordVideo = YES;
    [self.videoCamera start];
    [self.videoCamera.captureSession stopRunning];

1 Answer 1

2

You need to get the video preview from the AVCaptureSession and add it to a view(layer) in your application.

Here "session" is the AVCaptureSession that the camera is connected to and "self.videoPreviewView" is a UIView in my application that is used to display the video preview.

// Get the preview for the session
AVCaptureVideoPreviewLayer *videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

// Set the frame and add the previewLayer as a sublayer in the UI
CALayer *viewLayer = self.videoPreviewView.layer;
videoPreviewLayer.frame = self.videoPreviewView.bounds;
[self.videoPreviewView.layer addSublayer:videoPreviewLayer];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.