Webcam pixel formats and Gstreamer caps filters

Up until now I have been using the standard (link) YUV 4:2:2 pixel format with my Logitech Webcam Pro 9000. This format is good for most cases; however, the framerate is limited to 15/2 fps at 1280×720 resolution, while the other supported formats (MJPG, RGB3, BGR3, YU12, YV12) support this reolution with up to 30 fps! So it was time for me to figure it out.

The RGB formats were easy: video/x-raw-rgb,format=RGB3 and video/x-raw-rgb,format=BGR3 respectively. Unfortunately, my subsequent tests showed that using this format the USB link could not sustain framerates higher than 15 fps at 1280×720.

The planar YUV formats YU12 and YV12 were a little more tricky. I could easily idnetify YV12 as YV12 in fourcc but for YU12 I had to dig a bit to figure out that it is the same as I420. And so the Gstreamer caps filter stringa become: video/x-raw-yuv,format=(fourcc)I420 and video/x-raw-yuv,format=(fourcc)YV12 respectively. These two formats can sustain about 28 fps at 1280×720 resolution.

MJPG seems to be quite cool in that the link can sustain 29.5 fps at 1280×720 without any notable loss in quality. I’m not quite sure about the format though – is this really a pixel format or what? Using image/jpeg in the caps filter and adding a jpegdec element before the xvimagesink seems to work. Unfortunately, the MJPG data coming from the Logitech Webcam Pro 9000 and QuickCam Vision Pro 9000 cameras appears to be buggy and makes the JPEG decoders choke with the error:

  Error #69: Unsupported marker type 0x80

The number is different every time suggesting that some data is lost. If I reduce the resolution to 352×288 pixels the problem disappears. I will have to see if it makes any difference if I use a faster computer.

Interestingly, guvcview has no problem displaying the MJPG stream at any resolution.

A mapping between the formats and the Gstreamer caps is given in the table below. It also provides links to the corresponding V4L2 format types.

Camera Fourcc V4L2 Type Gstreamer caps
YUYV YUY2 V4L2_PIX_FMT_YUYV (YUYV) packed video/x-raw-yuv,format=(fourcc)YUY2
MJPG TBC: V4L2_PIX_FMT_JPEG (JPEG) compressed image/jpeg
RGB3 TBC: V4L2_PIX_FMT_RGB24 (RGB3) packed video/x-raw-rgb,format=RGB3
BGR3 TBC: V4L2_PIX_FMT_BGR24 (BGR3) packed video/x-raw-rgb,format=BGR3
YU12 I420 V4L2_PIX_FMT_YUV420 (YU12) planar video/x-raw-yuv,format=(fourcc)I420
YV12 YV12 V4L2_PIX_FMT_YVU420 (YV12) planar video/x-raw-yuv,format=(fourcc)YV12