【问题标题】:Recording Video at 25 Frames per second in iOS在 iOS 中以每秒 25 帧的速度录制视频
【发布时间】:2017-12-05 10:06:14
【问题描述】:

我正在制作一个定制相机,以全高清或仅高清质量拍摄。问题是,在我使用以下代码将相机设置为 25 帧后:

- (void) setFrameRate:(AVCaptureDevice*) camera {
    NSError *error;
    if (![camera lockForConfiguration:&error]) {
        NSLog(@"Could not lock device %@ for configuration: %@", camera, error);
        return;
    }
    AVCaptureDeviceFormat *format = camera.activeFormat;
    double epsilon = 0.00000001;
    int desiredFrameRate = 25;
    for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
        if (range.minFrameRate <= (desiredFrameRate + epsilon) &&
            range.maxFrameRate >= (desiredFrameRate - epsilon)) {
            [camera setActiveVideoMaxFrameDuration:CMTimeMake(10, desiredFrameRate*10)];
            [camera setActiveVideoMinFrameDuration:CMTimeMake(10, desiredFrameRate*10)];
            break;
        }
    }
    [camera unlockForConfiguration];
}

它会更改视频 fps,但不会像我在方法中设置的那样精确到每秒 25 帧。它在每秒 23.93 和 25.50 帧之间波动。 有谁知道为什么?

【问题讨论】:

    标签: ios camera avfoundation recording avassetwriter


    【解决方案1】:

    经过几次尝试和调试,我发现帧率不完全是 25 帧的问题与录制方法有关,与设备设置无关。

    我使用 AVAssetWriter 对象来录制视频,如以下链接 (https://reformatcode.com/code/ios/ios-8-film-from-both-back-and-front-camera) 中所示的示例。

    但绝不可能获得准确的 25 fps。

    为 AVCaptureMovieFileOutput 更改录制视频的对象,从那里设置和录制非常容易。结果更精确,介于 25 和 25.01 之间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-02
      • 1970-01-01
      相关资源
      最近更新 更多