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.
Related
I am developing an application for Windows 10 phone on Universal Windows Platform. I need to get a frame from the devices camera and do some processing; this is supposed to happen in the background, the user is not supposed to see the camera feed anywhere in the UI.
There are two classes that handle the most common use cases, namely CameraCaptureUI and MediaCapture. The MediaCapture class allows to grab the so called preview frame but the whole workflow revolves around binding a MediaCapture instance to a UI control (ie CaptureElement) and if I do not do it then I am unable to get the preview frames. This makes the MediaCapture class unsuitable for my case unless there is another way to use it that I am not aware of.
An answer to a related question How to get preview buffer of MediaCapture - Universal app suggests usage of Lumia Imaging SDK but it is targeted at Windows 8 family and the classes and methods used there are now deprecated in the current Lumia Imaging SDK for Windows 10.
Additionaly, the aforementioned answer brings up custom media sinks but I am unsure if that can help me in my scenario and if yes, then where should I start.
To sum up, how do I acquire frames from a camera device that can be used for further processing in a Windows 10 universal app?
There are multiple options available to you for this. CameraCaptureUI is not one of them.
Hide the CaptureElement
Opacity = 0
Visibility.Collapsed
Create it in code and don't add it to your layout
etc.
StartPreviewToCustomSink (https://msdn.microsoft.com/en-us/library/windows/apps/hh700850.aspx) although I've never done this. This link might also help.
Once you've done that, you can take photos or just get preview frames. The CameraStarterKit will teach you the former, CameraGetPreviewFrame will teach you the latter.
How about you put a CaptureElement in UI, but hide it with overlay or set width / height to 1 ? Its kind of a hack but it will provide you the frame.
I think a lot of people used application "Fraps" for recording video from game. I use it for displaying FPS (frames per second) in the games. Fraps can show digits at the corner of screen when game runs.
I want to display core temperature of processor. The temperature I will find, but I need to khow, how can I display it in the game? (I need it for testing core temperatures in the game, because stress tests of Everest/AIDA64 doesn't much load the system).
Want to use C# (but can listen to all solutions, C++, Java)
Example games: Dirt2, Call of Duty 5 (DirectX)
P.S. This post was similar...
c# text/winForm overlay video games like xfire,PIX,steam,fraps etc
What you want to do is a bit more complex than you might think. There are different sources on the web about this, some might be a bit outdated. A good search Term is "Hook direct 3d", there are also other threads on stackoverflow about this topic. A good thread is also this.
One advice: You are changing the runtime code of the game, which can be detected by anti cheat mechanism and can cause banning if the game is a multiplayer game. It is even possible that widely known applications like fraps are on some sort of whitelist against these checks, but i'm not sure about that.
An alternative to what you want could be to make your form always stay on top (form.TopMost = true;). Then you can set the transparency color the same color as your form (by default it would be form.TransparencyKey = System.Drawing.SystemColors.Control;). After that you can remove the border of your form (form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;).
Be careful not to use the transparency color anywhere else (it'll make part of images transparent if it contains this color).
Make sure to have a way of closing the form. (and moving it if needed).
I want to create a simple video renderer to play around, and do stuff like creating what would be a mobile OS just for fun. My father told me that in the very first computers, you would edit a specific memory address and the screen would update. I would like to simulate this inside a window in Windows. Is there any way I can do this with C#?
This used to be done because you could get direct access to the video buffer. This is typically not available with today's systems, as the video memory is managed by the video driver and OS. Further, there really isn't a 1:1 mapping of video memory buffer and what is displayed anymore. With so much memory available, it became possible to have multiple buffers and switch between them. The currently displayed buffer is called the "front buffer" and other, non-displayed buffers are called "back buffers" (for more, see https://en.wikipedia.org/wiki/Multiple_buffering). We typically write to back buffers and then have the video system update the front buffer for us. This provides smooth updates, as the video driver synchronizes the update with the scan rate of the monitor.
To write to back buffers using C#, my favorite technique is to use the WPF WritableBitmap. I've also used the System.Drawing.Bitmap to update the screen by writing pixels to it via LockBits.
It's a full featured topic that's outside the scope (it won't fit, not that i won't ramble about it for hours :-) of this answer..but this should get you started with drawing in C#
http://www.geekpedia.com/tutorial50_Drawing-with-Csharp.html
Things have come a bit from the old days of direct memory manipulation..although everything is still tied to pixels.
Edit: Oh, and if you run into flickering problems and get stuck, drop me a line and i'll send you a DoubleBuffered panel to paint with.
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.
I'm looking at trying to create a simple 'slider puzzle' game. You've seen the ones, you have an image and you shuffle the tiles.
However, I want to make one that will play back videos instead. What I'm trying to determine is whether it's possible to playback a video in C# and render the video on different controls (probably buttons, or panels). I've spotted the Microsoft.DirectX.AudioVideoPlayback classes but haven't found much documentation on them yet.
So to throw it up in the air, is this going to be possible to do without too much difficulty? Are there any useful (free) libraries that might help me along?
Have a look at DirectShowNet that wraps the DirectShow API, in the samples page there is a sample called PlayWnd the shows how to play a video file.
Depending upon how large and how long your video sources are, you could accomplish this very simply by first converting your videos to animated GIFs. A .Net PictureBox control will display and animate a GIF automatically, and you could easily use PictureBoxes for your tiles.
One big advantage of this approach is that (thanks to Mono) your application could work unaltered on Windows, Mac and the iPhone (also Linux and a couple others).