AVCaptureSessionPreset中等图像大小?

发布于 2024-10-31 08:00:33 字数 539 浏览 2 评论 0原文

当使用 AVCaptureSessionPresetMedium 时,

// Create the session
AVCaptureSession * newSession = [[AVCaptureSession alloc] init];

// Configure our capturesession
newSession.sessionPreset = AVCaptureSessionPresetMedium;

有没有办法动态地告诉宽度 x 高度将解析为什么?显然,我可以等到像

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
       fromConnection:(AVCaptureConnection *)connection

Gets 这样的委托被调用并在那里确定它,但我宁愿提前这样做,以便出于性能原因我可以预先计算一些值。

When using AVCaptureSessionPresetMedium

// Create the session
AVCaptureSession * newSession = [[AVCaptureSession alloc] init];

// Configure our capturesession
newSession.sessionPreset = AVCaptureSessionPresetMedium;

Is there any way to dynamically tell what this will resolve to for width x height? Obviously I can wait until a delegate like

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
       fromConnection:(AVCaptureConnection *)connection

Gets called and determine it there, but I would rather do it in advance so that I can precalculate some values for performance reasons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏尔 2024-11-07 08:00:33

我很高兴在这一点上被证明是错误的,但如果您不想对数字进行硬编码,下面的步骤似乎是正确的方法:

-(CGSize)cameraSizeForCameraInput:(AVCaptureDeviceInput*)input
{
        NSArray *ports = [input ports];
        AVCaptureInputPort *usePort = nil;
        for ( AVCaptureInputPort *port in ports )
        {
                if ( usePort == nil || [port.mediaType isEqualToString:AVMediaTypeVideo] )
                {
                        usePort = port;
                }
        }

        if ( usePort == nil ) return CGSizeZero;

        CMFormatDescriptionRef format = [usePort formatDescription];
        CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(format);

        CGSize cameraSize = CGSizeMake(dim.width, dim.height);

        return cameraSize;
}

必须在 startRunning 调用之后调用,否则结果为 0,0。我不知道将来会发生什么,所以这就是我循环遍历 ports 数组的原因。

I'd be very happy to be proven wrong on this, but the steps below seem to be the proper way if you don't want to hardcode the numbers:

-(CGSize)cameraSizeForCameraInput:(AVCaptureDeviceInput*)input
{
        NSArray *ports = [input ports];
        AVCaptureInputPort *usePort = nil;
        for ( AVCaptureInputPort *port in ports )
        {
                if ( usePort == nil || [port.mediaType isEqualToString:AVMediaTypeVideo] )
                {
                        usePort = port;
                }
        }

        if ( usePort == nil ) return CGSizeZero;

        CMFormatDescriptionRef format = [usePort formatDescription];
        CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(format);

        CGSize cameraSize = CGSizeMake(dim.width, dim.height);

        return cameraSize;
}

This has to be called after the startRunning call, otherwise the result is 0,0. I don't know what to expect in the future, so that's why I loop over the ports array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文