#region Groundplane with video texture
protected VertexBuffer CreateVertexBuffer(Device dev)
{
try
{
video = Video.FromFile("test.avi");//videoTexPath
//video.Ending += new EventHandler(MovieOver); // TODO: DISPOSING DOESN'T WORK!!
video.TextureReadyToRender += new TextureRenderEventHandler(onTextureReadyToRender);
video.RenderToTexture(dev);
video.Play();
// vidFrame.Text = Convert.ToString(video.CurrentPosition);
vidLength.Text = Convert.ToString(video.Duration);
//rotX.Text = Convert.ToString(video.CurrentPosition);
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
}
CustomVertex.PositionTextured[] quad = new CustomVertex.PositionTextured[4];
quad[0] = new CustomVertex.PositionTextured(-300.0f, -300.0f, 0.0f, 0.0f, 0.0f);
quad[1] = new CustomVertex.PositionTextured(-300.0f, 300.0f, 0.0f, 0.0f, 1.0f);
quad[2] = new CustomVertex.PositionTextured(300.0f, -300.0f, 0.0f, 1.0f, 0.0f);
quad[3] = new CustomVertex.PositionTextured(300.0f, 300.0f, 0.0f, 1.0f, 1.0f);
VertexBuffer buf = new VertexBuffer(
typeof(CustomVertex.PositionTextured), // What type of vertices
4, // How many
dev, // The device
0, // Default usage
CustomVertex.PositionTextured.Format, // Vertex format
Pool.Default); // Default pooling
GraphicsStream stm = buf.Lock(0, 0, 0);
stm.Write(quad);
buf.Unlock();
return buf;
}
///
/// The onTextureReadyToRender method (called from TextureRenderEventHandler to handle videotexture)
///
protected void onTextureReadyToRender(object sender, TextureRenderEventArgs e)
{
if (e.Texture == null)
return;
SurfaceDescription ds = e.Texture.GetLevelDescription(0);
if (ds.Pool == Pool.Default)
{
sysSurf = _device.CreateOffscreenPlainSurface(ds.Width, ds.Height,
ds.Format, Pool.SystemMemory);
}
using (Surface vidSurf = e.Texture.GetSurfaceLevel(0))
{
if (_tex == null)
{
_tex = new Texture(_device, ds.Width, ds.Height,
1, Usage.Dynamic, ds.Format, ds.Pool);
}
using (Surface texSurf = _tex.GetSurfaceLevel(0))
{
//_device.GetRenderTargetData(vidSurf, sysSurf);
//_device.UpdateSurface(sysSurf, texSurf);
SurfaceLoader.FromSurface(texSurf, vidSurf, Filter.Linear, unchecked((int)0xffffffff));
}
}
Invalidate();
}
///
/// Movie playback has ended
///
/*
void MovieOver(object sender, EventArgs e)
{
Dispose();
}
*/
#endregion
I've tried the following for disposing (cluttered with disposing some other textures):
protected void DisposeTextures()
{
if (_textures == null)
{
return;
}
foreach (Texture t in _textures)
{
if (t != null)
{
t.Dispose();
}
}
if (_tex == null)
{
return;
}
else
{
_tex.Dispose();
_tex = null;
}
if (video != null)
{
if (!video.Audio.Disposed)
{
video.Audio.Dispose();
}
if (!video.Disposed)
{
video.Stop();
//video.Dispose();
video = null;
}
}
}
I'll update here if I find a link where disposal of the video is explained, I should have one somewhere... From what I remember it doesn't work with only managed directx though, so you'll have to do some other tweak ;)
90 comments:
There's some talk on disposing video at http://www.gamedev.net/community/forums/topic.asp?topic_id=386498&PageSize=25&WhichPage=2
If you figure the video.dispose() using the code I posted, please reply here with a solution. Thanks
Thanks!
The issue I was having was implementing this inside a render loop I already had prepared; basically I just needed to copy it to the render method for the vertex I already had prepared ;-)
I haven't got much further though, now I need to get it to stop ripping and tearing during playback.
Also any ideas on the video formats it supports?
Cheers,
Sebastian
No, sorry - as I said, I quit the 'video in directx' trail a while back. By the way, I've heard that it's supposed to be fewer problems if you work with DirectShow than AudioVideoPlayback - even though DirectShow isn't officially supported in the latest SDK (Managed Code).
Currently, I'm working on a modeller, mainly to be a able to create buildings through a simple GUI. I just finished planning for it though, so it will probably be a couple of weeks before I have it working ;)
Great article! Thanks.
Thanks for interesting article.
Nice Blog!
Thank You! Very interesting article. Do you can write anything else about it?
Very interesting site. Blog is very good. I am happy that I think the same!
Nice! Nice site! Good resources here. I will bookmark!
Excellent website. Good work. Very useful. I will bookmark!
I see first time your site guys. I like you :)
djA0Dh You have a talant! Write more!
AMqCrQ Thanks to author.
rhUJFC The best blog you have!
TVwZSu Nice Article.
Please write anything else!
Good job!
Good job!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Thanks to author.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
qa5IUS write more, thanks.
Good job!
Hello all!
Thanks to author.
Wonderful blog.
Hello all!
Nice Article.
Nice Article.
Nice Article.
Good job!
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Good job!
Good job!
Thanks to author.
Thanks to author.
If ignorance is bliss, you must be orgasmic.
The gene pool could use a little chlorine.
Friends help you move. Real friends help you move bodies
Build a watch in 179 easy steps - by C. Forsberg.
Build a watch in 179 easy steps - by C. Forsberg.
What is a free gift ? Aren't all gifts free?
Oops. My brain just hit a bad sector.
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
Please write anything else!
Friends help you move. Real friends help you move bodies
Friends help you move. Real friends help you move bodies
Oops. My brain just hit a bad sector.
Energizer Bunny Arrested! Charged with battery.
640K ought to be enough for anybody. - Bill Gates 81
The gene pool could use a little chlorine.
Beam me aboard, Scotty..... Sure. Will a 2x10 do?
When there's a will, I want to be in it.
Save the whales, collect the whole set
Give me ambiguity or give me something else.
Friends help you move. Real friends help you move bodies
640K ought to be enough for anybody. - Bill Gates 81
Give me ambiguity or give me something else.
640K ought to be enough for anybody. - Bill Gates 81
What is a free gift ? Aren't all gifts free?
The gene pool could use a little chlorine.
Please write anything else!
I'm not a complete idiot, some parts are missing!
When there's a will, I want to be in it.
Save the whales, collect the whole set
What is a free gift ? Aren't all gifts free?
Build a watch in 179 easy steps - by C. Forsberg.
I don't suffer from insanity. I enjoy every minute of it.
A flashlight is a case for holding dead batteries.
Calvin, we will not have an anatomically correct snowman!
Suicidal twin kills sister by mistake!
Clap on! , Clap off! clap@#&$NO CARRIER
Thanks to author.
The gene pool could use a little chlorine.
Please write anything else!
Friends help you move. Real friends help you move bodies.
640K ought to be enough for anybody. - Bill Gates 81
Clap on! , Clap off! clap@#&$NO CARRIER
actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.
C++ should have been called B
What is a free gift ? Aren't all gifts free?
C++ should have been called B
Lottery: A tax on people who are bad at math.
Build a watch in 179 easy steps - by C. Forsberg.
Change is inevitable, except from a vending machine.
Energizer Bunny Arrested! Charged with battery.
Oops. My brain just hit a bad sector.
Hello E.H.
Do you have a complete example?
I integrate your code in my code, but the video is bucking. It is very slow and flickers.
Post a Comment