【问题标题】:Show full camera width from Mac camera when running app via Mac Catalyst通过 Mac Catalyst 运行应用程序时显示 Mac 相机的完整相机宽度
【发布时间】:2021-11-22 21:53:49
【问题描述】:

我知道我的 Macbook 的网络摄像头具有广阔的视野。当我打开 Quicktime 应用程序并选择我的 MacBooks 相机作为输入时,我看到了一个很好的宽视频源。

现在,我有一个使用 Mac Catalyst 运行的 iOS 应用程序。这是我正在使用的构建组合。

当我运行这个应用程序时,我从网络摄像头获得了一个明显裁剪的视频源版本。

这是我设置AVCaptureSession的类

import Foundation
import AVFoundation


class BasicCamera: ObservableObject {
    
    @Published var authorizationState: AVAuthorizationStatus = .notDetermined
    
    let session = AVCaptureSession()
    
    init() {
        guard let device = AVCaptureDevice.default(for: .video) else {
            fatalError("Could not make capture device.")
        }
        
        guard let input = try? AVCaptureDeviceInput(device: device) else {
            fatalError("Could not make input")
        }
        
        session.beginConfiguration()
        
        session.addInput(input)
        
        session.commitConfiguration()
        
        session.startRunning()
    }
    
    public func requestCameraPermission() async -> AVAuthorizationStatus {
        return await withCheckedContinuation({ continuation in
            AVCaptureDevice.requestAccess(for: .video) { [unowned self] didComplete in
                self.authorizationState = AVCaptureDevice.authorizationStatus(for: .video)
                continuation.resume(with: .success(self.authorizationState))
            }
        })
    }
    
}

然后像这样将它添加到 ViewController 中:

let preview = AVCaptureVideoPreviewLayer(session: session)
preview.removeFromSuperlayer()  
preview.frame = self.view.bounds      
self.view.layer.insertSublayer(preview, at: 0)

请注意,我使用的 UIViewController 是通过 UIViewControllerRepresentable 协议一致性引入 SwiftUI。

我尝试了许多预设和发现会话参数,包括.buildInWidtAngleCamera,但似乎无法让它显示完整的相机分辨率?除非我将其构建为真正的原生 Mac 应用程序,否则我会不会走运?

【问题讨论】:

  • 您是否尝试过使用Optimize interface for Mac?这是她的目标>常规>部署信息>在Mac复选标记按钮旁边。只是猜测,因为它可能会将相机识别为 iapd 的肖像
  • 不错!你说的很对。

标签: swift video avfoundation apple-m1


【解决方案1】:

切换到Optimize interface for MacTarget>General>Deployment Info>Next To the Mac checkmark button下。

很可能将相机识别为 iPad 的肖像

【讨论】:

    猜你喜欢
    • 2020-02-05
    • 2021-02-21
    • 2010-09-08
    • 2020-09-16
    • 1970-01-01
    • 2021-02-16
    • 2020-06-12
    • 1970-01-01
    • 2020-06-22
    相关资源
    最近更新 更多