Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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['cam'],cv.CV_CAP_PROP_FOURCC, cv.CV_FOURCC('M', 'J', 'P', 'G')))
    • Which gives me 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.

click to hide/show revision 2
You don't need to know about my dict()s

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['cam'],cv.CV_CAP_PROP_FOURCC, cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FOURCC, cv.CV_FOURCC('M', 'J', 'P', 'G')))
    • Which gives me 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.

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 me 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.

click to hide/show revision 4
Moving stuff from my comments up here for better formatting.

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().

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

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.

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

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().

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

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.

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

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().

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

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.Logitech, all of which support MJPG and YUYV.

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

click to hide/show revision 7
Sorting resolutions by size for fun

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().

1280x720    MJPG
352x288     YUYV
432x240     MJPG
640x360     YUYV
640x480     YUYV
800x448     YUYV
800x600     MJPG
960x544     MJPG
960x720     MJPG
640x480     YUYV
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: