AVFoundation Camera Preview Incorrect orientation

I am creating a custom camera with a small preview area inside the iPad, however the stream in this preview is rotated clockwise.

I reviewed both the AVCam demo and the SquareCam demo on Apple, and I don't see a solution either. All AVFoundation orientation streams in StackOverflow specifically relate to output orientation, not input orientation.

Here is the session code I'm using:

AVCaptureDevice *frontalCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; _session = [[AVCaptureSession alloc] init]; [_session beginConfiguration]; NSError *error; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:frontalCamera error:&error]; [_session addInput:input]; _output = [[AVCaptureStillImageOutput alloc] init]; [_output setOutputSettings:[[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil]]; [_session addOutput:_output]; AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session]; previewLayer.frame = self.imageViewCamera.bounds; previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.imageViewCamera.layer addSublayer:previewLayer]; _session.sessionPreset = AVCaptureSessionPreset640x480; [_session commitConfiguration]; [_session startRunning]; 

Any help would be greatly appreciated!

+4
source share
3 answers

Orientation layers. (Deprecated in iOS 6.0. Use videoOrientation (AVCaptureConnection).)

so use:

 [[AVCaptureVideoPreviewLayer connection] setVideoOrientation: AVCaptureVideoOrientationLandscapeRight]; 

or

 AVCaptureVideoPreviewLayer.connection.videoOrientation= AVCaptureVideoOrientationLandscapeRight; 
+1
source

Apple docs for iOS 6 say use videoOrientation (AVCaptureConnection) .

+2
source

This is deprecated, but you can change the orientation of your preview counterclockwise.

 previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight; 

I am not sure if this is a non-deprecated solution.

+1
source

All Articles