How to set rotation for AVCaptureMovieFileOutput

I have a full screen avcapturesession with AVPreviewLayer.

When I switch the camera, the preview shows the video correctly, but after saving the video is upside down.

I played with mirroring and landscape left / right properties to include a video output file, but to no avail.

This is the method that switches the camera:

- (void)swapFrontAndBackCameras { // Assume the session is already running NSArray * inputs = self . session.inputs; for (AVCaptureDeviceInput * INPUT in inputs) { AVCaptureDevice * Device = INPUT.device ; if ( [ Device hasMediaType : AVMediaTypeVideo ] ) { AVCaptureDevicePosition position = Device.position; AVCaptureDevice * newCamera = nil; AVCaptureDeviceInput * newInput = nil; if(position == AVCaptureDevicePositionFront) { newCamera = [ self cameraWithPosition : AVCaptureDevicePositionBack]; } else { newCamera = [ self cameraWithPosition : AVCaptureDevicePositionFront]; } newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil]; [self.session beginConfiguration ] ; [self.session removeInput:INPUT ] ; [self.session addInput:newInput ] ; AVCaptureConnection *videoConnection = nil; for ( AVCaptureConnection *connection in [self.movieFileOutput connections] ) { NSLog(@"%@", connection); for ( AVCaptureInputPort *port in [connection inputPorts] ) { NSLog(@"%@", port); if ( [[port mediaType] isEqual:AVMediaTypeVideo] ) { videoConnection = connection; } } } [videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; // This does it for the previewlayer only, not the output file :( [self.session commitConfiguration ] ; break; } } } 
+4
source share

All Articles