9

I am using AVCaptureVideoPreviewLayer to pass the live video and apply openGL shaders in realtime. On using front camera, the video is mirrored, I want to un-mirror it before applying the shader.

Can anyone help there?

Added : code for switching to front camera :

-(void)showFrontCamera{
    NSLog(@"inside showFrontCamera");
    [captureSession removeInput:videoInput];
    // Grab the front-facing camera
    AVCaptureDevice *backFacingCamera = nil;
    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in devices) {
        if ([device position] == AVCaptureDevicePositionFront) {
            backFacingCamera = device;
        }
    }
    // Add the video input
    NSError *error = nil;
    videoInput = [[[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error] autorelease];

    if ([captureSession canAddInput:videoInput]) {
        [captureSession addInput:videoInput];
    }

}
Manish Deora
  • 91
  • 1
  • 3
  • Can you provide more details, like, code snippet where you are switching the cameras? And, what's happening when you switch back to the rear camera? is it still mirrored? – Fahri Azimov Jun 28 '13 at 13:35
  • Hi Fahri, have added the code to switch to front camera. The issue is, the video of front camera comes mirrored, which is fine for portrait mode, but when i rotate the camera, the video gets flipped and becomes upside down. eg. the face of a person rotates by 180*. – Manish Deora Jul 02 '13 at 11:38
  • In my earlier comment, by rotate the camera, I mean changing to landscape mode. – Manish Deora Jul 02 '13 at 12:27

1 Answers1

7

If you already have a preview layer, you just have to update the connection:

[[previewLayer connection] setAutomaticallyAdjustsVideoMirroring:NO];
[[previewLayer connection] setVideoMirrored:NO];
Ja͢ck
  • 161,074
  • 33
  • 239
  • 294
  • 2
    I tried to add this line of code when creating the session, but then the front camera is flipped in the preview layer as well. And I do not want that effect, I only want the result not to flip anymore. So I tried to add this line of code when toggling to front camera, but it has no effect. Can you help me on this matter if you successfully used it? – CarmenA Apr 08 '15 at 23:50