【问题标题】:MAC OSX AVFoundation video captureMAC OSX AVFoundation 视频采集
【发布时间】:2013-03-25 06:29:25
【问题描述】:

我是 MAC OSX 开发的新手。我想在 OSX 10.7 上使用 AVFoundation 将视频捕获为原始帧。我不了解为相机设备设置特定的视频分辨率,不知何故我使用 VideoSettings 设置,但如果我设置为 320x240,它会以 320x176 捕获。我不明白是否有任何 API 调用不匹配。

请帮我解决这个问题。等待您的回复......提前谢谢......

问候, 阿南德

【问题讨论】:

  • 在您的问题中包含您的代码将有助于我们为您提供帮助。

标签: avfoundation


【解决方案1】:

user692178 的回答有效。但更简洁的方法是在AVCaptureVideoDataOutput 对象上设置kCVPixelBufferWidthKeykCVPixelBufferHeightKey 选项。这样就不需要在启动AVCaptureSession 之前通过调用AVCaptureDevice lockForConfigration 获得对设备的独占访问权限。最小样本如下。

_session = [[AVCaptureSession alloc] init];
_sessionInput = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
_sessionOutput = [[AVCaptureVideoDataOutput alloc] init];

NSDictionary *pixelBufferOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSNumber numberWithDouble:width], (id)kCVPixelBufferWidthKey,
                              [NSNumber numberWithDouble:height], (id)kCVPixelBufferHeightKey,
                              [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey,
                              nil];
[_sessionOutput setVideoSettings:pixelBufferOptions];

注意:此宽度/高度将覆盖会话预设宽度/高度(如果不同)。

【讨论】:

    【解决方案2】:

    在 AVCaptureDevice 中有两个属性。格式和活动格式。 format 将返回 AVCaptureDeviceFormat 的 NSArrary,其中包含 cam 公开的所有格式。您可以从此列表中选择任何一种格式并将其设置为 activeFormat。确保在通过调用 AVCaptureDevice lockForConfigration 获得对设备的独占访问权限后设置格式。设置格式后,使用 AVCaptureDevice unlockForConfigration 释放锁定。然后启动 AVCaptureSession,它将为您提供您设置的格式的视频帧。

    AVCaptureFormat 是 CMFormatDescription 的包装。 CMVideoFotmatDescription 是 CMFormatDescription 的具体子类。使用 CMVideoFormatDescriptionGetDimentions() 获取设置格式的宽度和高度。使用 CMFormatDescriptionGetMediaSubType() 获取视频编解码器。对于 raw fotmats 视频编解码器主要是 yuvs 或 vuy2。对于压缩格式,它的 h264、dmb1(mjpeg) 等等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多