AVCaptureTorchModeAuto does not continuously update torch mode
avfoundation, camera, ios, iphone, objective-c
Solution
With current set of APIs, the brightness sampling is only done at the start of the recording. So AVCaptureTorchModeAuto does not work as you expect.
Now about the use case discussed in the question:
Possibility 1: Use Rear camera for brightness detection:
Once torch comes up, analysis of the captured stream will not tell the current situation of room brightness, as Torch will cause cosmetic brightness.
So in order to get the real brightness value would have to require to switch on-off on timely basis, which is not very generic and convenient in most of the cases.
Getting brightness value to decide enabling of Torch or not.
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL,
sampleBuffer, kCMAttachmentMode_ShouldPropagate);
NSDictionary *metadata = [[NSMutableDictionary alloc]
initWithDictionary:(__bridge NSDictionary*)metadataDict];
CFRelease(metadataDict);
NSDictionary *exifMetadata = [[metadata
objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy];
float brightnessValue = [[exifMetadata
objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue];
}
Possibility 2: Use Front Camera for brightness detection:
Torch is not permitted with front camera.
Problem
I am writing an app that automatically turns on the torch on the back of an iOS device depending on lighting conditions. The app renders a live camera view, and does not record the video. I have tried using `AVCaptureTorchModeAuto`, but it only seems to measure the brightness of the image at the start of the capture session, and set the torch accordingly. The setting then does not change afterwards, regardless of the brightness of the camera image. It is possible to have the system adjust the torch continuously, like stated in the documentation? The capture device continuously monitors light levels and uses the torch when necessary. Available in iOS 4.0 and later.