在iPhone上录制视频时如何设置帧率?

时间:2010-12-19 22:14:29

标签: iphone cocoa-touch avfoundation

我想写一个使用iPhone相机录制视频的相机应用程序,但我找不到改变录制视频帧率的方法。例如,我想以每秒25帧的速度而不是默认的30帧进行录制。

是否可以以任何方式设置此帧速率,如果是,如何设置?

3 个答案:

答案 0 :(得分:1)

您可以使用AVCaptureConnection的videoMaxFrameDuration和videoMinFrameDuration属性。见http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVCaptureConnection_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009522

此外,有一个SO问题解决了这个问题(有一个很好的代码示例): I want to throttle video capture frame rate in AVCapture framework

答案 1 :(得分:0)

据我所知,您无法设置FPS进行录制。查看WWF 2010视频的AVFoundation。它似乎表明你可以,但据我所知,这只能用于捕获帧数据。

我喜欢被证明是错的,但我很确定你做不到。遗憾!

答案 2 :(得分:0)

您将需要AVCaptureDevice.h

这是以下工作代码:

- (void)attemptToConfigureFPS
{

    NSError *error;
    if (![self lockForConfiguration:&error]) {
        NSLog(@"Could not lock device %@ for configuration: %@", self, error);
        return;
    }

    AVCaptureDeviceFormat *format = self.activeFormat;
    double epsilon = 0.00000001;

    int desiredFrameRate = 30;

    for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {

        NSLog(@"Pre Minimum frame rate: %f  Max = %f", range.minFrameRate, range.maxFrameRate);


        if (range.minFrameRate <= (desiredFrameRate + epsilon) &&
            range.maxFrameRate >= (desiredFrameRate - epsilon)) {

            NSLog(@"Setting Frame Rate.");

            self.activeVideoMaxFrameDuration = (CMTime){
                .value = 1,
                .timescale = desiredFrameRate,
                .flags = kCMTimeFlags_Valid,
                .epoch = 0,
            };
            self.activeVideoMinFrameDuration = (CMTime){
                .value = 1,
                .timescale = desiredFrameRate,
                .flags = kCMTimeFlags_Valid,
                .epoch = 0,
            };

            // self.activeVideoMinFrameDuration = self.activeVideoMaxFrameDuration;

            // NSLog(@"Post Minimum frame rate: %f  Max = %f", range.minFrameRate, range.maxFrameRate);

            break;
        }
    }

    [self unlockForConfiguration];


    // Audit the changes
    for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {

        NSLog(@"Post Minimum frame rate: %f  Max = %f", range.minFrameRate, range.maxFrameRate);

    }



}