XNA Creators Club Online
Page 1 of 2 (36 items) 1 2 Next >
Sort Posts: Previous Next

Video playeback in XNA?

Last post 8/27/2009 1:42 PM by Dreamwagon. 35 replies.
  • 2/23/2008 5:08 AM

    Video playeback in XNA?

    Hello everybody am really stuck with a video that i wanna play inside my XNA app but i searched everywhere and didn't find one single topic explains how to implement Video in XNA but just a hint that i can load videos as textures which means that i have to do my own codex so is it true or there is a video playback class or something that can helps me render videos inside XNA

    thanks

    Ashour
  • 2/23/2008 5:35 AM In reply to

    Re: Video playeback in XNA?

  • 2/23/2008 8:50 AM In reply to

    Re: Video playeback in XNA?

    Well its not working it just keeps giving me error that the video file doesn't exist even i set the content processor and importer to scurvy and i set tried all the build actions i also tried the sample in the source code and it gives the same error

    am using XNA beta 2 am downloading the full version now maybe the beta misses something

    Ashour
  • 2/23/2008 10:51 AM In reply to

    Re: Video playeback in XNA?

    Ashour:

    am using XNA beta 2 am downloading the full version now maybe the beta misses something



    That's probably it. It is never a good idea to keep using a beta product, after the release version was... released.
  • 2/23/2008 11:53 AM In reply to

    Re: Video playeback in XNA?

    I've tried using Scurvy Media before and it never worked for me. When I finally managed to overcome the exceptions during build (sorry, can't remember how I did that), there was a massive memory leak during the build, which eventually resulted in an OutOfMemoryException.

    I have however made a video player myself, which I would be more than happy to share here. It's based on DirectShow (so its not Xbox 360 compatible) but it works quite well on Windows. Since it's DirectShow, it will play any video file that Windows Media Player can play, including sound etc. It fills a Texture2D with the video data, so it can be rendered to screen using your own spritebatch, or used in a shader to apply effects.

    I'll post it here shortly once I've cleaned up the code.

  • 2/23/2008 4:13 PM In reply to

    Re: Video playeback in XNA?

    Well thanks but where is the Draw function or something similar?

    i tried the class but it resulted in the error :"The operation was aborted. You may not modify a resource that has been set on a device, or after it has been used within a tiling bracket." which origantes in the update function in the class u provided here is the code i tried:

     
            protected override void LoadContent()
    {
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);
    mPlayer = new VideoPlayer(@"C:\clip1.avi", GraphicsDevice);
    mPlayer.Play();
    // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
    // Allows the game to exit
    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
    this.Exit();

    mPlayer.Update();


    base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    Texture2D CurrentTex = mPlayer.OutputFrame;

    if (mPlayer.CurrentState== VideoState.Playing)
    {
    spriteBatch.Begin();

    spriteBatch.Draw(CurrentTex, new Rectangle(0, 0, CurrentTex.Width, CurrentTex.Height), Color.White);

    spriteBatch.End();
    }

    base.Draw(gameTime);
    }

     

    Ashour
  • 2/23/2008 5:01 PM In reply to

    Re: Video playeback in XNA?

    Answer
    Reply Quote

    I copied your code out and got the same error. The problem is in your draw call, on the line:

    spriteBatch.Begin();

    You need to change this to:

    spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Deferred, SaveStateMode.SaveState);

    Basically, enable SaveState on the SpriteBatch. What is happening is the Texture2D OutputFrame is being set on the GraphicsDevice to be rendered, but is not being removed before the next update, so the next update will fail as the texture is still on the graphics device.

    My Draw() call looks like this:

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
    Window.Title = videoPlayer.CurrentPositionAsTimeString + " - " + videoPlayer.DurationAsTimeString;
    GraphicsDevice.Clear(Color.Black);

    batch.Begin(SpriteBlendMode.None, SpriteSortMode.Deferred, SaveStateMode.SaveState);
    batch.Draw(videoPlayer.OutputFrame, renderArea, null, Color.White, 0, new Vector2(0, 0), SpriteEffects.None, 0);
    batch.End();

    base.Draw(gameTime);
    }

    The "renderArea" is a Rectangle, scaled to fit the window.

    I did not implement a Draw() method in the video player as I thought it would have been restrictive. Without it, you have the freedom to draw the texture anywhere, with shader effects, and even on a model.

    Also, be sure to call VideoPlayer.Dispose() once you have finished with the player, otherwise the threads and the Texture2D may not be cleaned up properly.

  • 2/24/2008 5:24 AM In reply to

    Re: Video playeback in XNA?

    Thanks its wokring pretty well here except for the sound but i'll try to extract it from video and play it separetly and Go On with your class i suggest you put on the codeplex for more benefit

    thanks cya

    Ashour
  • 2/24/2008 9:47 AM In reply to

    Re: Video playeback in XNA?

    I've moved the player to codeplex. It can now be found here:

    http://www.codeplex.com/XNADSPlayer

  • 3/30/2008 7:39 AM In reply to

    Re: Video playeback in XNA?

    Sorry,i haven't think how can i play a video in XNA.Can us explain it to me?
    Thanks.

    PS:sorry for bad english.
  • 3/31/2008 12:04 PM In reply to

    Re: Video playeback in XNA?

    There is no way to play video using XNA FX.

    You have to use the ScurvyMedia library or the XNADS library (both linked in the thread you replied to).

    Or you must write your own which would load video files one frame at a time and then draw them to a texture.

    I belive that the Blade3D engine supports video textures see the video here http://wiki.blade3d.com/page/Blade3D+Videos?t=anon (scroll down to video textures). So you could try that.

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 3/31/2008 12:42 PM In reply to

    Re: Video playeback in XNA?

    Thanks for the replay.I've two questions:

    The ZMan [MVP/Moderator]:

    There is no way to play video using XNA FX.

    You have to use the ScurvyMedia library or the XNADS library (both linked in the thread you replied to).


    Does it work fine?

    The ZMan [MVP/Moderator]:

    Or you must write your own which would load video files one frame at a time and then draw them to a texture.


    Does it increase the dimension of the file?

    Thanks.
    Sorry for bad english.
  • 3/31/2008 1:34 PM In reply to

    Re: Video playeback in XNA?

    I have run the demos with both and they seem to run fine.

    Scurvy is the only one that runs onthe xbox since XNADS uses DirectShow.

    As for file size increase - my guess is that Scurvy will increase it since it unpacks all the frames and does not use a codec on each texture. XNADS uses the original file so will not.

    If you do it yourself it will depend on how skilled you are at writing codecs in managed code - especially on the 360.

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 4/1/2008 2:31 PM In reply to

    Re: Video playeback in XNA?

    I've tested Scurvy before, and it does save out each frame as a raw bitmap. That’s why they are so big. I was planning my second edition of XNADSPlayer to completely remove the DS part at runtime, making it 360 compatible, only using DirectShow at compile time to extract the audio and video from a wide range of media files and convert them into a 360 compatible video format. Also, using this method, the playback would be a lot more efficient as the video would be decoded directly using pure C#, rather than relying on DirectShow to deliver the video content quickly.

    The only problem I have encountered is that there is basically no open source, free-to-use codec compatible with managed code, and I don’t know enough about video codecs (mostly because Google doesn’t provide any answers) to make my own.

    I’ve tried merely compressing the output bitmaps using firstly the standard .NET GZipStream, and then using an open source compressor to better effect. Both provided a decrease in size (the second compressor decreased the file by 60%), however the resulting file is still far too large to be feasible.

    If anyone has any suggestions about video codecs, your help would be appreciated, and then maybe we will finally get fully functional video playback on Xbox 360.

  • 4/11/2008 9:53 AM In reply to
    • (551)
    • premium membership
    • Posts 186

    Re: Video playeback in XNA?

    i've done this in my game engine only here's how I was able to get around the huge file size.

    The problem with video's is that you shouldn't compile them into a series of textures.  What I do is load the AVI, WMV, or MOV file using Managed Code.  I get the current frame as a bitmap structure (not using GDI Bitmap but rather a Bitmap Struct that has the X and Y for the color) and set a textures color info to that of the bitmap structure, rinse and repeat.  The movie stays the same size while you dynamically update a texture with new color every frame of the movie.  Works like a charm for us.  As for sound, that's a whole different story.
  • 4/11/2008 11:17 AM In reply to

    Re: Video playeback in XNA?

    What I do is load the AVI, WMV, or MOV file using Managed Code.

    So... You managed to decode video files such as AVI, MOV and WMV in managed c#?
    If so, how did you do that when both WMV and MOV are patented, so there are none/few open source implementations? Not to mention the sea of closed source video codecs present in all three formats.

  • 4/11/2008 11:24 AM In reply to

    Re: Video playeback in XNA?

    Managed wrapper around DirectShow (The MDX one or a 3rd party one) probably... for the reasons you outline its very hard to do this in 100% managed code.
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 4/11/2008 11:55 AM In reply to

    Re: Video playeback in XNA?

    The ZMan [MVP/Moderator]:
    Managed wrapper around DirectShow (The MDX one or a 3rd party one) probably... for the reasons you outline its very hard to do this in 100% managed code.

    and so therefore completely incompatible with Xbox 360. The only way I can see this being possible is to port libmpeg2 (http://libmpeg2.sourceforge.net/) from C/C++ to C#, and then use DirectShow (or other API) to convert the videos to mpeg2 format at compile time. From what I've seen, libmpeg2 is a very efficient video decoder, so should still run at a viable speed in managed c#.

    Anyone up for a coding challenge? It’s either that or wait for XNA GS 3/4/onwards for Microsoft to finally implement their own (probably also unmanaged) video player in the XNA Framework.

  • 4/11/2008 12:05 PM In reply to

    Re: Video playeback in XNA?

    That's the rub though Aeon ... "load the avi, wmv, or mov file using managed code" ... you can'd do that on the 360 (unless you've got some managed codecs we're not privvy to ;-) ).

    fyi to others in this thread ... look for a new build of scurvy media in about 2 to 3 weeks.  the release will definitely have 360 build of the assembly (the currently released version only has x86).  Also, there will be performance improvements as I've already got the disk streaming code multi-threaded locally. 

    Also, if I can figure it out, disk sizes should be drastically improved ... as much as 50% reduction.  However, I'm still working on that one.
    Joel Martinez - XNA MVP

    Blog: http://codecube.net

    XNA Unit Testing: Scurvy Test
  • 4/11/2008 1:36 PM In reply to

    Re: Video playeback in XNA?

    The problem is C# and managed environments just aren't well suited to software video decoding.  You'll end up using a whole CPU core (if not more) just decoding video.  Video encoding/decoding thrives on vector processing and fine-grained caching, both of which are very difficult (caching) to impossible (vector code) to implement on any platform using C#.


    Have you actually looked at libmpeg2?  The decoding routines are all highly optimized for MMX/Altivec using compiler intrinsics and even pure assembly.
    Microsoft DirectX/XNA MVP
  • 4/23/2008 9:17 AM In reply to

    Re: Video playeback in XNA?

    Did you have any luck with this?

    This is something I am trying to do but am just starting out so am still unsure what you can do with the xbox.

  • 4/23/2008 11:04 AM In reply to

    Re: Video playeback in XNA?

    If you read through the whole thread that you replied to you will see that it explains all of your current options very well. There is only one video playback solution that works on the 360. On windows you can use any video playback library you choose.
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 4/23/2008 12:29 PM In reply to

    Re: Video playeback in XNA?

    Personally, I think the quickest and easiest way to get video (and audio) playback on Xbox 360 AND PC using the same class/library, is simply to nag microsoft until they put a video player into thier next version of the XNA Framework Stick out tongue
  • 4/23/2008 1:03 PM In reply to

    Re: Video playeback in XNA?

    Well people have been nagging since December 2006 when GSE 1.0 came out and so far we have seen nothing.... 16 months isn't my idea of 'quick and easy'.
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 4/27/2008 10:35 PM In reply to

    Re: Video playeback in XNA?

    Finally put out a new build of Scurvy Media:
    http://codecube.net/?p=40

    Would love to hear some feedback/bug reports on this :-) of course, to avoid hijacking this thread, please submit through the codeplex forums/contact system.

    Thanks! :-D
    Joel Martinez - XNA MVP

    Blog: http://codecube.net

    XNA Unit Testing: Scurvy Test
Page 1 of 2 (36 items) 1 2 Next > Previous Next