video capture in 0.05

Hi all

OF 0.05 ships with a new video module for linux based on unicap library

http://unicap-imaging.org/

It should support more cameras than the v4l version specially firewire devices not supported at all by the v4l specification.

Help testing unicap module

We’ve been having issues with some devices. Mostly v4l2 ones. It will be really helpful if you can test your cameras under linux and post here if anything goes wrong. Here’s some things you can do to help debugging if your device doesn’t work:

1. Test your device with ucview and other linux video app and post the results, you can find instructions in this post:
http://forum.openframeworks.cc/t/testing-video-grabbing-under-linux/373/0

2. If your camera work with other linux apps but not with OF:
Execute the movieGrabberExample from a console window or within codeblocks and post here the output.
**
3.** From a console window execute:
lsusb
and post the output.

With that we’ll have a clue of what’s happening, but if you feel like, at the link below you can download a debug version of the unicap library. If your device works under linux with other software but it doesn’t with OF unicap module, substitute the unicap library under libs/unicap with this one, execute the movieGrabberExample and post the output so we can trace the problem in the unicap library itself:
http://65.111.166.199/OF/unicap.debug.zip

Make your usb/integrated device work

Finally if you are using a usb or integrated camera, and you’re having trouble with OF 0.05 but it works with other linux apps or with previous versions of OF, almost sure the problem is with v4l2 and it will work with the v4l module. To make OF work with the v4l module, just comment line 130 in libs/openframeworks/utils/ofConstants.h:

#define OF_SWITCH_TO_UNICAP_FOR_LINUX_VIDCAP

to

//#define OF_SWITCH_TO_UNICAP_FOR_LINUX_VIDCAP

Hi arturo,
Thanks for your fantastic work with this. However I was wondering whether DV video camera support is at all on the horizon…I remember you mentioning that the unicap developer might make some DV additions for OF. Did this ever come about? I’ve got a DV camera that works under kino but not ucview or OF.

Thanks!

Hi grimus

You remember well :slight_smile:

Some time ago I was speaking with him because of this and other issues in unicap and he told me that although he wasn’t at all interested in supporting DV cams he was going to send a module with the basic functionality for dv under unicap but i haven’t heard from him since then. He has released 2 or 3 new versions since then, so the library is under development but since this isn’t a priority for him I don’t know when this can be working (if it will be). I’ll try to contact him.

Also, yesterday preparing the videograbber for the 0.05 release I was thinking that if finally we decide to mantain both libraries, I can get the colorspace conversion functions out of ofUCUtils so you can use the same ones in ofV4lUtils: let’s see what happens.

To both Arturo and Grimus:
:smiley: Great work on the video capture implementation for OF 0…05.
Last week I couldn’t get either of my two webcams to work and this week I’ve got my firewire webcam (Pyro 1394) working with the unicap library and although my usb webcam (v4l2 Logitech Quicam Pro) does not work with unicap it works perfectly with v4l now that YUV420 support was added. Thank you both!

Hi Jaime

Can you post the output from the unicap module in v4l2 mode so we can try to trace what it’s happening.

Thanks

With unicap library turned on and using my USB camera OF gives me this in the terminal:

  
enumerate: 8000000  
Total count method 1: 10  
Total count method 2: 0  
Unicap : Using device /dev/video0   
Unicap : Using module v4l2  
choosing device 0: Logitech QuickCam Pro 4000 (usb-0000:00:1d.2-1)  
Unicap : Available formats for this device:  
Unicap : 0: Raw Philips Webcam ( PWC2 ), min size: 160x120, max size:384x288, default size: 640x480  
Unicap : 1: 4:2:0, planar, Y-Cb-Cr ( YU12 ), min size: 160x120, max size:384x288, default size: 640x480  
Unicap : Selected format: Raw Philips Webcam ( PWC2 ), with size 320x240  
Unicap : Format not suported  
Segmentation fault (core dumped)  

Doesn’t work with ucview either. ucview responds with this in the terminal:

  
** Message: Could not convert format: 4:2:0, planar, Y-Cb-Cr ( YU12 ) 32315559 to 4:2:0, planar, Y-Cb-Cr ( YU12 ) 33424752  
  

lsusb outputs:

  
Bus 004 Device 002: ID 046d:08b2 Logitech, Inc. QuickCam Pro 4000  

Thanks very much…

I’ll take a look when i have some time.

Hi,

I have an integrated camera on my Thinkpad T61. I’m running ubuntu 7.10. ucview works, but in OF with either unicap or v4l, it’s not working with the movieGrabberExample.

Using unicap, I get no errors, just a black box with a white box next to it. Here’s the output:

  
  
enumerate: 8000000  
Total count method 1: 6  
Total count method 2: 0  
Unicap : Using device /dev/video0   
Unicap : Using module v4l2  
choosing device 0: Integrated Camera (0000:00:1d.7)  
Unicap : Available formats for this device:  
Unicap : 0: YUV 4:2:2 (YUYV) ( YUYV ), min size: 160x120, max size:1280x960, default size: 640x480  
Unicap : Selected format: YUV 4:2:2 (YUYV) ( YUYV ), with size 320x240  
  

when I type ‘s’:

  
  
 Converting to RGB24Unicap : Video settings:  
	 Brightness: 0.00   
	 Contrast: 0.00   
	 Saturation: 0.00   
	 Hue: 0.00   
	 Gamma: 1.00   
	 Gain: 24.00   
	 video source: Camera 1   
  

When using v4l (commenting out #define OF_SWITCH_TO_UNICAP_FOR_LINUX_VIDCAP in ofConstants.h), I just get an error:

  
  
choosing device /dev/video0  
V4L : Name = 'Integrated Camera'  
V4L : Dimensions (48 x 32) - (1280 x 1024)  
V4L : Capability :  
 - CAPTURE  
V4L : Brightness	= 32896  
V4L : Hue		= 32768  
V4L : Colour		= 0  
V4L : Depth		= 16 bits  
V4L : Palette		= VIDEO_PALETTE_YUYV  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : ERROR : Unable to change to a suitable palette  
V4L : Video size changed to width=320 height=240  
V4L : Could not use mmap : 22, Invalid argument  
V4L : Could not use mmap buffer.  
V4L : Shutting down....  
success allocating a video device   
V4L : ERROR: VIDIOCSYNC failed. Bad file descriptor  
  

Any idears?

-Brian

Hi brian

It seems a problem with the colorspace conversion routine. I’ve used ffmpeg one instead of unicap so no more libraries are required, but of course I couldn’t test every colorspace conversion. It’s weird because it seems that it has found the correct color conversion.

Can you change your capture size to 640x480, from other debug traces like theo’s one, I think that there’s something wrong with the v4l2 resize algorithm.

If that doesn’t work, can you please substitute unicap with the debug version that is described in the first post so I can see if there’s any more information ?

Arturo,

I replaced unicap with the debug version and ran movieGrabberExample. The output is below. Reading over the output, nothing strikes me as being wrong. Do you see anything? Thanks for the help.

-Brian

  
  
dcam.c cpi_enumerate_devices (177) :dcam: can' t get handle  
unicap.c enumerate_devices (407) :status: 80000001  
vid21394_cpi.c cpi_enumerate_devices (555) :failed to get raw1394 handle  
unicap.c enumerate_devices (407) :status: 80000001  
v4l.c v4l_enumerate_devices (220) :*** v4l enumerate devices  
v4l.c v4l_enumerate_devices (233) :v4l: open /dev/video0  
v4l.c v4l_enumerate_devices (243) :v4l2 ioctls succeeded (Patched version)  
unicap.c enumerate_devices (407) :status: 80000001  
v4l2.c v4l2_enumerate_devices (325) :v4l2_enumerate_devices[0]  
v4l2.c v4l2_enumerate_devices (339) :v4l2: open /dev/video0  
unicap.c enumerate_devices (402) :current index: 0  
v4l2.c v4l2_enumerate_devices (325) :v4l2_enumerate_devices[1]  
v4l2.c v4l2_enumerate_devices (339) :v4l2: open /dev/video0  
unicap.c enumerate_devices (407) :status: 80000001  
unicap.c open_cpi (562) :open----------Integrated Camera (0000:00:1d.7)  
v4l2.c v4l2_open (390) :v4l2_open  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 0  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 1  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 2  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 3  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 4  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 5  
tisuvccam.c tisuvccam_add_controls (362) :Failed to add info for control: 6  
tisuvccam.c tisuvccam_add_controls (371) :Failed to add info for control: 0  
tisuvccam.c tisuvccam_probe (409) :tisuvccam_probe: not an TIS UVC device  
v4l2.c v4l2_reenumerate_formats (765) :enum format: index 0 desc YUV 4:2:2 (YUYV)  
v4l2.c try_enum_framesizes (598) :found 7 framesizes for fourcc: 56595559  
v4l2.c v4l2_reenumerate_properties (1108) :v4l2_reenumerate_properties  
v4l2.c v4l2_reenumerate_properties (1247) :add property: Brightness  
v4l2.c v4l2_reenumerate_properties (1247) :add property: Contrast  
v4l2.c v4l2_reenumerate_properties (1247) :add property: Saturation  
v4l2.c v4l2_reenumerate_properties (1247) :add property: Hue  
v4l2.c v4l2_reenumerate_properties (1247) :add property: Gamma  
v4l2.c v4l2_reenumerate_properties (1247) :add property: Gain  
v4l2.c v4l2_reenumerate_properties (1306) :add property: Backlight Compensation  
v4l2.c v4l2_reenumerate_properties (1306) :add property: Power Line Frequency  
v4l2.c v4l2_reenumerate_properties (1306) :add property: Sharpness  
v4l2.c v4l2_reenumerate_properties (1306) :add property: Exposure, Auto  
v4l2.c v4l2_reenumerate_properties (1306) :add property: Exposure (Absolute)  
v4l2.c v4l2_enum_norms (1071) :Failed to enumerate norms  
v4l2.c v4l2_enum_frameintervals (896) :v4l2_enum_frameintervals  
Unicap : Using device /dev/video0   
Unicap : Using module v4l2  
choosing device 0: Integrated Camera (0000:00:1d.7)  
Unicap : Available formats for this device:  
unicap.c unicap_enumerate_formats (764) :unicap_enumerate_formats, index: 0  
Unicap : 0: YUV 4:2:2 (YUYV) ( YUYV ), min size: 640x480, max size:1280x1024, default size: 640x480  
unicap.c unicap_enumerate_formats (764) :unicap_enumerate_formats, index: 1  
v4l2.c v4l2_set_format (843) :v4l2_set_format  
Unicap : Selected format: YUV 4:2:2 (YUYV) ( YUYV ), with size 640x480  
Converting to RGB24unicap.c unicap_lock_stream (1167) :LOCK STREAM >>>> 1 key = 3430360  
unicap.c unicap_start_capture (922) :Capture start...  
v4l2.c v4l2_capture_start (1612) :v4l2_start_capture  
v4l2.c v4l2_capture_start (1645) :Method: MMAP  
v4l2.c v4l2_queue_buffer (1971) :QUEUE  
v4l2.c queue_buffer (1855) :Q: index = 0 type = 1, memory = 1  
v4l2.c v4l2_wait_buffer (2010) :WAIT  
v4l2.c v4l2_wait_buffer (2034) :-WAIT  
v4l2.c v4l2_queue_buffer (1971) :QUEUE  
v4l2.c queue_buffer (1855) :Q: index = 1 type = 1, memory = 1  
v4l2.c v4l2_wait_buffer (2010) :WAIT  
v4l2.c v4l2_wait_buffer (2034) :-WAIT  
v4l2.c v4l2_queue_buffer (1971) :QUEUE  
  

Hi Brian,

That looks pretty odd on my side.
Are you sure your driver is OK? Have you tested the web cam with applications known to work?

Hi Grimus,

I’m not _sure_ anything is ok ;), but I’ve tested the camera with ucview, Cheese, and maybe one or two other apps I can’t remember now, and it works fine with just about everything. [One app that it didn’t work with I think is called “Canorama” (I’m away from that machine right now). I just saw it in my gnome menu and it had a web-cam icon next to it, so I tried it and it displayed an error dialog box that read something like “Cannot open device at /dev/video0”. I didn’t investigate it further though so mentioning it probably doesn’t help.]

What seems odd to you about the output in my previous post?

Thanks for the help.

-Brian

Hi Brian

I’m with Pierre that it’s really strange that at least anything appear in the screen. I suppose is a problem with the yuv format. There are some variants to yuv http://www.fourcc.org/yuv.php, and unicap reports the colorspace in fourcc format but then ffmpeg uses it’s own format id system.

In ofUCUtils.cpp there’s a conversion table that you can try to alter in order to find if that’s the problem. It seems that unicap reports your device to use YUYV so try to change line 37:

  
  
 { PIX_FMT_YUYV422, 	FOURCC('Y', 'U', 'Y', 'V') },  
  

for any other of the PIX_FMT like: PIX_FMT_YUV422P or PIX_FMT_YUV422, then clean your example and compile again, perhaps the conversion table is wrong for your device.

Also write lsusb in a console and post the output so I can google what format does your device use.

Jaime

sorry for the late reply.There was a problem with the format selection algorithm in the unicap module, and if it didn’t find an rgb format it was just selecting the first format although it wasn’t supported by the ffmpeg conversion. In your case a PWC2 strange philips propietary one

Can you try to replace your ofUCUtils.cpp by this one:

http://65.111.166.199/openframeworks/ofUCUtils.cpp

and tell me if it works?

thanks

Sorry Brian,

I read the error message too hastily - it looks indeed like a conversion problem.
I’ve added the YUYV format. Can you replace ofV4LUtils.h in the library video code and give it a try?

http://www.digitalstar.net/openframeworks/ofV4LUtils.h

Let me know how it goes!

Hey Guys,

Thanks for the help. Unfortunately, I haven’t had luck with anything. I messed with the conversion table, but everything behaved the same and I saw no difference in the output.

I then switched to v4l to the new V4LUtils file, and I got pretty much the same results as before. The output is here:

  
  
choosing device /dev/video0  
V4L : Name = 'Integrated Camera'  
V4L : Dimensions (48 x 32) - (1280 x 1024)  
V4L : Capability :  
 - CAPTURE  
V4L : Brightness        = 32896  
V4L : Hue               = 32768  
V4L : Colour            = 0  
V4L : Depth             = 16 bits  
V4L : Palette           = VIDEO_PALETTE_YUYV  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Failed to set image properties : 22, Invalid argument  
V4L : Changed current palette to VIDEO_PALETTE_YUYV  
V4L : Video size changed to width=640 height=480  
V4L : Could not use mmap : 22, Invalid argument  
V4L : Could not use mmap buffer.  
V4L : Shutting down....  
success allocating a video device   
V4L : ERROR: VIDIOCSYNC failed. Bad file descriptor  
  

The last little piece of info is the device from lsusb:

  
  
Bus 002 Device 002: ID 17ef:1004   
  

Again, thanks for the help. It’s starting to seem more and more like some fluky hardware-specific thing. I’ll keep poking around and let you know if I turn anything up.

-Brian

Hi Brian

No idea why it doesn’t work. I’m googling for your device, if there’s something I’ll tell you.

By the way, it seems your device works with the uvc module, you can test by typing in a terminal:

lsmod | grep uvc

if something appears then that’s the problem with v4l, from the uvc project site, http://linux-uvc.berlios.de/:

The Linux UVC projects is currently focussing on kernel support for UVC devices. The driver implements the Video4Linux 2 (V4L2) API. Support for V4L1 is not planned.

Hi

I’ve uploaded the last compiled version of unicap (0.2.23). Looking at the changelog, I think it can solve some of the problems with v4l2 devices.

You can download it from:

http://65.111.166.199/openframeworks/unicap-libs.tar.gz

Uncompress it and substitute the libs/unicap contents.

Hi Arturo,

Can’t get it running with the new unicap lib
Here’s the output:

  
  
Unicap : Error opening device 0:   
Unicap : Using device    
Unicap : Using module   
choosing device 0:   
Unicap : Available formats for this device:  
Unicap : Can't set video format , with size 320x240  
Unicap : Failed to set alternative video format!  
Unicap : Failed to start capture  
Unicap : Failed to queue a buffer  
Unicap : Failed to queue a buffer  
Unicap : Failed to queue a buffer  
  

Hans

ups! sorry it was incorrectly compiled, now it should work…