Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / [Direct3D] Animated Textures; rendering a movie to a texture Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

April 04, 2005, 10:07 AM

For a school project we, a friend and I, are developping a not-so-state-of-the-art(no HDR, parallax mapping etc) 3d framwork using Managed Direct3D in C#. We just like to implement some realy handy features so other can develop faster and (most important) have no worries about 3D management or math.

One of the features we are developing is rendering a movie(AVI) to a texture. At first it seemed simple; every 1/framerate we read another frame from the movie into the texture. We currently using the following procedures to copy a frame from the movie to the texture:

we're using the AviFile wrapper wich we got from:

  2. // The both surfaces are of the same size and format.
  3. m_texAvi = new Texture(SceneGraphViewer.m_d3ddevice, m_video.Width, m_video.Height, 1, 0, Format.A8R8G8B8, Pool.Default);
  4. m_surDraw = m_texAvi.GetSurfaceLevel(0);
  6. // This happens in a different thread than the render thread
  7. m_video.GetFrameOpen();
  8. while(m_bOn)
  9. {
  10.   Bitmap b = m_video.GetBitmap(iFrameNumber);
  11.   Surface s = new Surface(m_dev, b, Pool.SystemMemory);
  12.   m_dev.UpdateSurface(s, m_surDraw);
  13. }
  14. m_video.GetFrameClose();

We've also tried other methods:

the Microsoft.DirectX.AudioVideoPlayback.Video class...
wich resulted in bad performance and we had to use a whole other
method of rendering our scene. Since it forces you to draw the texture when the event is fired.

We're wondering if video streams are a smart thing to use or wether
we should just use static sequences of textures (thus cache the movie).
And if so, whats the fastest method of copying the video frame to a texture surface in Managed DirectX.


April 04, 2005, 08:24 PM

i used directshow and directx 9 successfully to do what you have in mind. it is a rather simple thing if you use the baseclasses provided by the sdk for the com objects for filters etc. i have no idea wheter this would work with the managed directx in c# though. if you want i can put up the source for it somewhere.


April 05, 2005, 02:12 AM

That option came across our path when we searched the internet. We would like to have a look at your approach. We have some experience in unmanaged direct3d so it shouldn't be problem to read your code. Thanks in advance.


April 06, 2005, 06:32 PM

ok here's the url



i really tried to make the source as clean as possible, but i didn't comment the lexer/parser for the scriptfiles. don't think that you'll have a look at that anyways. if you got any questions you can reach me via msn or on irc efnet in channel #badlogic. i also want to emphasise that the video part is a bit hackish and i might have missed some important checks. sadly the documentation of directshow sucks a little so no warranty for the code.


April 07, 2005, 10:07 AM

Well thanks for the help but the source and the demo doesn't seems to be there (404). I sure would like to have a look at your code even if its hackish, I guess its sometimes nesicery.
As for the project we decided to use texture transforms, not as cool as AVI's but if you're creative enough just as good.


April 07, 2005, 06:05 PM

oh sorry my fault, correct links



should do. hope that helps. btw, what are texture transforms? do you mean using the matrices to alter texture coordinates on runtime?

This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.