Hi,
I'm currently writing a library (for XNA/DirectX) for
animation/soundless video playback, and I have a few design questions
for the pros out there if you don't mind answering them :
- I'm having my animation class inherit from game component, and update the frame depending on game time in the overriden Update method, and render it in the overidden Draw method, but even when I preload my textures to render, playback is choppy. Not sure exactly why, but I notice this only when I have significant number of frames (I noticed it with 100 frames, but *not* with 10/15). This problem may be linked and solved by the 2nd point, so please read on.
- When I preload all the textures for the frames in the animation (and the no. of frames is small, as explained in point 1), the animation plays back perfectly. Now I've also added the capability for future frame textures to be loaded on-the-fly asynchronously (using delegates) whilst the animation is playing, in order to a) I can't preload all the textures for a big video since they can have 1000s of frames... ba) To minimize loading time. From this I've discovered that the problem is caused by the slow loading time of frame textures in comparison to the playback rate (typically about 300ms compared to 30ms). Clearly the playback will overtake the on-the-fly preloading rather quickly, causing playback to wait up, making it appear choppy. So all I want to do it somehow quicken the preloading time for textures. This is my current code:
' Create new frame texture and store it in the array.
Dim creationParams As New TextureCreationParameters( _
0, 0, 0, 0, SurfaceFormat.Unknown, ResourceUsage.None, ResourcePool.Managed, _
Nothing, FilterOptions.None, FilterOptions.None)
_frameTextures(frame) = Texture2D.FromFile(graphicsDevice, _dataStream, byteLength, creationParams)
As you can see I'm loading from a stream (FileStream in my tests).
I've fiddled around with the parameters quite a bit but this code makes
it the quickest - still not quick enough .
I hope that some of you may have ideas on how video rendering is done by other programs, or more likely just some new ideas. Thanks in advance for any help!
Alex
P.S. If there are any premade animation playback libraries for XNA already please do let me know, but I've searched and I doubt it anyway since XNA is still very young.