使用V4L2捕获网络摄像头流失败

时间:2012-02-26 03:24:32

标签: c linux ubuntu-10.04 v4l2

我开始使用Ubuntu 10.4上的V4L2框架。

目前我正在使用网络摄像头进行一些测试。我正在关注this文档开始,安装工作正常。我下载并编译了应用程序示例。问题是视频输出,我用以下方法调用可执行文件:

# modprobe -r pwc
# modprobe -v pwc fps=15 compression=3 mbufs=4 fbufs=4 size=vga
# ./capturer_mmap -D /dev/video0 -w 640*480 -p 0 | ./viewer -w 640*480 -p 0 

给出这个输出:

enter image description here

终端输出:

window size 640*480
Video bytespreline = 1280

Display:
Image byte order = LSBFirst
Bitmap unit      = 32
Bitmap bit order = LSBFirst
Bitmap pad       = 32

Window:
Depth            = 24
Red mask         = 0x00ff0000
Green mask       = 0x0000ff00
Blue mask        = 0x000000ff
Bits per R/G/B   = 8
Image byte order = LSBFirst
Bitmap unit      = 32
Bitmap bit order = LSBFirst
Bitmap pad       = 32
Depth            = 24
Red mask         = 0x00ff0000
Green mask       = 0x0000ff00
Blue mask        = 0x000000ff
Bits per pixel   = 32
Bytes per line   = 2560
IsShared         = True
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
      after 431 requests (19 known processed) with 0 events remaining.
root@my-laptop:/home/foo/V4l2_samples-0.4.1# ./capturer_mmap -D /dev/video0 -w 640*480 -p 0  | ./viewer -w 640*480 -p 0
window size 640*480
Video bytespreline = 1280

Display:
Image byte order = LSBFirst
Bitmap unit      = 32
Bitmap bit order = LSBFirst
Bitmap pad       = 32

Window:
Depth            = 24
Red mask         = 0x00ff0000
Green mask       = 0x0000ff00
Blue mask        = 0x000000ff
Bits per R/G/B   = 8
Image byte order = LSBFirst
Bitmap unit      = 32
Bitmap bit order = LSBFirst
Bitmap pad       = 32
Depth            = 24
Red mask         = 0x00ff0000
Green mask       = 0x0000ff00
Blue mask        = 0x000000ff
Bits per pixel   = 32
Bytes per line   = 2560
IsShared         = True
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
      after 101 requests (19 known processed) with 0 events remaining.

我不知道如何解决这个问题。我相信probrem是用C代码的,因为我可以使用网络摄像头和Webcam Chesse应用程序。非常感谢任何帮助。非常感谢!

1 个答案:

答案 0 :(得分:2)

看起来您正在以完全错误的格式显示图像。

使用v4l2时,你一定要看看“libv4l”(在debian中打包,在ubuntu中也可以使用)。 v4l2允许设备以任何非常大量的视频格式输出它的帧,其中一些被压缩(例如使用jpeg)。 core v4l2没有提供任何方法将图像转换为应用程序支持的给定格式,因此理论上您的应用程序必须支持所有可能的格式。

为了避免代码重复(每个支持v4l2的应用程序都面临同样的问题!),创建了libv4l:它允许对设备进行低级访问,但同时保证可以使用少量访问框架标准格式。 例如如果设备只支持jpeg-output而你的应用程序请求RGB32帧,libv4l将为你透明转换。

你甚至可以使用libv4l和一些LD_PRELOAD技巧,以使它适用于没有libv4l支持编译的应用程序(只是为了检查我的建议是否有意义)