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:
- Recompiling the ffmpeg library
- Preloading v4l2
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libv4l/v4l2convert.so
- 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
- 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:
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?
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.
Does anyone have an answer to this? I really would like to default to MJPEG.
Same problem. Anyone has an answer to this?