Smooth Video Rendering in C# - c#

I am trying to find a way to render video in WPF with lower CPU usage than MediaElement.
The goal is smooth and low CPU video playback as much as Direct3D/DirectDraw video rendering in C++ programming.
I tried Direct2D(with WindowsAPICodePack) to render video, and the result is CPU usage is pretty low, but the problem is that I have no way to render video smoothly since there's no accurate timer to update video at exact time like DirectX in C++.
Maybe I need to go back to C++ world to use Direct3D natively and hosting C++ with DirectX window in C# WPF window. Even though I don't know what will happen with that, it may worth to try, I guess.
If you guys have any advise, please let me know.

You could try writing a small XNA app to render the video and embed that into your winform

Related

Why AxShockwaveFlash take so much memory or process while transitions?

I have developed an application with 2 AxShockwaveFlash and textBlock.In AxShockwaveFlash there is 2 different flash files with their own animation and in the bottom of the form a textblock scroll some text(Ticker).While loading of flash my ticker get stuck and when the flash has some transition then also my ticker get stuck.
I am not getting any clue why my application responds slow while playing or transitioning a flash file.How can I track exactly the problem is?
The simple answer to : Why AxShockwaveFlash take so much memory or process while transitions? is simply because that Someone out there doesn't know how to code a transition without killing the CPU.
To be fair your question didnt give enough helpful info (which led to the rambling answer below). Many people will call something "a Flash animation" when that something is anything from simple text fading in/out.. to a full blown 3D engine game demo to.. some intensive realtime video pixel effects. Just happens to be done in Flash so it's a Flash animation, right?.
A) If you can improve the C# code... Look into improving your WPF/Textblock code
Because if your Textblock is getting slowed down by the additional loading of some multimedia elements (photo, sound, Flash etc) then you simply have to improve that Textblock code.
Is this slow WPF TextBlock performance expected?
http://social.msdn.microsoft.com/Forums/vstudio/en-US/378a1945-8f72-4641-a0b8-e8ba5a31eced/is-the-wpf-textbox-really-that-slow?forum=wpf
http://www.codeguru.com/csharp/.net/net_wpf/article.php/c18025/10-Ways-to-Improve-the-Performance-of-Your-WPF-Application.htm
B) If you can improve the AS3 code... Look for any CPU intense pixel activity. Use bitmapData.lock and .unlock if the transitions code uses bitmapData.
If the Flash is externally created by someone else then perhaps there is some ineffecient coding? Check CPU usage by loading just the SWF's (no Textblock). Also consider the nature of your Flash animations for example I've never known SWF's of advert banners & pop-up ads to NOT add CPU usage. I dont know what those people do with their "simple" adverts. Essentially if someone else made it, find an alternative. Else if you have the source code, improve upon the transitions function first amongst others.

How to control HD video play position and speed in XNA?

I am developing a game for Windows in C# using Visual Studio 2010 and XNA 4.0. I would like to be able to set and change the play position of an HD video and also play the video in reverse, depending on user input.
I am having trouble finding where to start. XNA's videoPlayer class does not provide these type of functions. I've read that XNA DirectShow is now out of date and slow when using HD video.
I don't quite understand how I would be able to use or implement tools such as ffmpeg with my project. It seems some people have had similar questions and posted solutions but without much detail. These are below.
interop out to talk to the core DX functionality.
write a managed c++ wrapper to interop ffmpeg.
write an mpeg decoder.
I am not sure what would be best and where to begin.
Thanks!
The VideoPlayer class has a "PlayPosition" property, which you should be able to play with.
Otherwise (and I don't know how big your video file is nor how long) try an image sequence and animate the current image sequence and control that with user input. Of course working with image sequences would make audio reversal (if there is audio) etc very complicated.
Last but not least, you can see if you can figure anything out from this mpeg decoder here:
https://www.box.com/shared/ojzfv0qzfx
Something else that might help with mpeg decoding:
http://chrisa.wordpress.com/2007/11/21/decoding-mpeg2-information/

Dynamically increasing/decreasing speed of a video in a windows forms application

I'm building a Windows Forms application in VS 2010 that smoothly increases or decreases the speed of a video playing back based on the speed of the user input.
I've tried several avenues..
1.) Using the AudioVideoPlayback DirectX class - I set the speed of the video, by setting the current position of the video, based on a timer.. and increased or decreased that value based on user input. While this worked on my PC, it lags a lot on our lower end target PC's. Can anyone think of a more efficient way to increase/decrease the speed of playback using this class?
2.) I've tried the Windows Media Player ActiveX control, and tried setting the rate/position dynamically, but this is extremely jumpy and laggy even on my development PC
3.) I've tried the Apple QuickTime Control 2.0 COM Component that comes with VS 2010, and it's also very laggy.
4.) I'm trying to figure out how to set the speed on the Shockwave Flash Object control, but haven't found that out yet
Can anyone suggest other avenues to explore? I just need to be able to increase/decrease the speed of video playback smoothly based on user input without lag. I don't care what format the video needs to be in, all videos can be converted to the required format.
Any help/ideas will be appreciated.
Thanks
The ultimate way is to decode the Bitmaps from videos, and handle the frames yourself.
Try the CaptureNET example from DirectShow.NET. It allows you to capture bitmaps from each frame. After that, write your own playback control to handle the refresh rate.
After trying many different formats/libraries and components I found the VLC Media Player ActiveX control to be the most efficient method to slow down/speed up video without any noticeable lag.

DirectShow EVR resizing window problem

So I've been looking into the world of media playback for windows and I've started making a C# Media Player using DirectShow. I started off using the VRM-7 windowed video renderer and it was brilliant except it had a couple of small problems (multi monitors, fullscreen). But after some research I found that it's deprecated and I should be using VRM9.
So I changed it to use VRM9 windowless then found out that was an old post rofl >_< so finally I'm using Vista/Win7 (or XP .net 3) Enhanced Video Renderer (EVR) which is apparently the most up to date Microsoft video renderer and has all the flashy performance/quality things added to it. (tbh I haven't noticed any difference but maybe I need a blue-ray or HQ video to notice it).
With using EVR everything is working fine except resizing the video. Its really laggy/choppy/teary and probably something to do with its frame queueing mechanism.
To demonstrate my problem
open up windows media player classic.
View -> Options -> Playback -> output
Chose the "EVR" DirectShow Video renderer
Now restart wmp class and play a video, while it's playing click and drag a corner to resize it. You'll notice its horribly laggy. This is the exact same problem i am having.
But if you chose "EVR Custom Pres. **" or EVR Sync **" resizing works beautifully! So i tried googling around for anything about EVR resizing issues and how to fix it but i couldn't believe how little i could find. I'm guessing "Custom Pres." stands for "Custom Presenter" which sounds like they made their own.
Also you'll notice on the right hand size when you swap between EVR and the other EVR's the Resizer drop down on the right greys out.
So basically I wan't to know how I can fix this retarded resizing problem and is there any decent documentation out there? There is a fair bit for VMR7/9 but not much for EVR. I downloaded the DirectX SDK which apparently has samples but it was a waste of 500mb of bandwidth as it had nothing relevant.
Perhaps there is some way to force it not queueing up frames if that is the problem?
If you want code say the word and I'll paste some in. But it's really quite simple and nothing much happens, i'm convinced it's a problem with the EVR renderer.
EDIT: Oh and one other thing, what does VLC use? If you go into vlc options and change the renderer to anything but default, they all suck. So is it using VMR7? Or its own?
I need to write my own Custom Presenter, which from the looks of http://msdn.microsoft.com/en-us/library/bb530107(VS.85).aspx is a relatively big task.
Guess i'll look at the sample and try to go from there

C#: Creating a graphical screensaver

I am thinking about creating a screen saver. I have the whole thing, its graphics and the back-end kind of ready in my head. But I am not quite sure how to get the graphics out in code.
What I would like is a slide show of images with a bit of movement (kind of like the slide show in media center) and some floating text and shapes on top. The shapes somehow translucent.
I currently have a very simple static slideshow made in WinForms. Just a simple application that goes fullscreen and displays some images and pretends to fade them in and out in a hackish kind of way. But it is not very well made, and the performance is not very good. For example to prevent lag, I fade in a black square on top of the image, instead of fading in the actual image. Silly perhaps, but it kind of worked :p
Anyways, I would like to do a better job. But not sure where to start. Is WPF a good solution for this? Or should I look into DirectX or OpenGL? Is this something that could be handled well with XNA, or is that too game spesific?
WPF is not a bad idea. It takes advantage of DirectX and hardware acceleration for its animations and effects.
You will get better performance if you write this kind of stuff natively (against directx or opengl), but the cost of writing it will be much higher. It's quite possible you will not need that edge anyway.
Have a look at hanselman's baby smash (which is a full screen wpf app with animations) to get a grasp of what you can do with wpf.
Note: I did write a slide show kind of thingy in WPF way back, the key to getting this to work smoothly is loading up the images in a background thread and freezing it.
I guess XNA works well. There's a sample screensaver in C# Express, by the way.
Actually XNA works pretty well. For example: this is an (advanced) example of what can be made with XNA. The community is quite helpful and XNA has great potential.
A few weeks ago I wrote a two-part article describing how to create a Windows screen saver with GDI+. I am not displaying a slide show in my screen saver, but instead I am randomly drawing shapes. I did however explain the fundamentals of creating a screen saver for Windows which should be of some help if you have never created a screen saver before.
Create a Screen Saver Using C# – Part 1
Create a Screen Saver Using C# – Part 2
If you want to go with just GDI and GDI+, I wrote some info here about how to speed them up when rendering images and drawing them to screen. There is also fully functional screen saver source code at the above link (which I wrote myself after digging for some of the more obscure screen saver details), in case that helps.
Recently I finished with my first WPF (I wanted to see, how it can be done with WPF) screen-saver. You can check-it out on YouTube. Try to see HD-version.
Though I never tried XNA, I'm really pleased with WPF so far. Easy and flexible. But I guess you probably wouldn't get an XNA-performance (or am I wrong here?).
You can google for GDI+ or WPF ScreenSaver-templates to start with.

Categories