Reputation: 14351
I'm making a custom camera with a small preview area inside of the iPad, however, the stream in that previewing is rotated clockwise.
I have looked at both AVCam demo and the SquareCam demo on Apple and I don't see a solution in either. All of the AVFoundation orientation threads on StackOverflow are talking specifically about 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 much appreciated!
Upvotes: 4
Views: 3096
Reputation: 11257
This has been deprecated but you can change the orientation of your previewLayer counter-clockwise.
previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
I'm not sure what the non-deprecated solution is though.
Upvotes: 1
Reputation: 27072
The layer’s orientation. (Deprecated in iOS 6.0. Use videoOrientation (AVCaptureConnection) instead.)
so use:
[[AVCaptureVideoPreviewLayer connection] setVideoOrientation: AVCaptureVideoOrientationLandscapeRight];
or
AVCaptureVideoPreviewLayer.connection.videoOrientation= AVCaptureVideoOrientationLandscapeRight;
Upvotes: 1
Reputation: 162
The Apple docs for iOS 6 say to use videoOrientation (AVCaptureConnection)
instead.
Upvotes: 2