MAC OSX AVFoundation视频捕获
我是MAC OSX开发的新手。我想在OSX 10.7上使用AVFoundation将视频捕获为原始帧。我不明白为相机设备设置特定的视频分辨率,不知怎的,我使用VideoSettings设置,但如果我设置320x240,它将捕获在320x176。我不理解是否有任何API调用不匹配。MAC OSX AVFoundation视频捕获
请帮我解决这个问题。提前等待你的答复.....谢谢.......
问候, 阿南德
在AVCaptureDevice有两个属性。格式和activeFormat。格式将返回包含凸轮公开的所有格式的AVCaptureDeviceFormat的NSArrary。您从此列表中选择任何一种格式并将其设置为activeFormat。确保在通过调用AVCaptureDevice lockForConfigration获得对devlce的独占访问权限后设置格式。设置格式后,用AVCaptureDevice unlockForConfigration释放锁定。然后启动AVCaptureSession,它将为您提供您设置的格式的视频帧。
AVCaptureFormat是CMFormatDescription的包装。 CMVideoFotmatDescription是CMFormatDescription的concreete子类。使用CMVideoFormatDescriptionGetDimentions()以设置的格式获取宽度和高度。使用CMFormatDescriptionGetMediaSubType()获取视频编解码器。对于raw fotmats,视频编解码器大多是yuvs或vuy2。对于压缩格式,它的h264,dmb1(mjpeg)等等。
user692178的答案有效。但更清洁的方法是设置kCVPixelBufferWidthKey
和kCVPixelBufferHeightKey
选项AVCaptureVideoDataOutput
对象。然后在开始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];
注意:此宽度/高度将覆盖会话预置宽度/高度(如果不同)。
在您的问题中包括您的代码将帮助我们帮助您。 – Caleb 2013-03-28 06:03:35