[Streaming] Video on a texture - ?

Hi everyone!

Have you seen Doom 3’s videos on a “message boards”?

Any way of fast-projecting (?) an AVI to a texture?

Thanks in advance,



Originally posted by Freelancer:
[b]Hi everyone!

Have you seen Doom 3’s videos on a “message boards”?

Any way of fast-projecting (?) an AVI to a texture?

Thanks in advance,
Easy… Get DXSDK and find Texture3D example. Modify it by removing D3D stuff and just copy frame in some shared temp buffer. In main render loop check for new data and upload it to texture and render. Use some events and critical sections to synchronize access to shared temp buffer.

Use PBO to upload texture (if hw support it).

If you can’t get smooth playback try to limit max fps in your engine (ie. insert Sleep(10) after SwapBuffers) to give chance to decoder to finish it’s job.


If you’re using the NeHe tutorial, good luck playing back the sound…
yooyo, got a working example? I sorta have something up and running but since most of the videos these days come with different sound streaming coding, I have yet to get anything working with sound.
PS: Well I have something but I’m using an expensive hack to play the sound…

I also modified the Texture3D example and it worked pretty fast.
In this example, as there is no sound rendered overloaded, it seems that the sound is played using the default sound device. So the sound works.
Another point: if you use PBO extension, it is only faster if your video decodes to BGRA. If you decode to RGB or BGR, using PBO is slower than not using it (at least in my experience in some computer configurations).
The NEHE example uses vfw instead of DirectShow and it is much more slower because you are calling the decode function every frame, even if there is no new frame in the video.
Also this example uses the DrawDibDraw that is very slow and is not necesary in most of the cases (if you know the format of the video and it is not a YUV or similar format)
The speed diference is really big. In the DShow example there is a callback that is called when a new frame is needed so you only update the texture when a new frame is decoded.
In the Nehe example, even with the DrawDibDraw call removed, you are decoding and updating the texture with the same data until the new frame comes which makes it really slow.

Hope this helps.

Sir, I would really appreciate it if you can send me some sample code showing a video working with sound in an OpenGL scene.
Thanks in advance :slight_smile:

For a limited time :slight_smile:
You can download a quick and dirty modification of the Nehe example using the Texture3D DShow example.

Note that you should have installed the DirectX SDK including the Extras that are in a separate download.

Also note that the example was made for a 512x256 video (the size of the texture) and assuming that the video is decoded in BGR. It was a quick test I made so I commented all the code that converts between formats but I left it on the code so you can take it back.

Hope this helps.

Who’s the man? Cab’s the man :smiley:
Thanks for your help, I’ll be taking a look at this later on and I’ll try and provide some feedback :slight_smile:

You can use GL_TEXTURE_RECTANGLE_EXT to keep texture memory. It works with PBO very smooth.

Your demo eats up to 80% of cpu time on my P4 2.8Ghz during decoding xvid 608x256 movie. Just add Sleep ( 10 ) in U1P_UpdateStats and cpu time will be ~5-10%.



I just wanna take a moment and send a big thank you out there for Cab; your sample code was really helpful in getting me all started.
I’ve been working on a faster and better version though in the past few hours and I should be able to put together a demo tomorrow and post it right here.

Cheers :slight_smile:


Most formats, including WMV/ASF, supported :slight_smile:
Early beta picture (hmm I wonder where have I bumped into something like that before :stuck_out_tongue: )


Nice. Will you provide source code?

I think you can use many decoder to decode the VIDEO to a 2d Image buffer.
you can use Windows AVI API . or use a opensource lib at sourceforge named “avifile”.

and you also could use DirectShow . it is very easy to use . and you can copy most of the code from MSDXSDK .

here is a example. with source code


Originally posted by Nico:
Nice. Will you provide source code?
Guilty as charged :smiley: .
Look into AppUtils, DVTexture for the code relevant to this demo, and Application GLSL DV for the main files.