Full Motion Video in XNA

About two weeks ago, the graphic artist I have working with me on my game said, that he had planned a whole lot of full motion video clips. Initially I had to disapoint him. As you probably know, there is no easy way of showing FMV on the XBox 360 from within the XNA framework.

So… since XNA does not have a video loader/decoder of it’s own, and we can not use Windows to load the video, we have to roll our own decoder.

Instead of saving all the frames from an AVI stream as single images, and then import them one at a time into XNA during runtime, why not use a “simple” compression format? Well.. some say that C# is simply not fast enough. I say it depends on optimization and available CPU resources (and the XBox 360 should have more than enough power)

So to prove my point, I have implemented a very simple MPEG I video decompressor in 100% managed code. (Video only)

What you see below, is a web-friendly version of a video captured with fraps. The video being decoded is a small clip from the Blender movie “Elephants Dream”, running on XNA 3.0.

Movie information:
Original dimensions: 720 x 576
Rescaled dimensions: 512 * 256 (power of two texture.. scaled using Sony Vega studio 9)
Original framerate: 25 FPS
Frames: 3384 in clip
Approx bitrate: 1660 kbps
Movie disk size: 29208028 bytes (~29 MB)
Decoding speed in C#: 65+ FPS, single threaded on an Intel 2.65 GHz Core 2 Duo

You will probably notice a frame rate drop when watching the movie. This has nothing to do with the decoder or XNA, but just the fact that my hard-drive is struggling to save the movie. Btw, the original fraps movies dimensions are 1024*768, so the movie has been scaled a few times when you watch this. If anyone wants it, I can save a few decoded frames from the movie, so you can evaluate the quality.

Now running on the XBox 360 is a different story. Here we get around 25/33 frames per second, if we set the decoding thread priority to high. So I will have to find a way to multithread the decoding procedure. However, this is not going to be easy!

If you want to know more about video compression, I would suggest you have a look at this page:  Video Compression

Leave a Reply

You must be logged in to post a comment.