Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone 7 Plus - AVFoundation dual camera

I'm actively researching this at the moment, but now that the iPhone 7 Plus has a dual camera system, will AVFoundation allow you to handle video frames from each specific camera simultaneously?

I am thinking/hoping that I'll be able to handle output from two AVCaptureDevice instances at the same time given a certain position.

like image 525
dokun1 Avatar asked Sep 08 '16 07:09

dokun1


People also ask

Does the iPhone 7 Plus have 2 cameras?

First of all, it is important to point out that the iPhone 7 Plus actually has two cameras with two lenses. While both cameras have the same 12 MP resolution sensors, there is actually a difference in sensor size and maximum aperture between the two.

How do you use the second camera on iPhone 7 Plus?

If you've tinkered in the camera app at all, you may have activated the second camera by accident without even knowing it. To select the camera with the 56mm f2. 8 "telephoto" lens, open Camera and tap the circle icon above the on-screen shutter button that says 1x.

Why does the iPhone 7 Plus have two camera lenses?

The telephoto camera is used to take the main photo while the wide-angle camera is used to build a depth map of the scene. This means your iPhone can selectively blur different areas and make it look like it was taken using a DSLR, an effect that until now you needed to use an app like Photoshop to achieve.

Can iPhone use both cameras at the same time?

In AVCapture on iOS 13 it is now possible to simultaneously capture photos and video from multiple cameras on iPhone XS, iPhone XS Max, iPhone XR, and the latest iPad Pro.


1 Answers

You can only add one camera at the time to an AVCaptureSession. For example you can switch between the front and the back camera, but not use both at the same time. It is the same with the two back cameras on the 7 Plus, you have to choose either. However, there is a small difference since you can also call a "duo camera" that merges the images from both cameras when you zoom. But that is only available for still photo and you will only get one image/capture buffer. For video you have to pick either camera.

To pick the camera you can use the new AVCaptureDeviceDiscoverySession. To use the duo camera:

@property (nonatomic) AVCaptureDevice *backCamera;
@property (nonatomic) AVCaptureDeviceInput *backCameraInput;


if([AVCaptureDeviceDiscoverySession class]){
    NSArray *allTypes = @[AVCaptureDeviceTypeBuiltInDuoCamera, AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera ];
    AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:allTypes mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack];

    for(AVCaptureDevice *device in discoverySession.devices) {
        if(device.deviceType== AVCaptureDeviceTypeBuiltInDuoCamera){
            self.backCamera = device;
            self.backCameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.backCamera error:&error];
        }
    }
}

if(!self.backCamera){
    self.backCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    self.backCameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.backCamera error:&error];
}

To use wide and tele camera individually

@property (nonatomic) AVCaptureDevice *backCamera;
@property (nonatomic) AVCaptureDeviceInput *backCameraInput;
@property (nonatomic) AVCaptureDevice *teleCamera;
@property (nonatomic) AVCaptureDeviceInput *teleCameraInput;


if([AVCaptureDeviceDiscoverySession class]){
    NSArray *allTypes = @[AVCaptureDeviceTypeBuiltInDuoCamera, AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera ];
    AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:allTypes mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack];

    for(AVCaptureDevice *device in discoverySession.devices) {
        if(device.deviceType==AVCaptureDeviceTypeBuiltInWideAngleCamera){
            self.backCamera = device;
            self.backCameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.backCamera error:&error];
        }

        if(device.deviceType==AVCaptureDeviceTypeBuiltInTelephotoCamera){
            self.teleCamera = device;
            self.teleCameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.teleCamera error:&error];
        }
    }
}

if(!self.backCamera){
    self.backCamera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    self.backCameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.backCamera error:&error];
}

If you don't do this, or keep your old code you will only use the wide camera even if you zoom.

EDIT: In iOS 11 there is new AVCapturePhotoSettings called dualCameraDualPhotoDeliveryEnabled. It allows you to take two still images simultaneously, however, no streaming/video.

like image 187
Sten Avatar answered Nov 16 '22 03:11

Sten