🔒 Locked
Managed DX Video
Advertisement
Original Post
Hi, I've been trying to play an AVI using the Video class in the AudioVideoPlayback namespace, rendering to a texture. There is absolutely no documentation on how to do this that I can find... :S I would much appreciate if someone could please post sample code or give me some guidance on how to do this (using RenderToTexture) I think. Thanks... Alex P.S. Also does anyone know what video formats it supports? Is it just AVI & WMV?
Even some documentation on how to use it would be good, though a download the best. thanks
thanks for the reply.
i saw that but thought it wasn't really necessary to include a full-blown DirectShow library. i've heard audiovideoplayback with videos on textures DOES WORK according to certain blogs...but no code. :S
anyway is this the solution you use?
i saw that but thought it wasn't really necessary to include a full-blown DirectShow library. i've heard audiovideoplayback with videos on textures DOES WORK according to certain blogs...but no code. :S
anyway is this the solution you use?
thanks for the recommendation...i may get it if it's a good book in general, but i'd prefer a tutorial/source code or something on video playback (with textures) in specific. if you have the time, i'd really appreciate the info.
i would advice u to return to the 2003 summer SDK 's ,they contain a sample in managed code for rendering video to texture
best regards
best regards
Thanks for your reply...I don't know how to geet back to this and I also want to keep the Dec 2005 (the last DX 9.0 SDK) & April 2006. Is there any other way I can find it?
My sincerest apologies for not replying last night when I said I would. It seems the info in the book is somewhat limited and doesn't offer a full code sample of how to do it. Even so, I will post what I can as well my thoughts on how to complete the process.
First you have to hook the video's event, TextureReadyToRender, which is fired whenever a new frame in the video is ready to be rendered. The newly created texture is stored in the TextureRenderEventArgs that is passed to the event handler. Second, you need to detect if the created texture was created in the default pool (which a) you have no control over and b) is required to use the render to texture feature). If this is the case, you can proceed by creating a surface and a textur of your own. The code snippet from the book goes like this:
This, I believe is the code that should go into the event handler that should be added after the video is created. Something along the lines of:
Video vid = new Video("myvideo.mpg", false);
vid.TextureReadyToRender += new EventHandler(OnTextureReadyToRender);
OnTextureReadyToRender(vid, vid.TextureRenderEventArgs);
I haven't tested any of this out, so you may have to do some tweaking of your own, but I believe this will take the texture generated by the video file, put it into textureSurface and you can use it as you please to render to whatever geometry you wish. I hope some of that helps and let me know when you get it working.
-AJ
First you have to hook the video's event, TextureReadyToRender, which is fired whenever a new frame in the video is ready to be rendered. The newly created texture is stored in the TextureRenderEventArgs that is passed to the event handler. Second, you need to detect if the created texture was created in the default pool (which a) you have no control over and b) is required to use the render to texture feature). If this is the case, you can proceed by creating a surface and a textur of your own. The code snippet from the book goes like this:
SurfaceDescription ds = e.Texture.GetLevelDescription(0);if (ds.Pool == Pool.Default) systemSurface = device.CreateOffscreenPlainSurface(ds.Width, ds.Height, ds.Format, Pool.SystemMemory);texture = new Texture(device, ds.Width, ds.Height, 1, Usage.Dynamic, ds.Format, Pool.Default);using (Surface videoSurface = e.Texture.GetSurfaceLevel(0)){ using (Surface textureSurface = texture.GetSurfaceLevel(0)) { device.GetRenderTargetData(videoSurface, systemSurface); device.UpdateSurface(systemSurface, textureSurface); }}This, I believe is the code that should go into the event handler that should be added after the video is created. Something along the lines of:
Video vid = new Video("myvideo.mpg", false);
vid.TextureReadyToRender += new EventHandler(OnTextureReadyToRender);
OnTextureReadyToRender(vid, vid.TextureRenderEventArgs);
private void OnTextureReadyToRender(object sender, TextureRenderEventArgs e){ //Code from above}I haven't tested any of this out, so you may have to do some tweaking of your own, but I believe this will take the texture generated by the video file, put it into textureSurface and you can use it as you please to render to whatever geometry you wish. I hope some of that helps and let me know when you get it working.
-AJ
Thank you very much for your reply and it's no prob you didn't reply immediately.
Anyway, texture and systemSurface aren't declared anywhere so i'm wondering where to put them - in general declaratoins or in the same method? and do they have any initialisers?
Also, what do I put for the render code since I'm using a game loop and Sprite object to draw textures?
Thanks again!
Anyway, texture and systemSurface aren't declared anywhere so i'm wondering where to put them - in general declaratoins or in the same method? and do they have any initialisers?
Also, what do I put for the render code since I'm using a game loop and Sprite object to draw textures?
Thanks again!
*bump*
Quote:
Original post by alex_myrpg
Thanks for your reply...I don't know how to geet back to this and I also want to keep the Dec 2005 (the last DX 9.0 SDK) & April 2006. Is there any other way I can find it?
Summer 04
Sumemr 03 Though this is DirectX 9.0b
Not sure which has the DirectShow samples. You can install them, choose custom and have it just install the sample code.
Thanks, I'll install them when I have time...they're big downloads though for such small samples. :(
Quote:
Original post by alex_myrpg
Thank you very much for your reply and it's no prob you didn't reply immediately.
Anyway, texture and systemSurface aren't declared anywhere so i'm wondering where to put them - in general declaratoins or in the same method? and do they have any initialisers?
Also, what do I put for the render code since I'm using a game loop and Sprite object to draw textures?
Thanks again!
I would make them private members of whatever class the pertinent code is going to be in. Except for texture, which, if you want, might be a public variable in case you want outside code to be able to mess around with your texture. Hope that helps.
-AJ
Interesting - I just tried that and the screen does flicker a bit when the video is meant to be playing. I think it's something to do with my render loop (the code in between device.BeginScene() and device.EndScene(). The important code is:
.Begin(SpriteFlags.AlphaBlend)
If _menuScreenVideo1.Playing Or True Then
' Render frame
'If _menuScreenVideo1Frame IsNot Nothing Then
' .Draw2D(_menuScreenVideo1Frame, Rectangle.Empty, SizeF.Empty, New PointF(0, 0), Color.White)
'End If
Else
' Render still image
.Draw2D(_menuScreenImage, Rectangle.Empty, SizeF.Empty, New PointF(0, 0), Color.White)
End If
' Draw message label
If _titleScreenTimer Mod 2000 < 1000 Then _
_menuScreenFont.DrawText(_menuScreen, "Press 'Space' to start", New Rectangle(0, 560, 800, 20), DrawTextFormat.Center, Color.White)
.End()
I'll experiment with it in the meanwhile but otherwise maybe this code will help you to diagnose the problem. Thanks for the help...
EDIT:
I've tried just about everything I can now including these pages:
http://www.spiludvikling.dk/viewtopic.php?p=13400
http://www.tar.hu/directx9kick/app02lev1sec3.html (possibly an excerpt from your book)
Anyway I'd very much appreciate if you could take a quick look at my code (maybe you only need to see the one class). Thanks...
[Edited by - alex_myrpg on April 13, 2006 1:30:44 PM]
.Begin(SpriteFlags.AlphaBlend)
If _menuScreenVideo1.Playing Or True Then
' Render frame
'If _menuScreenVideo1Frame IsNot Nothing Then
' .Draw2D(_menuScreenVideo1Frame, Rectangle.Empty, SizeF.Empty, New PointF(0, 0), Color.White)
'End If
Else
' Render still image
.Draw2D(_menuScreenImage, Rectangle.Empty, SizeF.Empty, New PointF(0, 0), Color.White)
End If
' Draw message label
If _titleScreenTimer Mod 2000 < 1000 Then _
_menuScreenFont.DrawText(_menuScreen, "Press 'Space' to start", New Rectangle(0, 560, 800, 20), DrawTextFormat.Center, Color.White)
.End()
I'll experiment with it in the meanwhile but otherwise maybe this code will help you to diagnose the problem. Thanks for the help...
EDIT:
I've tried just about everything I can now including these pages:
http://www.spiludvikling.dk/viewtopic.php?p=13400
http://www.tar.hu/directx9kick/app02lev1sec3.html (possibly an excerpt from your book)
Anyway I'd very much appreciate if you could take a quick look at my code (maybe you only need to see the one class). Thanks...
[Edited by - alex_myrpg on April 13, 2006 1:30:44 PM]
Quote:
Original post by alex_myrpg
Thanks, I'll install them when I have time...they're big downloads though for such small samples. :(
They are big becuase they contain the whole API not just the samples. When you install you can choose to install just the samples but there is no way to just download the samples.
Quote:
Original post by alex_myrpg
Interesting - I just tried that and the screen does flicker a bit when the video is meant to be playing. I think it's something to do with my render loop (the code in between device.BeginScene() and device.EndScene(). The important code is:
.Begin(SpriteFlags.AlphaBlend)
If _menuScreenVideo1.Playing Or True Then
' Render frame
'If _menuScreenVideo1Frame IsNot Nothing Then
' .Draw2D(_menuScreenVideo1Frame, Rectangle.Empty, SizeF.Empty, New PointF(0, 0), Color.White)
'End If
Else
' Render still image
.Draw2D(_menuScreenImage, Rectangle.Empty, SizeF.Empty, New PointF(0, 0), Color.White)
End If
' Draw message label
If _titleScreenTimer Mod 2000 < 1000 Then _
_menuScreenFont.DrawText(_menuScreen, "Press 'Space' to start", New Rectangle(0, 560, 800, 20), DrawTextFormat.Center, Color.White)
.End()
I'll experiment with it in the meanwhile but otherwise maybe this code will help you to diagnose the problem. Thanks for the help...
EDIT:
I've tried just about everything I can now including these pages:
http://www.spiludvikling.dk/viewtopic.php?p=13400
http://www.tar.hu/directx9kick/app02lev1sec3.html (possibly an excerpt from your book)
Anyway I'd very much appreciate if you could take a quick look at my code (maybe you only need to see the one class). Thanks...
I don't know if it's this way in your code, but the first call to Draw2D(), the one that draws the video frame, is commented out. Therefore, the frame is never getting drawn. Try uncommenting that line and see what happens.
-AJ
Actually I've tried that and many more ways of rendering it in the loop, including drawing primitives, etc...all the same result: flicker of screen. I guess I'll try the samples next...
EDIT:
Good news at last! Just tried the Summer 04 sample and it had a working example...I managed to port it to my engine nicely and it's now rendering to a texture.
It turns out the trick was to put the render code (BeginScene, ..., EndScene, Present) in the TextureReadyToRender event and not to render in the main game loop while the video is playing. Does that sound like a good solution? I may try to use SyncLock to improve the mechanism. Anyway thanks for all your help guys.
[Edited by - alex_myrpg on April 14, 2006 10:50:50 AM]
EDIT:
Good news at last! Just tried the Summer 04 sample and it had a working example...I managed to port it to my engine nicely and it's now rendering to a texture.
It turns out the trick was to put the render code (BeginScene, ..., EndScene, Present) in the TextureReadyToRender event and not to render in the main game loop while the video is playing. Does that sound like a good solution? I may try to use SyncLock to improve the mechanism. Anyway thanks for all your help guys.
[Edited by - alex_myrpg on April 14, 2006 10:50:50 AM]
Hello everyone, i have just the same problem as alex_myrpg and i used a similar solution.
I'm also using summer 2004 SDK and tried to modify it's original example to it's simplest form.
Again just like alex_myrpg, i had a good looking movie when placing the rendering code at the ReadyToRender event and of course, my problem is that i don't want to switch my render loop to the video loop.
Because this is a thread issue (i think) i tried the following solution using locks with no results :( :
The movie plays, but the texture renders for just a moment and then disappears. I think texture is being destroyed but i don't understand how because all code where i deal with texture is locked (or i suppose that).
What i didn't try is to have a copy of texture. I'll try this later but i think that when coping from texture to copyTexture the result will be the same since i cannot warranty that copyTexture will be safe, at least texture is not because the lock code seems to be useless.
Any suggestions will be greatly appreciated.
Best regards.
I'm also using summer 2004 SDK and tried to modify it's original example to it's simplest form.
Again just like alex_myrpg, i had a good looking movie when placing the rendering code at the ReadyToRender event and of course, my problem is that i don't want to switch my render loop to the video loop.
Because this is a thread issue (i think) i tried the following solution using locks with no results :( :
protected void Render() {device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue, 1.0f, 0);device.BeginScene();lock(sync){ device.Transform.World = Matrix.RotationAxis( new Vector3((float)Math.Cos(Environment.TickCount / 250.0f),1, (float)Math.Sin(Environment.TickCount / 250.0f)), Environment.TickCount / 1000.0f ); // Set the texture device.SetTexture(0,textura); device.SetStreamSource(0, vertexBuffer, 0); device.VertexFormat = CustomVertex.PositionNormalTextured.Format; device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, (4*25)-2);}device.EndScene();device.Present();}//End RenderTexture texture=null;Surface systemSurface;private Object sync = new Object(); //to lock threads when working with texture//Called by ReadyToRendervoid RenderIt(object sender, TextureRenderEventArgs e){lock(sync){ using(e.Texture){ SurfaceDescription ds = e.Texture.GetLevelDescription(0); if (ds.Pool == Pool.Default){ systemSurface = device.CreateOffscreenPlainSurface(ds.Width, ds.Height, ds.Format, Pool.SystemMemory); } texture = new Texture(device, ds.Width, ds.Height, 1, Usage.None, ds.Format, Pool.Default); using(Surface videoSurface = e.Texture.GetSurfaceLevel(0)){ using(Surface textureSurface = texture.GetSurfaceLevel(0)){ device.GetRenderTargetData(videoSurface, systemSurface); device.UpdateSurface(systemSurface, textureSurface); } } }}}//End RenderItThe movie plays, but the texture renders for just a moment and then disappears. I think texture is being destroyed but i don't understand how because all code where i deal with texture is locked (or i suppose that).
What i didn't try is to have a copy of texture. I'll try this later but i think that when coping from texture to copyTexture the result will be the same since i cannot warranty that copyTexture will be safe, at least texture is not because the lock code seems to be useless.
Any suggestions will be greatly appreciated.
Best regards.
Hi, I've pretty much given up on this...but please let me know if you find out. :)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement