gpt4 book ai didi

ios - AVCaptureConnection isVideoMinFrameDurationSupported 是假的?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:24 26 4
gpt4 key购买 nike

所以在我的应用程序中,我正在录制视频。我想将录制视频的 fps 限制为 15 fps,因为如果速度更快,我在处理每一帧时都会遇到问题。该应用程序针对 iOS 5.0+,因此我不必担心比这更旧的 iOS 版本。

我知道要设置最大 fps,我可以使用 AVCaptureConnection 的 setVideoMinFrameDuration。我也知道要让它真正起作用,我还必须设置 VideoMaxFrameDuration。然而,在我的 iPad 上,AVCaptureConnection 的 isVideoMinFrameDurationSupported 似乎总是返回 false,因此我从未设置 videoMinFrameDuration,最终不得不回退到设置 AVCAPtureVideoDataOutput 的 minFrameDuration(这是一个已弃用的调用,并导致警告等。谁能解释为什么我不能设置 videoMinFrameDuration?

代码:

AVCaptureVideoDataOutput *videoDataOut = [[AVCaptureVideoDataOutput alloc] init];
NSDictionary *settings = [[NSDictionary alloc]
initWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange],
(id)kCVPixelBufferPixelFormatTypeKey, nil];
videoDataOut.videoSettings = settings;

captureQueue = dispatch_queue_create("videoCaptureQueue", NULL);
[videoDataOut setSampleBufferDelegate:self queue:captureQueue];
videoDataOut.alwaysDiscardsLateVideoFrames = YES;
AVCaptureConnection *conn = [videoDataOut connectionWithMediaType:AVMediaTypeVideo];

// This if block is failing for some reason even though I'm running iOS 5.0+
if ([conn isVideoMinFrameDurationSupported] && [conn isVideoMaxFrameDurationSupported]){
[conn setVideoMinFrameDuration:CMTimeMake(1, pParams->fps)];
[conn setVideoMaxFrameDuration:CMTimeMake(1, pParams->fps)];
}
else {
videoDataOut.minFrameDuration = CMTimeMake(1, pParams->fps);
}
[captureSession addOutput:videoDataOut];

dispatch_release(captureQueue);

最佳答案

我解决了我的问题。您必须在尝试设置 minFrameDuration(或者就此而言,拉出 AVCaptureConnection)之前将输出添加到捕获 session 。

因此,新代码如下所示:

AVCaptureVideoDataOutput *videoDataOut = [[AVCaptureVideoDataOutput alloc] init];
NSDictionary *settings = [[NSDictionary alloc]
initWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange],
(id)kCVPixelBufferPixelFormatTypeKey, nil];
videoDataOut.videoSettings = settings;

captureQueue = dispatch_queue_create("videoCaptureQueue", NULL);
[videoDataOut setSampleBufferDelegate:self queue:captureQueue];
videoDataOut.alwaysDiscardsLateVideoFrames = YES;
[captureSession addOutput:videoDataOut];

AVCaptureConnection *conn = [videoDataOut connectionWithMediaType:AVMediaTypeVideo];
if ([conn isVideoMinFrameDurationSupported] && [conn isVideoMaxFrameDurationSupported]){
[conn setVideoMinFrameDuration:CMTimeMake(1, pParams->fps)];
[conn setVideoMaxFrameDuration:CMTimeMake(1, pParams->fps)];
}

dispatch_release(captureQueue);

关于ios - AVCaptureConnection isVideoMinFrameDurationSupported 是假的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17089860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com