Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureVideoPreviewLayer front camera flip( unmirror ) the pixelbuffer before passing to opengl shader

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];
    }

}
like image 930
Manish Deora Avatar asked Jun 28 '13 11:06

Manish Deora


1 Answers

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

[[previewLayer connection] setAutomaticallyAdjustsVideoMirroring:NO];
[[previewLayer connection] setVideoMirrored:NO];
like image 85
Ja͢ck Avatar answered Nov 16 '22 02:11

Ja͢ck