MAC OSX AVFoundation 视频捕捉

4

我是一名新手,想要使用AVFoundation在MAC OSX 10.7上捕获视频原始帧。我无法理解如何将特定的视频分辨率设置到相机设备上,我已经使用VideoSettings进行了设置,但如果我设置为320x240,它会捕获320x176的画面。我不知道是否有API调用不匹配。

请帮助我解决这个问题。谢谢!

祝好, Anand


在你的问题中包含代码将有助于我们帮助你。 - Caleb
2个回答

4
用户692178的答案是可行的,但更清晰的方法是在AVCaptureVideoDataOutput对象上设置kCVPixelBufferWidthKey和kCVPixelBufferHeightKey选项。然后在开始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];

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

3

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

AVCaptureFormat是CMFormatDescription的封装器。CMVideoFotmatDescription是CMFormatDescription的具体子类。使用CMVideoFormatDescriptionGetDimentions()获取所设置格式的宽度和高度。使用CMFormatDescriptionGetMediaSubType()获取视频编解码器。对于原始格式,视频编解码器大多是yuvs或vuy2。对于压缩格式,它们是h264、dmb1(mjpeg)等等。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接