videoMinFrameDuration已过时

3

当我把Xcode从4.6升级到5.1时,出现了“'videoMinnFrameDuration'在ios7中已被弃用”的问题。

- (void)setFrameRate:(NSInteger)frameRate;
 {
_frameRate = frameRate;

if (_frameRate > 0)
{
    for (AVCaptureConnection *connection in videoOutput.connections)
    {

        if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)])
            connection.videoMinFrameDuration = CMTimeMake(1,_frameRate);

一个被弃用的方法意味着它已经过时,因为存在安全问题,或者因为有一个新的方法可以完成同样的功能,或者其他原因。它只是为了让运行旧版本xcode的设备仍然能够运行您的代码而包含在内。出于代码安全和可移植性的考虑,您不应再使用它。请参考文档以了解应该使用哪个方法。 - Aserre
2个回答

5

首先,您正在使用过时的GPUImage版本,因为这个问题在框架代码中已经修复了将近一年的时间。请更新您本地的框架版本。

在GPUImage中,我解决这个问题的方式是,在涉及到相关代码的周围禁用弃用检查,因为我仍然需要在旧的iOS版本中使用这种方法:

    if ([_inputCamera respondsToSelector:@selector(setActiveVideoMinFrameDuration:)] &&
        [_inputCamera respondsToSelector:@selector(setActiveVideoMaxFrameDuration:)]) {

        NSError *error;
        [_inputCamera lockForConfiguration:&error];
        if (error == nil) {
#if defined(__IPHONE_7_0)
            [_inputCamera setActiveVideoMinFrameDuration:CMTimeMake(1, _frameRate)];
            [_inputCamera setActiveVideoMaxFrameDuration:CMTimeMake(1, _frameRate)];
#endif
        }
        [_inputCamera unlockForConfiguration];

    } else {

        for (AVCaptureConnection *connection in videoOutput.connections)
        {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)])
                connection.videoMinFrameDuration = CMTimeMake(1, _frameRate);

            if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)])
                connection.videoMaxFrameDuration = CMTimeMake(1, _frameRate);
#pragma clang diagnostic pop
        }
    }

如果新属性(activeVideoMinFrameDuration)可用,我们将使用它。如果不可用,则退回到现在已弃用的方法。由于我们知道它已被弃用,因此没有必要让编译器警告我们。

1
在 AVFoundation 的 AVCaptureSession.h 类中,它通过以下注释提到。
@property supportsVideoMinFrameDuration
 @abstract
    Indicates whether the connection supports setting the videoMinFrameDuration property.

 @discussion
    This property is only applicable to AVCaptureConnection instances involving
    video.  In such connections, the videoMinFrameDuration property may only be set if
    -isVideoMinFrameDurationSupported returns YES.

    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.  On Mac OS X, frame rate adjustments are supported both at the AVCaptureDevice
    and at AVCaptureConnection, enabling connections to output different frame rates.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接