iPhone视频中的可变帧速率

iPhone视频中的可变帧速率,iphone,camera,avfoundation,Iphone,Camera,Avfoundation,我们如何改变现有视频的帧速率以及从iPhone捕获视频的帧速率 我们可以使用AVFoundation框架或任何第三方库来实现它吗 选择自定义帧速率的代码如下-添加检查以验证当前格式是否支持选择的FPS - (void)configureCamera:(AVCaptureDevice *)videoDevice withFrameRate:(int)desiredFrameRate { BOOL isFPSSupported = NO; AVCaptureDeviceFormat

我们如何改变现有视频的帧速率以及从iPhone捕获视频的帧速率


我们可以使用AVFoundation框架或任何第三方库来实现它吗

选择自定义帧速率的代码如下-添加检查以验证当前格式是否支持选择的FPS

- (void)configureCamera:(AVCaptureDevice *)videoDevice withFrameRate:(int)desiredFrameRate
{
    BOOL isFPSSupported = NO;
    AVCaptureDeviceFormat *currentFormat = [videoDevice activeFormat];
    for ( AVFrameRateRange *range in currentFormat.videoSupportedFrameRateRanges ) {
        if ( range.maxFrameRate >= desiredFrameRate && range.minFrameRate <= desiredFrameRate )        {
            isFPSSupported = YES;
            break;
        }
    }

    if( isFPSSupported ) {
        if ( [videoDevice lockForConfiguration:NULL] ) {
            videoDevice.activeVideoMaxFrameDuration = CMTimeMake( 1, desiredFrameRate );
            videoDevice.activeVideoMinFrameDuration = CMTimeMake( 1, desiredFrameRate );
            [videoDevice unlockForConfiguration];
        }
    }
}
注意:不推荐使用AVCaptureConnection videoMinFrameDuration设置FPS

- (void)configureCamera:(AVCaptureDevice *)device withFrameRate:(int)desiredFrameRate
{
    AVCaptureDeviceFormat *desiredFormat = nil;
    for ( AVCaptureDeviceFormat *format in [device formats] ) {
        for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) {
            if ( range.maxFrameRate >= desiredFrameRate && range.minFrameRate <= desiredFrameRate ) {
                desiredFormat = format;
                goto desiredFormatFound;
            }
        }
    }

    desiredFormatFound:
    if ( desiredFormat ) {
        if ( [device lockForConfiguration:NULL] == YES ) {
            device.activeFormat = desiredFormat ;
            device.activeVideoMinFrameDuration = CMTimeMake ( 1, desiredFrameRate );
            device.activeVideoMaxFrameDuration = CMTimeMake ( 1, desiredFrameRate );
            [device unlockForConfiguration];
        }
    }
}