MAC OSX AVFoundation视频捕获 [英] MAC OSX AVFoundation video capture
问题描述
我是MAC OSX开发的新手.我想使用OSX 10.7上的AVFoundation将视频捕获为原始帧.我不了解如何使用VideoSettings设置相机设备的特定视频分辨率,但是如果我设置为320x240,则它将以320x176的分辨率捕获.我不了解API调用是否不匹配.
I am new bie to MAC OSX development. I wanted to capture video as raw frames using AVFoundation on OSX 10.7. I am not understanding setting specific video resolution to camera device, somehow I setted using VideoSettings, but if I set 320x240, it is capturing at 320x176. I am not understanding is there any API call mismatch.
请帮助我,您可以解决此问题.等待您的回复...谢谢…….
Please help me yo sort out this issue. Awaiting for your reply.....Thanks in advance.......
关于, 阿南德
推荐答案
user692178的答案有效.但是更干净的方法是在AVCaptureVideoDataOutput
对象上设置kCVPixelBufferWidthKey
和kCVPixelBufferHeightKey
选项.这样就无需在启动AVCaptureSession
之前通过调用AVCaptureDevice lockForConfigration
获得对设备的独占访问权.最小样本如下.
The answer by user692178 works. But a cleaner approach would be to set kCVPixelBufferWidthKey
and kCVPixelBufferHeightKey
options on AVCaptureVideoDataOutput
object. Then there won't be need to get exclusive access to device by calling AVCaptureDevice lockForConfigration
before starting AVCaptureSession
. Minimal sample as below.
_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];
注意:此宽度/高度将覆盖会话预设的宽度/高度(如果不同).
Note: This width/height will override session preset width/height (if different).
这篇关于MAC OSX AVFoundation视频捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!