PDA

View Full Version : v4l tv card to texture



Spiral Man
07-26-2003, 09:53 AM
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).]

mogumbo
07-28-2003, 07:10 AM
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.

Spiral Man
07-28-2003, 08:36 AM
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

potyi
07-28-2003, 10:55 PM
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:
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

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

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

Spiral Man
07-29-2003, 07:05 AM
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

rwilco
08-02-2003, 08:32 AM
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

nrg
08-05-2003, 07:55 AM
Originally posted by Spiral Man:
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).]


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.