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.......
Regards, Anand
The answer by user692178 works. But a cleaner approach would be to set
kCVPixelBufferWidthKey
andkCVPixelBufferHeightKey
options onAVCaptureVideoDataOutput
object. Then there won't be need to get exclusive access to device by callingAVCaptureDevice lockForConfigration
before startingAVCaptureSession
. Minimal sample as below.Note: This width/height will override session preset width/height (if different).
In AVCaptureDevice there are two properties. formats and activeFormat. format will return an NSArrary of AVCaptureDeviceFormat with contains all formats exposed by cam. You select any one format from this list and set it to activeFormat. Make sure that you set the format after you receive the exclusive access to the devlce by calling AVCaptureDevice lockForConfigration. After you set the format release the lock with AVCaptureDevice unlockForConfigration. Then start the AVCaptureSession which will give you the video frames of the format you set.
AVCaptureFormat is a wraper for CMFormatDescription. CMVideoFotmatDescription is the concreete subclass of CMFormatDescription. Use CMVideoFormatDescriptionGetDimentions() to get the width and height in the set format. Use CMFormatDescriptionGetMediaSubType() to get the video codec. For raw fotmats video codec mostly is yuvs or vuy2. For compressed formats its h264, dmb1(mjpeg) and many more.