V4l tv card to texture

sorry if this is a little off topic, but i havent been to these forums in a while.

i am trying to get data from a video4linux supported tv card to a OpenGL texture map in linux. so far, i have it working, but its very slow, and im having trouble figuring out how to speed things up. my current code looks something like this (its all spread out in various functions, but this is about how it goes):

int width = 384;
int height = 288;
int size = width * height * 4;
//set everything up

while( running )
{
read( vidfile, frame, size );
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, frame );
//draw quad with texture
}

ive done everything i can to remove any calculations being made in the execution loop, but unfortunately this is still slower than i need it to be. i tried mmaping the file to the memory i need, but i cant get the card to give me any data that way. is there a faster way to do this with read() or is read() just too slow?

thanks for any help

[This message has been edited by Spiral Man (edited 07-26-2003).]

What hardware are you using? I’ve heard that pulling a video stream into system RAM can saturate a whole processor pretty completely. Also, if you’re reading the video stream into your graphics card and then sending it back to your graphics card you could be sending a whole lot of data on the AGP bus.

well, im using a bt878 based card (a hauppauge pci card), so its not pushing any more data over the agp bus that if i was uploading a texture each frame.

however, i figured out how to get mmap working (i was using ioctl incorrectly), so im using a dual buffered mmap read, and im getting a much better framerate. also, my single buffered mmap read was also a lot faster than calling read(), so i guess there is a lot of overhead in the read() call.

thanks for the help

What about MPlayer ? It’s support v4l input and OpenGL video output. The relevant texture filling code is in libvo/vo_gl.c or libvo/vo_gl2.c.
On my computer the gl video output is more faster (and consume less (1%) CPU) than gl2 module (30% CPU).

If you are intrested in, I wrote video shader support to gl video output module (ARB_vertex_program and ARB_fragment_program
supported), it’s small, and perhaps not perfect, but it works. Some example shader also available (b&w, negative, edge detection)

The patch (against MPlayer-0.90) are available: http://aromo.aszi.sztaki.hu/~potyi/mplayer/

Before you compile please make sure you use the latest GL extension header files (glext.h, glxext.h)

Regards,
potyi

Originally posted by Spiral Man:
[b]well, im using a bt878 based card (a hauppauge pci card), so its not pushing any more data over the agp bus that if i was uploading a texture each frame.

however, i figured out how to get mmap working (i was using ioctl incorrectly), so im using a dual buffered mmap read, and im getting a much better framerate. also, my single buffered mmap read was also a lot faster than calling read(), so i guess there is a lot of overhead in the read() call.

thanks for the help[/b]

[This message has been edited by potyi (edited 07-29-2003).]

[This message has been edited by potyi (edited 07-29-2003).]

thanks for the tip. ill look into the mplayer source and see if i can speed my code up some more. unfortunately, vertex and pixel shaders wont do me much good on my geforce2 (and id like the program to be usable on slightly older hardware, if i can make it)

thanks again for all the help

I know that some(most/all?) tv cards block until a full frame is in the buffer so you wont get higher frame rates than what you tv standard supplies

Originally posted by Spiral Man:
[b]sorry if this is a little off topic, but i havent been to these forums in a while.

i am trying to get data from a video4linux supported tv card to a OpenGL texture map in linux. so far, i have it working, but its very slow, and im having trouble figuring out how to speed things up. my current code looks something like this (its all spread out in various functions, but this is about how it goes):

int width = 384;
int height = 288;
int size = width * height * 4;
//set everything up

while( running )
{
read( vidfile, frame, size );
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, frame );
//draw quad with texture
}

ive done everything i can to remove any calculations being made in the execution loop, but unfortunately this is still slower than i need it to be. i tried mmaping the file to the memory i need, but i cant get the card to give me any data that way. is there a faster way to do this with read() or is read() just too slow?

thanks for any help

[This message has been edited by Spiral Man (edited 07-26-2003).][/b]

We just coded a “vj-software” for Linux with my friend and it uses also v4l input.

The trick to get good fps is to set up the card to capture many (4) frames at the same time… so when you read the first complete frame, there already is 3 more frames waiting for you… and after you have read the second frame, there is again 3 more frames waiting for you…

If you had not already done that (and of course use mmap():ed mode), please read the v4l documentation from the kernel sources. the API/usage is documented there.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.