标签: avcapturedevice

iPhone 4 AVFoundation:同时从前后摄像头捕捉

我想知道是否可以使用AVFoundation框架同时从两个摄像头捕获.具体来说,我的问题是前后AVCaptureDevices是否可以同时处于活动状态.

目前我知道AVCaptureSession实例只能支持一个输入(和输出).我创建了两个AVCaptureSessions,将前置摄像头设备连接到一个,然后将其连接到另一个,然后我将会话的输出指向不同的SampleBufferDelegate函数.我看到的是,一个委托函数在几帧中处于活动状态,然后另一个委托函数接管.似乎AVFoundation在某种程度上关闭了相机设备,如果正在使用另一个相机设备.任何人都可以确认这一点或分享他们有关此主题的经验

提前致谢

iphone camera avfoundation ios avcapturedevice

7
推荐指数
1
解决办法
4628
查看次数

为什么AVCaptureVideoOrientation横向模式会导致静止图像颠倒?

我正在使用AVFoundation类在我的应用程序中实现自定义相机.我只捕捉静止图像,而不是视频.我有一切工作,但我被一些东西困扰.我会在捕获静止图像时考虑设备方向,并适当地设置视频连接的videoOrientation.代码段:

    // set the videoOrientation based on the device orientation to
    // ensure the pic is right side up for all orientations
    AVCaptureVideoOrientation videoOrientation;
    switch ([UIDevice currentDevice].orientation) {
        case UIDeviceOrientationLandscapeLeft:
            // Not clear why but the landscape orientations are reversed
            // if I use AVCaptureVideoOrientationLandscapeLeft here the pic ends up upside down
            videoOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        case UIDeviceOrientationLandscapeRight:
            // Not clear why but the landscape orientations are reversed
            // if I use AVCaptureVideoOrientationLandscapeRight here the pic ends up upside down …
Run Code Online (Sandbox Code Playgroud)

iphone image-capture ios avcapturesession avcapturedevice

7
推荐指数
2
解决办法
1万
查看次数

在Swift 2.1中,如何获得抛出的NSError?

我正在初始化AVCaptureDeviceInput.在Swift 2中,不是获取NSError变量,而是使用do-try-catch三明治捕获错误.但是我没有看到如何在catch部分中获取NSError.Apple开发人员论坛上的建议并未说明您如何访问NSError.

有人可以开导我吗?

error-handling exception-handling avcapturedevice swift2

7
推荐指数
1
解决办法
3313
查看次数

AVCaptureSession错误在安装之间持续存在

我有一个应用程序直接打开基于此WWDC示例的相机:https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html

一些用户遇到了相机无法开启但不允许他们捕捉内容的错误.

我昨晚刚遇到同样的问题,这就是我观察到的:

  1. 我正在调试一个单独的问题,相机工作100%正常,然后突然,它停止工作.

  2. 每当我打开应用程序或导航回相机时,它都会显示当前指向的任何黑暗视图,但图像被冻结.它就像它工作了1秒钟,然后捕获预览会冻结.

  3. 我试着强行关闭并重新打开,同样的问题.

  4. 我尝试卸载并重新安装,同样的问题.

  5. 然后我重新启动手机,问题就解决了.

如何在单独的安装之间存在此错误?

有谁知道可能导致相机失败的原因?

如果只是在使用它几个月后发生一次,我该如何进行调试呢?我不知道触发它的原因是什么?

camera avfoundation ios avcapturesession avcapturedevice

7
推荐指数
1
解决办法
174
查看次数

为什么我的 iOS 应用程序不请求用户访问相机的权限?

我开发 iOS 应用程序,它使用相机。AVCaptureDeviceInput 用于与相机连接。我检查了授权状态为

- (void)checkDeviceAuthorizationStatus
{
    NSString *mediaType = AVMediaTypeVideo;

    [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
        if (granted)
        {
            //Granted access to mediaType
            [self setDeviceAuthorized:YES];
        }
        else
        {
            //Not granted access to mediaType
            dispatch_async(dispatch_get_main_queue(), ^{
                [[[UIAlertView alloc] initWithTitle:@"AVCam!"
                                            message:@"AVCam doesn't have permission to use Camera, please change privacy settings"
                                           delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil] show];
                [self setDeviceAuthorized:NO];
            });
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)

当我启动应用程序时,为什么它不询问用户访问相机的权限?因此该应用程序不会出现在设置/隐私/相机中以手动允许访问相机。然后显示此错误"AVCam doesn't have permission to use Camera, please change privacy settings"并且应用程序无法使用相机。

编辑:这意味着未经用户许可,应用程序不得访问相机。不仅是相机,相机胶卷也存在同样的问题。

所有这些事情都是在我在“设置/重置/恢复所有设置”中重置设置后发生的。在此之前,该应用程序运行良好。

ios avcapturesession avcapturedevice avcam

6
推荐指数
1
解决办法
1万
查看次数

AVCaptureDevice 在模拟器上始终为空

我正在尝试捕获实时麦克风音频数据。

我从苹果示例中获取了以下内容AVCaptureSession

AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];

AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

NSError *error = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];

if (audioInput) {
    [captureSession addInput:audioInput];
}
else {
    // Handle the failure.
    NSLog(@"ERROR");
}
Run Code Online (Sandbox Code Playgroud)

audioCaptureDevice并且audioInput都是空的。

record ios avcapturesession avcapturedevice

6
推荐指数
1
解决办法
3669
查看次数

如何在 OSX 中使用 AVFoundation 手动控制曝光时间?

我正在使用 AVFoundation 从连接的相机捕获图像。我需要能够手动控制曝光,而不是自动控制。

我找到了 AVCaptureDevice.exposureMode ( https://developer.apple.com/documentation/avfoundation/avcapturedevice/1388858-exposuremode ),它允许我将模式设置为锁定或自定义,但相关的 iso 和 ExposureDuration 属性是 iOS只要。

有没有办法控制 OSX 中 AVFoundation 的曝光时间?或者甚至使用另一个框架?

macos avfoundation avcapture avcapturedevice

6
推荐指数
0
解决办法
262
查看次数

AVCaptureMetadataOutput().rectOfInterest 不工作

我正在构建一个UIView具有覆盖框的盒子,最终目标是让 QR 码阅读器仅在 QR 落在盒子内时才触发。我知道我需要将 设置.rectOfInterest()为与黄色框相同,但是在当前实现中(下面的代码),读取器不起作用。

public override init(frame: CGRect) {
    super.init(frame: frame)

    if let captureDevice = AVCaptureDevice.default(for: .video) {
        do {
            let input = try AVCaptureDeviceInput(device: captureDevice)
            session.addInput(input)
        } catch {
            print("Error")
        }

        let scannerRect = CGRect(x: self.center.x - (self.frame.width * 0.667 / 2), y: self.frame.width * 0.667 / 4, width: self.frame.width * 0.667, height: self.frame.width * 0.667)

        let output = AVCaptureMetadataOutput()
        output.rectOfInterest = scannerRect
        session.addOutput(output)

        output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
        output.metadataObjectTypes = [.qr]

        video = AVCaptureVideoPreviewLayer(session: …
Run Code Online (Sandbox Code Playgroud)

qr-code avcapturedevice cgrect swift

6
推荐指数
1
解决办法
2185
查看次数

macOS:作为 AVFoundation CaptureDevice 访问虚拟相机 (OBS)

在 macOS 上,是否可以将虚拟相机(例如OBS)视为 CaptureDevice?例如,我看到 Google Chrome 或 Zoom 可以使用此相机,但使用 AVCaptureDevice.DiscoverySession 我无法看到它。

我做错了吗?

    var deviceTypes: [AVCaptureDevice.DeviceType] = [.builtInMicrophone, .builtInWideAngleCamera]
    #if os(OSX)
    deviceTypes.append(.externalUnknown)
    #else
    deviceTypes.append(contentsOf: [.builtInDualCamera,
                                    .builtInDualWideCamera,
                                    .builtInTelephotoCamera,
                                    .builtInTripleCamera,
                                    .builtInTrueDepthCamera,
                                    .builtInUltraWideCamera])
    #endif
    let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes,
        mediaType: nil, position: .unspecified)

    result = discoverySession.devices.map { device in
        device.localizedName
    }
Run Code Online (Sandbox Code Playgroud)

macos avfoundation avcapturedevice obs

6
推荐指数
1
解决办法
754
查看次数

具有可视化效果的音频录制 Mac 应用程序无法使用 AudioKit 选择输入设备

嘿,我想知道是否有人可以指出我正确的方向。

我正在构建一个 Mac 音频应用程序,我需要执行以下操作

  • 选择音频输入设备
  • 显示设备输入的实时音频图(想想 GarageBand/Logic)
  • 捕获音频以进行重播
  • 输出声音或使其可选择作为另一个应用程序的输入设备 - 类似于 GarageBand Logic 等插件的工作方式

到目前为止,我已经研究过使用以下内容:

  • 音频套件
  • AVFoundation/AVCaptureDevice

AudioKit

这个框架看起来很棒,并且有我想做的大部分事情的示例应用程序,但是它似乎只接受 Mac 在设置中选择的音频输入。这对我来说是不可能的,因为我希望用户能够在应用程序中进行选择(就像 GarageBand 或 Neural Dsp 插件一样)

使用AudioEngine我可以获得可用的输入设备,但我发现的所有内容都表明它们在应用程序中不可更改 - 这是显示它们的代码

struct InputDevicePicker: View {
    @State var device: Device
    var engine: AudioEngine

    var body: some View {
        Picker("Input: \(device.deviceID)", selection: $device) {
            ForEach(getDevices(), id: \.self) {
                Text($0.name)
            }
        }
        .pickerStyle(MenuPickerStyle())
        .onChange(of: device, perform: setInputDevice)
    }

    func getDevices() -> [Device] {
        AudioEngine.inputDevices.compactMap { $0 }
    }

    func setInputDevice(to device: Device) { …
Run Code Online (Sandbox Code Playgroud)

macos avfoundation avcapturesession avcapturedevice audiokit

6
推荐指数
0
解决办法
138
查看次数