4

I have a full screen avcapturesession with an AVPreviewLayer.

When I toggle the camera the previewlayer shows the video correctly, but once saved the video is upside down.

I have played around with mirroring and landscape left/right properties for the connection of the video output file, but to no avail.

This is the method that toggles 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;
        }
    } 
}
Hyra
  • 798
  • 1
  • 5
  • 21
  • you check this link..it may help..http://stackoverflow.com/questions/15524824/how-do-you-prevent-fullscreen-video-rotation-in-ios-6 – Kundan Apr 10 '13 at 09:48
  • It's not that the video gets rotated upon playing. The actual saved video (data) is upside down. – Hyra Apr 10 '13 at 09:53
  • The same problem i got with images..which i solved by changing image format..I am not sure whether it works for video or not..but give a try?? – Kundan Apr 10 '13 at 10:01
  • Any example call of how you changed the image format? – Hyra Apr 10 '13 at 10:02
  • you check this link..http://stackoverflow.com/questions/10307521/ios-png-image-rotated-90-degrees – Kundan Apr 10 '13 at 10:06
  • Looks like there's not really a way to do this. The AVCaptureMovieFileOutput doesn't like to be told to be in a different UIOrientation .. – Hyra Apr 10 '13 at 16:27

0 Answers0