MAC OSX AVFoundation video capture

I am a new bie for the development of MAC OSX. I wanted to capture video as raw frames using AVFoundation on OSX 10.7. I don’t understand how to set a specific video resolution on the camera device, somehow I installed using VideoSettings, but if I installed 320x240, it captures 320x176. I don't understand if there are any API call mismatches.

Please help me solve this problem. Waiting for your reply ..... Thanks in advance .......

Regards, Anand

+3
avfoundation
source share
2 answers

There are two properties in AVCaptureDevice. formats and activeFormat. format will return an NSArrary from AVCaptureDeviceFormat containing all formats opened by the camera. You select any format from this list and set it to activeFormat. Make sure you set the format after gaining exclusive access to devlce by calling the AVCaptureDevice lockForConfigration function. After you set the format, release the lock using AVCaptureDevice unlockForConfigration. Then run AVCaptureSession, which will provide you with video clips of the format you installed.

AVCaptureFormat is a wraper for CMFormatDescription. CMVideoFotmatDescription is a subclass of the CMFormatDescription subclass. Use CMVideoFormatDescriptionGetDimentsions () to get the width and height in the given format. Use CMFormatDescriptionGetMediaSubType () to get the video codec. For raw fotmats, the video codec is mostly yuvs or vuy2. For compressed formats its h264, dmb1 (mjpeg) and many others.

+3
source share

User response692178 is working. But a cleaner approach would be to set the kCVPixelBufferWidthKey and kCVPixelBufferHeightKey to an AVCaptureVideoDataOutput object. Then there is no need to get exclusive access to the device by calling AVCaptureDevice lockForConfigration before starting AVCaptureSession . Minimum sample as shown 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 overrides the width / height of the session preset (if different).

+3
source share

All Articles