Sign in to follow this  
Roof Top Pew Wee

AudioVideoPlayback to texture

Recommended Posts

I've just gotten into AudioVideoPlayback to play videos. Playing a video in the window's simple enough, but now I'm trying to get the video to render to a texture. So, I checked the docs, and swa that I need to set an event for TextureReadyToRender, and also give the video a device. Here's my code:

Video video = new Video("test.avi");
video.TextureReadyToRender += new TextureRenderEventHandler(onTextureReadyToRender);
video.RenderToTexture(sprMan.D3DDevice);
video.Play();

// and the onTextureReadyToRender method:

private static void onTextureReadyToRender(object sender, TextureRenderEventArgs e)
		{
			someTexture.texture = e.Texture;
}


But it's not quite working right. The texture seems to flash black most of the time. Any suggestions? --Vic--

Share this post


Link to post
Share on other sites
In fact, it seems as if the video instance is causing some problem on my render loop. That is, the following code simply causes problems:

video = Video.FromFile("test.avi");

video.RenderToTexture(D3DDevice);

When I remove the RenderToTexture call, then everything works fine. It seems as if the video is doing something with the device that screws up the render loop. Anyone experienced this before, and if so, how can I get around it?

--Vic--

Share this post


Link to post
Share on other sites
turnpast    1011
I'm not totaly clear on what the problem is, but here are a couple of things to try.

1) Copy the texture produced by the video to another texture and use the copy for rendering -- SurfaceLoader.FromSurface should make a acceptable copy for you. there is a fair possibility that the texture produced by the video is being reuesed and that may be why it seems to flicker. Be aware that there may be a significent performance penalty because of the copy.

2) Pump your render from the video callback -- this may not work at all, but if it does it should help with your async problems (and force you to restructure your code in some very inconvienant ways).

hope this helps.

Share this post


Link to post
Share on other sites
I really appreciate your comments, turnpast.

As far as copying textures goes, I don't think that's the problem because I've completely eliminated the onTextureReadyToRender function. I'm not even using the texture created by the video. It's just sitting in the background creating textures, churning away without me doing anything with it.

I did put the rendering inside of the event, but this is definitely not what I want. It limits my framerate, and if I were to have multiple video files, things would get really wacky.

Has anyone done this at all? If so, could anyone post a little bit of sample code? I really am having trouble with this, and have been spending quite a few hrs. on something which seems like it should be simple. My render loop keeps getting interrupted and is throwing exceptions like crazy.

--Vic--

[Edited by - Roof Top Pew Wee on May 26, 2005 9:42:25 PM]

Share this post


Link to post
Share on other sites
Hmm, has no one done this? Well, since I'm limited to C# right now, I can't get into DirectShow. What else could I look to to get a video to a texture? Any other libraries? I'm dying to figure this one out. Debating even offering to PayPal some cash to anyone who helps.

--Vic--

Share this post


Link to post
Share on other sites
turnpast    1011
It may be that you have to pre-render the video to a set of textures and use that as an animation. Playing a video of any significent resolution is going to be a fairly resource intensive process and it is perhaps not surprising if it produces lag. I am still a little unclear on what exactly the problems it is causing are. Does it kill your frame rate? Does it just break everything?

Share this post


Link to post
Share on other sites
What happens is that the video callback occurs on a different thread from my rendering. Well, since my rendering loop is throwing exceptions like crazy, my guess is that the callback is doing something to the device during my render loop so that it is lost. But it's hard to really tell because of the two threads.

So that's why I'm really interested to see if anyone has done anything like this before, and if so, if I can see some sample code.

If I can't get it to work, then I will just take the videos and have them be a sequence of images which I can load into textures. However, I'd like to avoid that because even though playing video hurts performance, preloading the videos and storing them in textures will prob do even worse to my vid mem.

And it's not necessarily that it's killing my framerate, but rather interrupting my render loop, causing my screen to flash black really fast (every time the video's event is called). Have you ever gotten this to work? I'd love to see some code or a base project where it works, to see if I can compare and find out where I'm having problems.

--Vic--

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this