Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the exposure, focus and white balance to the video recording?

I have a program to take a video with default parameters, and the Exposure, Focus and White Balance will be adjusted automatically when I move the camera. I want to add 2 buttons in the program: LOCK and PRESET. When the LOCK button is pressed, the exposure, focus and white balance will be fixed, and their values will be stored as user settings. The PRESET button is to set the user settings to the camera, to make sure we can take all the videos with the same exposure, focus and white balance values.

The lock part is easy, I just have to change the mode, so I would like to know if there is any way to get and set values for exposure, focus and white balance.

Take exposure for example,by default, the exposureMode is set to AVCaptureExposureModeContinuousAutoExposure, that means, when I hold the iPhone to take a video, the exposure will be adjusted automatically to ensure that we can see the scene clearly in bright or dark environment.

AVCaptureDevice* pCaptureDevice = [self videoDeviceWithPosition:AVCaptureDevicePositionBack];
[pCaptureDevice lockForConfiguration:nil];
[pCaptureDevice setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[pCaptureDevice unlockForConfiguration];

When the LOCK button is pressed, I change the exposureMode to AVCaptureExposureModeLocked, so the current exposure value will not be changed anymore.

[pCaptureDevice lockForConfiguration:nil];
[pCaptureDevice setExposureMode:AVCaptureExposureModeLocked];
[pCaptureDevice unlockForConfiguration];

However, how can I get the exposure value at that moment when the button is pressed? And what's more important, how can I set the exposure value back to the AVCaptureDevice when PRESET is pressed.

I searched in the forum and only found Michael Grinich's post: Accessing iOS 6 new APIs for camera exposure and shutter speed. I followed his found and tried to use the private APIs to get and set the exposureGain and exposureDuration, but I found that in AVCaptureExposureModeContinuousAutoExposure mode, these 2 values never changed when I move the camera from the dark environment to the bright(exposureGain = 1.0 and exposureDuration = {1, 30, 1, 0}). And setting them didn't change the exposure at all.

[pCaptureDevice lockForConfiguration:nil];
[pCaptureDevice setExposureMode:AVCaptureExposureModeLocked];
[pCaptureDevice setManualExposureSupportEnabled:YES];
NSLog(@"exposure gain: %f", [pCaptureDevice exposureGain]);
[pCaptureDevice setExposureGain:3.0];
NSLog(@"exposure gain: %f", [pCaptureDevice exposureGain]);
[pCaptureDevice unlockForConfiguration];

Could anybody help me to solve this problem? Thanks very much in advance!

like image 338
Yang Avatar asked Jan 20 '13 14:01

Yang


1 Answers

I added an answer that might help you on Accessing iOS 6 new APIs for camera exposure and shutter speed. I can add a little more detail here...

Setting the focus manually follows exactly the same structure that I outlined for setting the exposure. That is:

#define AVCaptureFocusModeManual     3
NSError*    error = nil;
if ([captureDevice lockForConfiguration:&error]) {
    captureDevice.manualFocusSupportEnabled = YES;
    if ([captureDevice isFocusModeSupported:AVCaptureFocusModeManual]) {
        captureDevice.focusMode = AVCaptureFocusModeManual;
        // this is a value [0..1]
        captureDevice.focusPosition = ...;
    }
    [captureDevice unlockForConfiguration];
}

The white balance doesn't seem to have a special mode the way exposure and focus do. Don't set the WhiteBalanceMode to locked, but otherwise it seems that you can just set the color temperature:

// this is also a value [0..1]
captureDevice.whiteBalanceTemperature = ...;
like image 100
Bretton Wade Avatar answered Sep 30 '22 14:09

Bretton Wade