Linux下 打开多个USB 2.0 摄像头的问题( libv4l2: error turning on stream: No space left on device )

来源:互联网 发布:一诺网络 编辑:程序博客网 时间:2024/06/02 01:46

Linux下 打开多个摄像头会出错,错误信息:

libv4l2: error turning on stream: No space left on device

网上搜了下,很多人碰到这种情况,但基本都没解决问题,留下的都是无用的信息。特写这篇文章,好让某些人少走弯路。


----------------------------------------------------------------------------------------------------------------

问题的准确描述:Linux系统下,当多个usb摄像头在 同一个USB2.0的控制器下挂载,就会出现这种情况。

----------------------------------------------------------------------------------------------------------------

可以用命令查看 lsusb -t 查看当前电脑挂载的usb设备的树型结构关系:



这种情况下,就会提示libv4l2: error turning on stream: No space left on device, 不管你用opencv 还是qt, 还是xawtv,luvcview, vlc打开,都没用的,这跟上层应用没关系。

因为这是Linux kernel里面的 uvc设备驱动的一个bug。简单描述一下就是,YUV是非压缩的视频格式,对于USB2.0,一旦有一个设备插入,就会静态的占去80%的USB带宽,所以在控制器下再加一个USB设备,就会报错,带宽不够。

当然,如果多个摄像头分别挂载在不同的usb 控制器下就不会有问题了,比如我电脑有一个usb3.0的口,换了个口,插进去,再 lsusb -t 确认一下,发现确实在不同的控制器下,这个时候两个camera就能同时打开了(注意哦,不同的USB接口,有可能是挂载在一个控制器下,这个你得拆开电脑看看的,还是lsusb -t 眼见才是真):



有兴趣的可以参考这篇英文解释

http://www.ideasonboard.org/uvc/faq/

To work around the problem you can start with the following options.

  • Disable other devices that allocate periodic transfer bandwidth. This includes keyboards, mice and microphone/speaker. The easiest way to disable audio devices is to blacklist the snd-usb-audio module.
  • Capture video in a compressed format. Many UVC devices support both uncompressed YUV and compressed MJPEG, switching from YUV to MJPEG should reduce bandwidth usage.
  • Reduce the frame size. Reducing the frame rate is unlikely to help given that images are often transferred in bursts regardless of the frame rate
  • Connect the cameras to different USB host controller. This effectively raised the total available bandwidth as each USB host controller can use 480 Mb/s. Note that connecting the cameras to separate hubs on a single USB host controller won't help here. Extra USB host controllers can be added to the system as cheap PCI cards.
稍微翻译一下:

1)拔掉或者禁掉其他的设备,如鼠标,键盘,麦克...

2)用压缩的MJPEG格式传输,或者降低像素,这样能减少带宽的使用。

这种方法我测试过,行得通。一个用默认的640x480打开,一个用300x200的打开就可以了,但像素太低就没啥好看的吧,看来是两难啊。

sudo apt-get install luvcviewluvcview -d /dev/video1 -f yuv -s 300x200luvcview -d /dev/video0 -f yuv

3)减少视频传输的帧率, 这个用处不大,因为如果某个时刻两个USB摄像头恰好都在传输数据,那还是要挂掉的。

4)换个usb 控制器。 这个方法最简单有效了。

----------------------------------------------------------------------------------------------

opencv下好像可以用压缩的格式打开摄像头。参考下面的文章:

http://answers.opencv.org/question/146/selecting-mjpg-with-a-usb-webcam/

有人修改并重新编译了一下Linux kernel 源码里面的uvc设备的驱动,有兴趣的可以试试:

http://stackoverflow.com/questions/9781770/capturing-multiple-webcams-uvcvideo-with-opencv-on-linux

0 0
原创粉丝点击