linux video grabbing enhancements


I’ve made some modifications to the unicap video grabbing module. The one in 0.05 waits for a new frame every time you call grabFrame(), so an application using it will only run at the same fps as the device’s speed.

This new version uses dma if the capture device is capable of, so it should be faster, also as there’s no wait in the main thread your app should run now without the device speed limitation.

I’ve tested it and it works ok, but it would be great if you can give it a try and give some feedback before considering it a definitive change.

You just have to download:

And substitute the current files in libs/openFrameworks/video with these ones.

Hi Arturo,
Tried your new files, without a good result I’m afraid.
No errors and stuff, but no result on the screen
This is the output while executing:

Unicap : Using device /dev/video0   
Unicap : Using module   
choosing device 0: UVC Camera (046d:0990) (/dev/video0)  
Unicap : Available formats for this device:  
Unicap : 0: MJPEG ( MJPG ), min size: 160x120, max size:960x720, default size: 320x240  
Unicap : 1: YUV 4:2:2 (YUYV) ( YUYV ), min size: 160x120, max size:1600x1200, default size: 320x240  
Unicap : Selected format: YUV 4:2:2 (YUYV) ( YUYV ), with size 320x240  
Converting to RGB24  

And the debug dump (of which I don’t understand anything at all):

*** glibc detected *** ./movieGrabberExample_debug: double free or corruption (out): 0x08336cc8 ***  
======= Backtrace: =========  
======= Memory map: ========  
08048000-08225000 r-xp 00000000 08:01 4538955    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/movieGrabberExample_debug  
08225000-0823d000 rw-p 001dc000 08:01 4538955    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/movieGrabberExample_debug  
0823d000-0834b000 rw-p 0823d000 00:00 0          [heap]  
b53c2000-b53fb000 rw-p b53c2000 00:00 0   
b53fb000-b53fc000 ---p b53fb000 00:00 0   
b53fc000-b5bfc000 rwxp b53fc000 00:00 0   
b5d00000-b5d21000 rw-p b5d00000 00:00 0   
b5d21000-b5e00000 ---p b5d21000 00:00 0   
b5e49000-b5e4a000 rw-p b5e49000 00:00 0   
b5e4a000-b5e4b000 rw-s 00000000 00:09 2424858    /SYSV00000000 (deleted)  
b5e4b000-b5e4c000 rw-s 00000000 00:09 2392089    /SYSV00000000 (deleted)  
b5e4c000-b5e8c000 rw-s e7ac6000 00:0e 13087      /dev/nvidia0  
b5e8c000-b5f8c000 rw-s 35d9c000 00:0e 13087      /dev/nvidia0  
b5f8c000-b608c000 rw-s 3196d000 00:0e 13087      /dev/nvidia0  
b608c000-b60f5000 rw-p b608c000 00:00 0   
b60f5000-b6159000 rw-p 00000000 00:0e 1068       /dev/zero  
b615a000-b665a000 rw-s e0000000 00:0e 13087      /dev/nvidia0  
b665a000-b667d000 rw-p b665a000 00:00 0   
b667d000-b669f000 rw-s 00000000 00:09 0          /SYSV00000000 (deleted)  
b669f000-b6705000 rw-p b669f000 00:00 0   
b6705000-b6709000 r-xp 00000000 08:01 10651220   /usr/lib/  
b6709000-b670a000 rw-p 00003000 08:01 10651220   /usr/lib/  
b670a000-b6721000 r-xp 00000000 08:01 10652050   /usr/lib/  
b6721000-b6722000 rw-p 00016000 08:01 10652050   /usr/lib/  
b6722000-b6723000 rw-p b6722000 00:00 0   
b6723000-b6724000 r-xp 00000000 08:01 10652048   /usr/lib/  
b6724000-b6725000 rw-p 00000000 08:01 10652048   /usr/lib/  
b6725000-b6727000 r-xp 00000000 08:01 10651209   /usr/lib/  
b6727000-b6728000 rw-p 00001000 08:01 10651209   /usr/lib/  
b6728000-b673c000 r-xp 00000000 08:01 10652062   /usr/lib/  
b673c000-b673d000 rw-p 00013000 08:01 10652062   /usr/lib/  
b673d000-b673e000 r-xp 00000000 08:01 10651326   /usr/lib/  
b673e000-b673f000 rw-p 00000000 08:01 10651326   /usr/lib/  
b673f000-b7213000 r-xp 00000000 08:01 10650277   /usr/lib/  
b7213000-b724f000 rwxp 00ad3000 08:01 10650277   /usr/lib/  
b724f000-b7254000 rwxp b724f000 00:00 0   
b7254000-b7255000 rw-p b7254000 00:00 0   
b7255000-b7339000 r-xp 00000000 08:01 10651203   /usr/lib/  
b7339000-b733c000 rw-p 000e4000 08:01 10651203   /usr/lib/  
b733c000-b7349000 r-xp 00000000 08:01 10651224   /usr/lib/  
b7349000-b734a000 rw-p 0000d000 08:01 10651224   /usr/lib/  
b734a000-b735e000 r-xp 00000000 08:01 4097364    /lib/tls/i686/cmov/  
b735e000-b7360000 rw-p 00013000 08:01 4097364    /lib/tls/i686/cmov/  
b7360000-b7362000 rw-p b7360000 00:00 0   
b7362000-b7364000 r-xp 00000000 08:01 4097344    /lib/tls/i686/cmov/  
b7364000-b7366000 rw-p 00001000 08:01 4097344    /lib/tls/i686/cmov/  
b7366000-b74af000 r-xp 00000000 08:01 4097338    /lib/tls/i686/cmov/  
b74af000-b74b0000 r--p 00149000 08:01 4097338    /lib/tls/i686/cmov/  
b74b0000-b74b2000 rw-p 0014a000 08:01 4097338    /lib/tls/i686/cmov/  
b74b2000-b74b6000 rw-p b74b2000 00:00 0   
b74b6000-b74c0000 r-xp 00000000 08:01 4079680    /lib/  
b74c0000-b74c1000 rw-p 0000a000 08:01 4079680    /lib/  
b74c1000-b74e4000 r-xp 00000000 08:01 4097346    /lib/tls/i686/cmov/  
b74e4000-b74e6000 rw-p 00023000 08:01 4097346    /lib/tls/i686/cmov/  
b74e6000-b75ce000 r-xp 00000000 08:01 10651987   /usr/lib/  
b75ce000-b75d1000 r--p 000e8000 08:01 10651987   /usr/lib/  
b75d1000-b75d3000 rw-p 000eb000 08:01 10651987   /usr/lib/  
b75d3000-b75d9000 rw-p b75d3000 00:00 0   
b75d9000-b75e0000 r-xp 00000000 08:01 4645967    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b75e0000-b75e1000 rw-p 00006000 08:01 4645967    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b75e1000-b75e3000 rw-p b75e1000 00:00 0   
b75e3000-b766d000 r-xp 00000000 08:01 4645968    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b766d000-b7673000 rw-p 00089000 08:01 4645968    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b7673000-b7a73000 r-xp 00000000 08:01 4645961    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b7a73000-b7a79000 rw-p 00400000 08:01 4645961    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b7a79000-b7b72000 rw-p b7a79000 00:00 0   
b7b72000-b7c31000 r-xp 00000000 08:01 10651281   /usr/lib/  
b7c31000-b7c35000 rw-p 000be000 08:01 10651281   /usr/lib/  
b7c35000-b7c39000 r-xp 00000000 08:01 10651260   /usr/lib/  
b7c39000-b7c3a000 rw-p 00003000 08:01 10651260   /usr/lib/  
b7c3a000-b7cbc000 r-xp 00000000 08:01 10651166   /usr/lib/  
b7cbc000-b7cbd000 rw-p 00081000 08:01 10651166   /usr/lib/  
b7cbd000-b7d45000 r-xp 00000000 08:01 10650015   /usr/lib/  
b7d45000-b7d60000 rwxp 00087000 08:01 10650015   /usr/lib/  
b7d60000-b7d61000 rwxp b7d60000 00:00 0   
b7d61000-b7d90000 r-xp 00000000 08:01 10651538   /usr/lib/  
b7d90000-b7d95000 rw-p 0002e000 08:01 10651538   /usr/lib/  
b7d95000-b7d96000 rw-p b7d95000 00:00 0   
b7d96000-b7d9b000 r-xp 00000000 08:01 10651922   /usr/lib/  
b7d9b000-b7d9c000 rw-p 00004000 08:01 10651922   /usr/lib/  
b7d9e000-b7da2000 rw-s 35ee6000 00:0e 13087      /dev/nvidia0  
b7da2000-b7da3000 rw-s e7b07000 00:0e 13087      /dev/nvidia0  
b7da3000-b7da4000 rw-s 35ee5000 00:0e 13087      /dev/nvidia0  
b7da4000-b7da5000 rw-s 35ee4000 00:0e 13087      /dev/nvidia0  
b7da5000-b7da6000 rw-s f2001000 00:0e 13087      /dev/nvidia0  
b7da6000-b7da7000 rw-s f2c02000 00:0e 13087      /dev/nvidia0  
b7da7000-b7da9000 rwxp 00000000 00:0e 1068       /dev/zero  
b7da9000-b7eae000 r-xp 00000000 08:01 4645964    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b7eae000-b7ebf000 rw-p 00104000 08:01 4645964    /home/hans/of_preRelease_v0.05_linux_cb_FAT/apps/examples/movieGrabberExample/bin/libs/  
b7ebf000-b7f76000 rw-p b7ebf000 00:00 0   
b7f76000-b7f77000 r-xp b7f76000 00:00 0          [vdso]  
b7f77000-b7f91000 r-xp 00000000 08:01 4079635    /lib/  
b7f91000-b7f93000 rw-p 00019000 08:01 4079635    /lib/  
bfb7b000-bfb9b000 rwxp bffdf000 00:00 0          [stack]  
bfb9b000-bfb9c000 rw-p bffff000 00:00 0   

Putting the old files back again :wink:

Thanks hans

I think the debug output is just because of closing the application with the x control in the window instead of pressing esc.

Yours is the only device, by now, working with v4l2 so it doesn’t surprise me very much that it doesn’t work with dma an all.

I’ll have a v4l2 device this weekend, i’ll try to test this.

i’m wondering if there has been any change or progress on this front. I have a v4l2 webcam. works in cheese but am having a hard time with openframeworks. I have placed your new unicap files, and although i do not get segfaults, there is no image being returned. This is consistent with both the openCV example and the movie grabber one.

here’s the output from cmd line:

enumerate: 8000000  
Total count method 1: 4 Brightness Contrast Gamma Auto Gain Sharpness  
Total count method 2: 5  
Unicap : Using device /dev/video0   
Unicap : Using module v4l2  
choosing device 0: USB Camera (046d:08d7) (0000:00:1d.0)  
Unicap : Available formats for this device:  
Unicap : 0: JPEG ( JPEG ), min size: 320x240, max size:640x480, default size: 640x480  
Unicap : Can't set video format , with size 640x480  
Unicap : Failed to set alternative video format!  


there were some problems in 0.05 with v4l2 and yuv devices. this should be corrected in 0.06, although it’s not already released, you can try with this pre-release:…-FAT.tar.gz

[quote author=“arturo”]Hi

there were some problems in 0.05 with v4l2 and yuv devices. this should be corrected in 0.06, although it’s not already released, you can try with this pre-release:…-FAT.tar.gz[/quote]

aw, looks like there is a problem with the a dynamic librarie, POCO or something, nothing will compile because a file is missing.

looks like i might have to wait for of_0.6 pre release?

since the pre release of 0.06 wasn’t working, i got ucview with unicap,

btw, for ubuntu users, see here:

these are more recent instructions than those pointed on the download page.

i tried my cam with UCView and it didn’t work either, i checked the forums and i am not the only one,

someone else with my error and my webcam already posted about this here:…-?f=8&p=379

hmmm, this is weird indeed. i wonder how does cheese do it…

thanks again

yeah, of_ 0.06 needs a poco package,

i got it
video grabbing doesn’t work

i will try something else
thanks for all the help arturo


yeah, of_ 0.06 needs a poco package,

yes, sorry, forgot about that.

About your camera, if ucview doesn’t support it, it won’t work under oF. Anyway, i’ll upload a debug version of the latest unicap release later so you can debug your problem and post here and in the unicap forums.

[quote author=“arturo”]

yeah, of_ 0.06 needs a poco package,

yes, sorry, forgot about that.

About your camera, if ucview doesn’t support it, it won’t work under oF. Anyway, i’ll upload a debug version of the latest unicap release later so you can debug your problem and post here and in the unicap forums.[/quote]

that sounds like a good idea.

anyway, thanks again arturo


Have been looking the unicap forum, (couldn’t yesterday as it was failing), it seems it has to do with a colorspace conversion not supported in ucview. In oF I’ve used the ffmpeg routines for color conversion so if your camera supports some yuv or rgb format it should be working. can you post the output of the videoGrabber example with the 0.06 prerelease?



Hey ramy

has been trying with libv4l as said in the unicap forums and it seems to work. It’s kind of an abstraction layer over v4l and v4l2 devices so every device reports the same colorspaces.

I’ve uploaded a file with a substitution for unicap compiled with libv4l support + the last libv4l version. if you want to give it a try……-v4l.tar.gz

there’s a unicap directory, substitute the one in the libs directory with this one.

there’s also a cbp project file for the moviegrabber example, substitute that with your original one in the 0.06 prerelease.

please post if this works for you.