4

I'm currently building a very simple app that displays the iPad (front/rear) camera live stream

using AVCaptureVideoPreviewLayer.

I just want to duplicate the SAME live stream and display it

on a second view, Just Like Apple's Photo Booth app on the iPad (9 views of the same stream).

After several attempts, i now understand that two sessions won't help,

as one overrides the other.

My current approach is to create 2 AVCaptureVideoPreviewLayers and use the same AVCaptureSession.

But Still, not working.

This is my code:

rightLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[rightLayer setBackgroundColor:[[UIColor redColor] CGColor]];
[rightLayer setVideoGravity:AVLayerVideoGravityResizeAspect];

leftLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[leftLayer setBackgroundColor:[[UIColor blueColor] CGColor]];
[leftLayer setVideoGravity:AVLayerVideoGravityResizeAspect];

CALayer *rootLayer = [myView layer];
[rootLayer setMasksToBounds:YES];
[rightLayer setFrame:CGRectMake(512, 0, 512, 748)];
[leftLayer setFrame:CGRectMake(0, 0, 512, 748)];

[rootLayer addSublayer:rightLayer];
[rootLayer addSublayer:leftLayer];

[session startRunning];

When i run my app, only the left layer displays the live stream.

The weird thing is, i couldn't find a single tutorial/ piece of code about

Apple's Photo Booth app and how to achieve the same behaviour.

Help please...

Thanks

GTP_Tech
  • 155
  • 2
  • 14
  • Common sense tells me that only one instance of a frame capturing object should exist. And you should duplicate that frame with required filters on different frames, maybe using multi-threading system. Hence your `[[AVCaptureVideoPreviewLayer alloc] initWithSession:session]` should be instantiated only once, and some routine like `frameReady` should instantiate two threads which take care of applying filters and displaying on respective views. Let me know if this helps you. – Dunes Buggy Jul 29 '13 at 14:58
  • 1
    were you able to solve this problem? I would like to know the solution. Thanks – Tarang Oct 16 '13 at 17:05
  • 1
    possible duplicate of http://stackoverflow.com/q/16543075/870028 – Johnny Aug 07 '14 at 18:26

0 Answers0