Alternatives to deprecated AVCaptureConnection frame-duration properties?

回眸只為那壹抹淺笑 提交于 2019-12-22 06:55:53

问题


According to this document the properties and methods relating to video-frame maximum and minimum duration:

  • supportsVideoMaxFrameDuration
  • supportsVideoMinFrameDuration
  • videoMaxFrameDuration
  • videoMinFrameDuration

have all been deprecated. Are there alternatives?


回答1:


According to the header file (AVCaptureSession.h),

This property is deprecated on iOS, where min and max frame rate adjustments are applied exclusively at the AVCaptureDevice using the activeVideoMinFrameDuration and activeVideoMaxFrameDuration properties.




回答2:


in iOS7 using the following sequence I get it running at the frame rate I specify (I also had a few problems using activeVideoMinFrameDuration, but this seems to be a working solution):

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];

where catpureSession is an object of class AVCaptureSession and samplingFrequency is my frame rate (set to 30)



来源:https://stackoverflow.com/questions/19168970/alternatives-to-deprecated-avcaptureconnection-frame-duration-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!