0

我使用此代码让 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];

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

4

1 回答 1

0

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

于 2013-06-27T23:17:53.263 回答