AVCaptureDeviceInput上的奇怪的肉体行为

时间:2013-06-27 23:02:07

标签: 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 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];

但是在录制开始时有一个奇怪的行为,闪光灯开启然后关闭不到一秒然后永久保持,有谁知道为什么以及如何解决它?

1 个答案:

答案 0 :(得分:0)

尝试制作班级的AVCaptureSession *sessionAVCaptureDeviceInput *input成员变量。他们需要在功能范围内存活