Iphone AVCaptureDeviceInput上的绞线闪存行为

Iphone AVCaptureDeviceInput上的绞线闪存行为,iphone,ios,objective-c,avfoundation,Iphone,Ios,Objective C,Avfoundation,我用这个代码让flash在我录制的视频上工作 NSError *error = nil; // Create the session AVCaptureSession *session = [[AVCaptureSession alloc] init]; // Configure the session to produce lower resolution video frames, if your // processing algorithm can cope. We'll spec

我用这个代码让flash在我录制的视频上工作

NSError *error = nil;
// Create the session

AVCaptureSession *session = [[AVCaptureSession alloc] init];

// Configure the session to produce lower resolution video frames, if your

// processing algorithm can cope. We'll specify medium quality for the

// chosen device.

session.sessionPreset = AVCaptureSessionPresetMedium;


// Find a suitable AVCaptureDevice

AVCaptureDevice *device = [AVCaptureDevice

                           defaultDeviceWithMediaType:AVMediaTypeVideo];

// Create a device input with the device and add it to the session.

AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device

                                                                    error:&error];

[session addInput:input];


// Create a VideoDataOutput and add it to the session

AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init] ;

[session addOutput:output];


// Configure your output.

dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);

[output setSampleBufferDelegate:self queue:queue];

// Specify the pixel format

output.videoSettings =

[NSDictionary dictionaryWithObject:

 [NSNumber numberWithInt:kCVPixelFormatType_32BGRA]

                            forKey:(id)kCVPixelBufferPixelFormatTypeKey];

[output setAlwaysDiscardsLateVideoFrames:YES];


// If you wish to cap the frame rate to a known value, such as 15 fps, set

//turn flash on
[session beginConfiguration];
BOOL lockAcquired = [device lockForConfiguration:&error];

if (!lockAcquired) {
    // log err and handle...
} else {
    if ([device hasTorch] && [device hasFlash]){
        [device setTorchMode:AVCaptureTorchModeOn];
        [device setFlashMode:AVCaptureFlashModeOn];
}
[device unlockForConfiguration];
[session commitConfiguration];

// Start the session running to start the flow of data
[session startRunning];

但是录制开始时有一种奇怪的行为,闪光灯打开然后关闭不到一秒钟,然后一直保持打开状态,有人知道我为什么以及如何解决它吗?尝试制作
AVCaptureSession*会话
AVCaptureDeviceInput*输入类的成员变量。他们需要生存的功能范围

没有改变任何东西,仍然有相同的启动行为