Ask Your Question

itsrachelfish's profile - activity

2017-03-08 07:48:36 -0600 received badge  Good Question (source)
2013-10-21 00:36:38 -0600 received badge  Nice Question (source)
2012-07-12 16:38:07 -0600 received badge  Famous Question (source)
2012-07-12 16:36:33 -0600 commented answer Selecting MJPG with a USB webcam

How do you query support for it in code? What does that even mean?

As stated in my question, all the cameras tested support MJPG and YUYV. I used v4l2-ctl to make sure. The first link from click.wetfish.net shows the complete output of vtl2-ctl --list-formats-ext from one of my cameras. It clearly supports all of these resolutions in both MJPG and YUYV, however I have no way to choose which format I'd like to use within an OpenCV application.

2012-07-07 11:12:56 -0600 received badge  Notable Question (source)
2012-07-07 04:38:17 -0600 received badge  Popular Question (source)
2012-07-06 03:31:36 -0600 received badge  Student (source)
2012-07-05 22:44:14 -0600 received badge  Editor (source)
2012-07-05 22:43:21 -0600 asked a question Selecting MJPG with a USB webcam

Recently switched distros from Debian 6 to Ubuntu 12.04. I use multiple USB webcams with OpenCV's python bindings and need to use compression to avoid USB bandwidth issues. In Debian, OpenCV would select the MJPG video mode by default and everything was wonderful. In Ubuntu the default is YUYV and I've found no way to change it.

So far I've tried:

  1. Recompiling the ffmpeg library
  2. Preloading v4l2
    • LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libv4l/v4l2convert.so
  3. Using SetCaptureProperty
    • cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FOURCC, cv.CV_FOURCC('M', 'J', 'P', 'G')))
    • Which gives the warning: HIGHGUI ERROR: V4L: Property <unknown property="" string="">(6) not supported by device
  4. Setting the video mode with v4l2-ctl before running OpenCV.
    • v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=MJPG
    • This works as confirmed by v4l2-ctl -V but is reset whenever OpenCV runs.

Unfortunately none of those made any difference. And if you're wondering, MJPG works when specified as an outfmt in mplayer, so it's definitely an OpenCV issue.

Edit: Upon further investigation, I'm still confused. Very confused. Changing the resolution to 800x600 from 640x480 makes OpenCV select MJPG.

I used v4l2-ctl --list-formats-ext to list all the video modes supported by my camera, then tested all the available resolutions using the basic webcam example (camera.py) modified to use SetCaptureProperty().

352x288     YUYV
432x240     MJPG
640x360     YUYV
640x480     YUYV
800x448     YUYV
800x600     MJPG
960x544     MJPG
960x720     MJPG
1280x720    MJPG

While the video modes appear to change randomly, they do so in a predictable way. The same video modes are selected even using webcams of different models from different manufacturers. I tested 3 HP cameras and 1 Logitech, all of which support MJPG and YUYV.

If you'd like to see the complete output from v4l2-ctl, they are available here: