Ask Your Question
7

Selecting MJPG with a USB webcam

asked 2012-07-05 22:43:21 -0600

itsrachelfish gravatar image

updated 2012-07-07 07:29:07 -0600

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:

edit retag flag offensive close merge delete

Comments

I'm having the same problem. I need to force OpenCV to use MJPEG, but I have been unable to. I had essentially tried everything you have here, did you come up with a solution?

randomlogic78 gravatar imagerandomlogic78 ( 2013-01-11 11:31:38 -0600 )edit

Same issue. I change setting to MJPEG before running my OpenCV code. After my code runs, the format returns to YUYV at 640x480. I also tried your edited version 800x600. Still no luck. Using Logitech C920 webcam here.

szhao37 gravatar imageszhao37 ( 2013-10-21 00:39:27 -0600 )edit

Does anyone have an answer to this? I really would like to default to MJPEG.

BPCook gravatar imageBPCook ( 2015-03-12 11:05:57 -0600 )edit

Same problem. Anyone has an answer to this?

cvcook gravatar imagecvcook ( 2015-07-09 20:13:51 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2012-07-10 06:18:27 -0600

beebop gravatar image

every webcam model have own list of supported video modes and output formats(!) so before you use mode you must query support for it in code.

edit flag offensive delete link more

Comments

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.

itsrachelfish gravatar imageitsrachelfish ( 2012-07-12 16:36:33 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-07-05 22:43:21 -0600

Seen: 21,203 times

Last updated: Jul 10 '12