I was wondering if it's possible to add multiple AVCaptureVideoDataOutput
to AVCaptureSession
with a single camera device input?
My experiments indicate that adding a second VideoDataOutput
will cause canAddOutput
return NO
. But I couldn't find anywhere on Apple's documentation says multiple data output is disallow.
We can not use single
AVCaptureSession
for multipleAVCaptureVideoDataOutput
objects.What can you do is you can make multiple
AVCaptureVideoDataOutput
with multipleAVCaptureSession
objects.You can create two different setups of the
AVCaptureVideoDataOutput
andAVCaptureSession
then you can use them one after another in the app and you will be able to achieve the goal.In my case, I had to capture front and back image using the camera at a time.
I did create two different objects for
AVCaptureVideoDataOutput
andAVCaptureSession
as given below.Now in view did load initially I did setup back camera and set up flags for session started recording or not for both sessions as followed.
Now, whenever the user starts capturing photo we will capture the front photo using below code.
As soon as the back image will be captured we will setup session to capture front image using setupFrontAVCapture method and then we will capture front image using takeFrontPhoto method as given below.
This way you can use two different set of
AVCaptureSession
andAVCaptureStillImageOutput
objects and you can achieve your goal.Please let me know if you have any confusion.