I use AV Foundation to capture video from my webcam. A webcam can only create a video stream in a limited number of pixel formats, so I want the AV Foundation to be able to convert any camera with a pixel format to the desired pixel format, which may not be supported by the camera (i.e. the AV Foundation structure would have to do the conversion from the pixel format, the camera can record to the desired pixel format by itself). I'm looking for YUV for RGB, RGB for YUV, YUV for YUV and RGB for RGB conversions will be fine, similar to what Color Converter DSP provides in Windows Media Fundamentals .
At first I tried to set the type that I want as output to
-[AVCaptureVideoDataOutput setVideoSettings:@{(id)kCVPixelBufferPixelFormatTypeKey: @(constant)}]
so that the structure is converted to this type.
I tried to use all types from AVCaptureVideoDataOutput availableVideoCVPixelFormatTypes , but received only half of them, and another half errors with messages in the console, which is surprising, since you can imagine that if the pixel format is available, it will work.
Here are the AVCaptureVideoDataOutput availableVideoCVPixelFormatTypes formats that work for me:
- kCVPixelFormatType_422YpCbCr8_yuvs
- kCVPixelFormatType_422YpCbCr8
- kCVPixelFormatType_24RGB
- kCVPixelFormatType_32ARGB
- kCVPixelFormatType_32BGRA
Here are those errors:
- kCVPixelFormatType_16LE555
- kCVPixelFormatType_16BE565
- kCVPixelFormatType_16LE565
- kCVPixelFormatType_4444YpCbCrA8
- kCVPixelFormatType_444YpCbCr8
- kCVPixelFormatType_422YpCbCr16
- kCVPixelFormatType_422YpCbCr10
- kCVPixelFormatType_444YpCbCr10
The errors I get
"AVCaptureSession Warning: The session received the following error while unpacking the video: Domain Error = NSOSStatusErrorDomain Code = -6680" The operation could not be completed. (OSStatus Error -6680.) "Make sure all video output formats are properly configured."
and
Warning AVCaptureSession: The session received the following error while unpacking the video: Error Domain = NSOSStatusErrorDomain Code = -12905 "Operation could not be completed (error OSStatus -12905.)". Make sure all video output formats are configured correctly.
So I'm a little clueless here. Is there any way to know which pixel formats will work exactly? It just prints an error for the console, without returning any error values, so itβs hard to subtract whether such a conversion is possible or not. I'm also not too sure that if you correctly ask AV Media to perform pixel format conversion, maybe I should use only the pixel formats supported by the webcam here and use another AV Foundation class to convert the pixel format (I did not find such a class )?