1

Using XCode-6.4, iOS-8.4.1:

With AVCaptureSession, I would like to zoom further out (as much as the iPhone camera possibly can manage!)

I already use the "setVideoZoomFactor" method set equal to 1 (= its smallest value allowed). This works quite good (see code-example at the very bottom...). But then I did the following observation (recognising that the camera in photo-mode possibly manages to zoom even further out than being in video-mode):

The iPhone-camera in photo-mode shows a completely different zoom than the camera being in video-mode (at least for my iPhone 5S). You can test yourself using the native "Camera App" on your iPhone. Switch between PHOTO and VIDEO and you will see that the Photo-mode can possibly zoom further out than video-zoomfactor=1). How is that possible ???

And moreover, is there any way in achieving the same minimal zoomfactor the photo-mode achieves also in video-mode using AVCam under iOS ????

Here is an illustration of what the zoom-difference is between photo-mode and video-mode of my 5S iPhone (see picture):

enter image description here

Here is the code of the AVCamViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Create the AVCaptureSession
    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    [self setSession:session];

    // Setup the preview view
    [[self previewView] setSession:session];

    // Check for device authorization
    [self checkDeviceAuthorizationStatus];

    dispatch_queue_t sessionQueue = dispatch_queue_create("session queue", DISPATCH_QUEUE_SERIAL);
    [self setSessionQueue:sessionQueue];

    // http://stackoverflow.com/questions/25110055/ios-captureoutputdidoutputsamplebufferfromconnection-is-not-called

    dispatch_async(sessionQueue, ^{
        self.session = [AVCaptureSession new];
        self.session.sessionPreset = AVCaptureSessionPresetMedium;
        NSArray *devices = [AVCaptureDevice devices];
        AVCaptureDevice *backCamera;
        for (AVCaptureDevice *device in devices) {
            if ([device hasMediaType:AVMediaTypeVideo]) {
                if ([device position] == AVCaptureDevicePositionBack) {
                    backCamera = device;
                }
            }
        }

        NSError *error = nil;
        AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:backCamera error:&error];
        if (error) {
            NSLog(@"%@",error);
        }
        if ([self.session canAddInput:input]) {
            [self.session addInput:input];
        }
        AVCaptureVideoDataOutput *output = [AVCaptureVideoDataOutput new];
        [output setSampleBufferDelegate:self queue:sessionQueue];
        output.videoSettings = @{(id)kCVPixelBufferPixelFormatTypeKey:@(kCVPixelFormatType_32BGRA)};
        if ([self.session canAddOutput:output]) {
            [self.session addOutput:output];
        }

        // Apply initial VideoZoomFactor to the device
        NSNumber *DefaultZoomFactor = [NSNumber numberWithFloat:1.0];
        if ([backCamera lockForConfiguration:&error])
        {
// HERE IS THE ZOOMING DONE !!!!!!
            [backCamera setVideoZoomFactor:[DefaultZoomFactor floatValue]];
            [backCamera unlockForConfiguration];
        }
        else
        {
            NSLog(@"%@", error);
        }

        [self.session startRunning];
    });
}
iKK
  • 6,394
  • 10
  • 58
  • 131

1 Answers1

1

If your problem is that your app is zooming the photo by comparison to native iOS camera app, then this setup will probably help you. I had "this" issue and the following solution fix it.

The solution: Configure your session

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Create the AVCaptureSession
    AVCaptureSession *session = [[AVCaptureSession alloc] init];   
    [self setSession:session];
--> self.session.sessionPreset = AVCaptureSessionPresetPhoto;  <---
...
}

You must be aware that setup will only work for photos and not for videos. If you try with videos, your app shall crash.

You can configure your session based upon your needs (photo or video) For video you can use this value: AVCaptureSessionPresetHigh

BR.

CRUS
  • 11
  • 2