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

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

问候,
阿南德

最佳答案

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

_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];

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

关于avfoundation - MAC OSX AVFoundation 视频捕捉,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15608931/

10-13 00:51