XNA Game, Full Screen Animation / Video Playback - c#

I have an XNA game (its a slot machine).
I have some really cool animations my artist made for me that are more or less 1600x1000 and over 50 frames.
For all of the animations so far I have been using sprite sheets. (Where all the frames are in one image file and when its rendered it chooses what part of the image to show).
The problem is that you can only load an image of a certain size. 2kx2k or 4kx4k depending on your videocard. Obviously putting each frame into one file is out of the question for this large animation.
Can you just load each image individually and display them in order? (That is what I used to do for the smaller animations anyway before I found out that isn't how you were supposed to do it)
My Questions:
What if any is a good way to play these large animations?
Is there a benefit to having a spritesheet instead of loading the frames in individually as Texture2D's?
Is there a (free) way to play fullscreen videos in XNA?

Apparently, XNA 3.1 "now supports the ability to play back video that can be used for such purposes as opening splash and logo scenes, cut scenes, or in-game video displays." That is what you'll want to use - the sizes you're talking about are far too big for conventional animation techniques. Some sample code is here.

Related

Is it possible to crop videos and save them in Unity?

I'll explain my situation : I have a UI image, of fixed size, and if clicked it shows a video (like Live Photos). The video could be of every possible resolution and with an AspectRatioFitter and a mask I make the video fill the entire image. In this way only a portion of the video (that match the image resolution) is visible, the rest of it is "cropped", hides. I was wondering if it's possible to actually save to the disk only the visible section of the video, cropping the parts not visible. In the end the goal would be to have the image and the video of the same resolution. Is it possible to do this in Unity?
You can use C# to get video files on your system and crop them at your preferred times and then save them to your preferred folder. I have linked a google search for you that should help you find what you're looking for, try using the videos if you need something visual. Crop a video using C#

How to make MediaElement work as good as AxWindowsMediaPlayer?

I need a very simple video player in my C# app. It only has to loop a video from file and nothing more. Since I'm developing a WPF application, I've tried to use System.Windows.Controls.MediaElement. It has all the functions I need, but works quite poor: I've played some full HD videos on it, and it's always lagging and spiking.
To make sure, it's not my app problem, I've created 2 test applications. The first in a WinForms borderless 1920x1080 window with only AxWMPLib.AxWindowsMediaPlayer control. And the second in a borderless WPF window of the same size with System.Windows.Controls.MediaElement.
Then I run 2 videos on both of players. Here are their specs:
1: 1920x1080, 12000kb/s, 25 FPS, wmv
2: 1920x1080, 5730kb/s, 25 FPS, mp4
On AxWindowsMediaPlayer everything looks fine. But MediaElement seems to drop some frames and ignore vertical sync (it's possible to see parts of one frame on another during fast scene changes). So, it's completely unsuitable and shouldn't be like that, but I've found nothing about the problem in Microsoft official docs (they only suggest to use MediaElement instead of AxWindowsMediaPlayer in WPF apps). Is it possible to make it work more smoothly or using an additional WinForms Form with AxWindowsMediaPlayer is the only solution?
It was written over five years ago (look up James Dailey messages in the thread), there were possibly some improvements but overall I suppose the statements are still in good standing. I will pick up some relevant quotes:
As you know the WPF environment is constructed from the ground up to offer developers a very rich “graphics first” environment. The MediaElement in particular was designed to allow you to mix video with various other UI components seamlessly. This solution will give you the flicker free, “draw over video” solution that you are looking for. The best part is you can do all of this in C#. The bad part of this solution is that the MediaElement is not designed for displaying time sensitive media content. In other words, the MediaElement is notorious for dropping and delaying the display of video frames. There are ways to minimize this such as using SD rather than HD content, use a video accelerated codec, etc.
also:
Unfortunately you can’t really tell the WPF MediaElement to never drop frames. The term we use for this class of issues is “disparate clocks”. In this case WPF is updating the screen at a certain rate (clock 1). The MediaElement (based on WMP) is cranking out video frames at a slightly different rate (clock 2). Given the underlying technologies there is currently no way to synchronize the two clocks and force them to “tick” at the same rate. Since the display will only be updated according to the WPF clock, multiple frames of video may be sent from the MediaElement to WPF between clock ticks. Because of this the MediaElement may appear to drop frames. This is a very common problem in multimedia development and there is no simple solution.
Windows Media Player uses Media Foundation and DirectShow APIs which power media playback with high quality video experience.

Best way to render images as a video clip in a mobile device

I have tried to approach this problem several ways.
I have a web application that will load a sprite (which is a large jpeg that 'holds' 100 frames. Using the offset of div properties I am able to 'move' the image along so it looks like a movie clip.
This works well.
I need to produce the same on mobile devices.
I have to support Windows Mobile 6.5.
I was using jQuery/ajax to move the sprite image along to stop any flickering of the image within the browser.
Windows mobile 6.5 does not support this.
So, i decided to do a native app using C# Framework 2.0.
I thought about converting the sprite to a mp4 file and playing within a web browser control. but IE on the device will not support html5.
I have been told there is a CAB file from adobe so that I can play flash videos on the IE. But, apart from using ffmpeg to convert these images to a flv there is not much control as to adding menu like pause,stop,play etc when playing the flv file. I have not started any of this by the way i assume that would be the case.
So.. I thought if I download the sprite to the device i could use the graphics object of a picture box and render the rectangle of interest from large sprite to picture box.
I could not download the Sprite and save it to an image though. I get 'out of memory exception'.
I used the OpenNetCF.Drawing as it is supposed to support large files. I still get the error message. I have reduced the size of the image and it will work on about 20 frames.
I would then have to 'stack' these images containing 20 frames and load them up when necessary.
I am beginning to wonder now whether i am doing the right thing?
Is there a different way of trying to achieve what i am trying to achieve that is quicker and more efficient as I have run out of ideas.
If I am OK doing it this way then what is the best way to render images in a picturebox like a video. Memory efficiency says load the image from the file on the device when needed and dispose of it but that would cause 'flickering'. What IS the best way to handle multitude of images on a device?
i have plenty of code I can upload but I was worried the question would look 'messy' as I have tried so many things. I will of course edit/upload the code as required.
Thanks.

is there a way to make a 3D game in winforms or WPF in C#?

I'm thinking about making a 3D point and click game, is it possible to make one in winforms or WPF? I don't need any physics or anything all I need is to make the application render 3D objects. I know that I can use XNA but if I do then I will have to relearn almost everything again. My third approach would be to make the scenes in a 3D game engine and then print the screen and then load it as a image. Any suggestion would be appreciated.
There's a big difference between a 3D game, and just letting players interact with a rendered image.
Your approach of loading a pre-rendered image is possible to do in both Winforms and WPF. You would just need to capture click events on the image and check the location against your list of active areas. Then just handle what needed to be done, ie: move to the next area, activate item, etc.
Edit from comment:
It's not so much which is friendlier. You can host an XNA viewport in Winforms/WPF. It's more about how you want your game to work. If you never have moving 3D scenes, XNA is overkill, and images will work just fine.
If you want dynamic scenes, you'll need to be able to render them on the fly. Then, XNA makes more sense. It is a lot more work though compared to just displaying images.
If you just want to show pre-rendered 3d images in your game, why not create them using a real 3d graphics tool, such as 3D Studio Max or Maya (or a free one, such as Blender)? It sounds like there's no need for actually rendering the 3d scenes in a game engine at all.

How does Windows Media Player deal with monitor refresh rates?

I'm writing an animation app in C#/WinForms (see this question). Basically, the animation in my application is smooth but shows tearing effects; when I take the same animation and render it to an AVI file and play it with Windows Media Player, the animation shows no tearing effects at all. I know WMP is not changing the frame rate because the animation is synchronized with music.
I assume WMP uses DirectX or some other technology that is aware of the monitor's refresh rate and scanline position etc., but I always assumed that programming to the refresh rate would constrain the frame rate. Obviously this isn't the case with WMP.
Does anyone know anything about how WMP (or other video players) renders video internally? I've searched but I can't seem to find any details about this.
It's been a while since I did any DirectX programming, so this may be out of date.
From what I remember, with DirectX you could set up a flipping chain of buffers, usually three buffers: the buffer being displayed, the buffer to be displayed and the buffer being written to. On an update, DirectX will wait for a V-sync before updating the displayed buffer. Now, this will cause a discrepency between the displayed image and the image that should be displayed, but this will be, at most, one refresh, about 1/60th of a second, so you're unlikely to notice.
Some ASCII art to show what I mean:
|-|-|-|-|-|-|-|-|-|-|-|-|-|-| - screen refresh
|----|----|----|----|----|--- - animation
|-----|---|-----|---|-----|-- - displayed
Are you painting each frame of your animation to a memory bitmap first, and then blitting the bitmap to your window? If not, this might be the solution for you.
(this is, of course, in addition to double-buffering)

Categories

Resources