不推荐使用的AVCaptureConnection帧持续时间属性的替代方案?

时间:2013-10-03 20:48:42

标签: ios ios7 avfoundation

根据this document与视频帧最大和最小持续时间相关的属性和方法:

  • supportsVideoMaxFrameDuration
  • supportsVideoMinFrameDuration
  • videoMaxFrameDuration
  • videoMinFrameDuration

已全部弃用。还有替代品吗?

2 个答案:

答案 0 :(得分:7)

根据头文件(AVCaptureSession.h),

  

此属性在iOS上已弃用,其中最小和最大帧速率调整为   仅使用AVCaptureDevice应用   activeVideoMinFrameDuration和activeVideoMaxFrameDuration     属性。

答案 1 :(得分:7)

在iOS7中使用以下序列

我按照我指定的帧率运行它(我在使用activeVideoMinFrameDuration时遇到了一些问题,但这似乎是一个有效的解决方案):

AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if([camera isTorchModeSupported:AVCaptureTorchModeOn]) {
    [camera lockForConfiguration:nil];
    //configure frame rate
    [camera setActiveVideoMaxFrameDuration:CMTimeMake(1, samplingFrequency)];
    [camera setActiveVideoMinFrameDuration:CMTimeMake(1, samplingFrequency)];
    [camera unlockForConfiguration];
}

AVCaptureInput* cameraInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:nil];
AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
dispatch_queue_t captureQueue=dispatch_queue_create("catpureQueue", DISPATCH_QUEUE_SERIAL);

//setup delegate
[videoOutput setSampleBufferDelegate:self queue:captureQueue];

videoOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey,
                             nil];
[catpureSession setSessionPreset:AVCaptureSessionPresetMedium];

if([catpureSession canAddInput:cameraInput])
    [catpureSession addInput:cameraInput];
if([catpureSession canAddOutput:videoOutput])
    [catpureSession addOutput:videoOutput];

[catpureSession startRunning];

其中 catpureSession 是类 AVCaptureSession 的对象, samplingFrequency 是我的帧速率(设置为30)