如何为视频录制指定曝光,对焦和白平衡?

时间:2013-01-20 14:47:33

标签: ios camera avcapturedevice

我有一个程序来拍摄带有默认参数的视频,当我移动相机时,将自动调整曝光,聚焦和白平衡。我想在程序中添加2个按钮:LOCK和PRESET。按下LOCK按钮时,曝光,对焦和白平衡将被修复,其值将作为用户设置存储。 PRESET按钮用于将用户设置设置为相机,以确保我们可以拍摄具有相同曝光,对焦和白平衡值的所有视频。

锁定部分很简单,我只需要改变模式,所以我想知道是否有任何方法可以获得并设置曝光,聚焦和白平衡的值。

以曝光为例,默认情况下,曝光模式设置为AVCaptureExposureModeContinuousAutoExposure,这意味着,当我拿着iPhone拍摄视频时,曝光将自动调整,以确保我们可以在明亮或黑暗中清晰地看到场景环境。

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

按下LOCK按钮时,我将exposureMode更改为AVCaptureExposureModeLocked,因此不再更改当前曝光值。

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

但是,如何在按下按钮时获取曝光值?更重要的是,当按下PRESET时,如何将曝光值设置回AVCaptureDevice。

我在论坛中搜索过,只发现了Michael Grinich的帖子:Accessing iOS 6 new APIs for camera exposure and shutter speed。我按照他的发现并尝试使用私有API获取并设置exposureGain和exposureDuration,但我发现在AVCaptureExposureModeContinuousAutoExposure模式下,当我将相机从黑暗环境移动到明亮时(曝光增益= 1.0和exposureDuration = {1,30,1,0})。设置它们并没有改变曝光度。

[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];

有人可以帮我解决这个问题吗?非常感谢提前!

2 个答案:

答案 0 :(得分:1)

我添加了一个可能对Accessing iOS 6 new APIs for camera exposure and shutter speed提供帮助的答案。我可以在这里添加更多细节......

手动设置焦点的方式与我设置曝光的完全相同。那就是:

#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];
}

白平衡似乎没有曝光和对焦方式的特殊模式。不要将WhiteBalanceMode设置为锁定,否则您似乎只能设置色温:

// this is also a value [0..1]
captureDevice.whiteBalanceTemperature = ...;

答案 1 :(得分:0)

要设置手动固定曝光值和ISO,您现在可以执行以下操作:

[Device lockForConfiguration:nil];
[Device setExposureModeCustomWithDuration:CMTimeMake(5, 100) ISO:AVCaptureISOCurrent completionHandler:nil]; //currently set to 50ms for example
[Device unlockForConfiguration];

您可以在此处参考其文档:https://developer.apple.com/reference/avfoundation/avcapturedevice/1624646-setexposuremodecustomwithduratio?language=objc