简体   繁体   English

iPhone视频中的可变帧率

[英]Variable Frame Rate in iPhone video

How can we change frame rates of an existing video as well as while capturing video from iPhone? 在从iPhone捕获视频时,我们如何改变现有视频的帧频?

Can we implement it using either AVFoundation framework or by any third party library? 我们可以使用AVFoundation框架还是任何第三方库来实现它?

Code for choosing custom frame rate is as below - Added checks to Apple RosyWriter to verify if current format supports FPS chosen 选择自定义帧频的代码如下-向Apple RosyWriter添加了检查以验证当前格式是否支持所选的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];
        }
    }
}

In case current format ( activeFormat ) didn't support your chosen FPS, use below code to change activeFormat and then chose FPS. 如果当前格式( activeFormat )不支持您选择的FPS,请使用下面的代码更改activeFormat ,然后选择FPS。 Will need to get format dimension to match your needs though. 不过,将需要获取格式尺寸以匹配您的需求。

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

Note: Usage of AVCaptureConnection videoMinFrameDuration to set FPS is deprecated. 注意:不建议使用AVCaptureConnection videoMinFrameDuration设置FPS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM