Which one to use: DirectX? Windows Media Player? GNU? Others? - c#

I want to create a windows Forms program where I play an AVI file.
I want to be able to play it in full speed, to pause, to get the total number of frames, and to show a given frame (seek).
The AVI file has metadata for the file AND metadata per frame.
I want to do this in a windows Forms application in C#, or if it is really necessary using C++.
Internet search shows me a lot of possibilities to use: DirectX, DirectShow, Windows Media Player, Microsoft DirectX9, GNU code, and several other methods.
Alas I haven't seen one that supports all that I want, especially the metadata per frame is not used often.
It seems that several of these methods are obsolete, for instance to be able to use Microsoft DirectX I need to add "useLegacyV2RuntimeActivationPolicy".
So anyone who knows what method is the latest and greatest method to use in windows programming? Which method allows me to show metadate-per-frame?

Related

How to forward output of a directshow app(C++) to a C# app?

I am making a C# app to capture graphic from an avermedia pcie capture card.
But it seems that there are no out of box tools to do so.
So I made a C++ directshow app to do the capture, which is a console app and opens a capture window when running.
How can I redirect the output to a C# app? for example, to a CaptureElement?
So you want to have XAML CaptureElement connected to AverMedia PCIe capture card. This sounds like a well-understood challenge overall, however every other piece of technology you mentioned is eventually a bad choice: DirectShow, multiple apps with piping, redirection and fitting of cutsom code to XAML CaptureElement control.
Microsoft has intentionally been limited ways you can integrate different APIs and so there are not so many ways to get everything together.
Let us go over the supposed integration path. The capture card is supposed to be shipped with a compatible driver:
Video capture devices are supported through the UVC class driver and must be compatible with UVC 1.1
When this is the case, such devices are visible to Media Foundation API handling video capture among tasks. XAML CaptureElement would be able to see a video capture device through this API and this way everything is supposed to work without need to fit anything from your end.
If this is not happening, it suggests you are dealing with an unsupported device coming without suitable or compatible driver.
Previous media API in Windows was DirectShow but its days are gone. It remains perfectly working as a legacy framework, a lot of applications out there are still relying on it. Specifically it will not integrate with new technology like XAML and UWP. More to that, even Media Foundation itself, the current media API, in its public offering is lagging behind when it comes to fitting with most recent technology. Having said that it is a good idea to stay well clear of DirectShow here if this is at all possible.
I see no need for cross-process design with video travelling between process through piping. There is no good reason for such design and even though this can work efficiently (Windows itself proves it can work great in terms of performance by having so called Frame Server service in it), this is not to be built on piping. In your case it is unlikely to be have to be built on multiple processes either. Instead you can develop a native code DLL project that takes care of video acquisition and connects to managed code via suitable glue layer: C++/CLI, COM, C++/WinRT and such.
Then next thing is fitting to XAML CaptureElement. The control is designed to work with Windows.Media.Capture.MediaCapture class that talks to hardware and you don't have suitable hardware as you plan to implement your own acquisition layer. Long story short you are not supposed to forward external data to CaptureElement and you would have hard time doing this. Your best strategy is to upload externally obtained data to Windows.Graphics.Imaging.SoftwareBitmap or alike and take involved performance impact as acceptable. That is, you will be dealing with video frames as images.
An alternative way is to upload acquired video frames into Direct 3D 11 textures and it would open you a more performant way of integration with video related controls, such as Windows.UI.Xaml.Controls.SwapChainPanel however it would also require that you put much more development effort in there.

c# mixing two audio files in windows phone 8.1 silverlight project

My goal is to mix 2 audio files that is one voice and one background music. For mixing I am using NAudio.
The problem is I am getting following exception while reading mp3 file using NAudio's Mp3FileReader.
DllImport cannot be used on user-defined methods
I am using NAudio in Windows Phone 8.1 Silverlight app project. I am not sure if NAudio is useable on WP Silverlight app if its useable then please help by providing a code example or suggest any other library or custom implementation to mix 2 audio files.
No, I'm afraid NAudio is not usable on Silverlight, as it makes lots of calls into Windows APIs which you can't do in Silverlight. You can take a look at the NAudio NLayer project which offers fully managed MP3 decoding. You could use that in conjunction with some of the more generic helper classes in NAudio like the MixingSampleProvider to perform the mixing you require. Of course the next issue would be what you want to do with that mixed audio. Silverlight does have a way of streaming user generated audio using the MediaElement but NAudio does not provide support for this directly.
[DllImport] requires a substantial chunk of code in the CLR, nothing very subtle about the pinvoke marshaller. That's a problem on a phone, it runs a special version of the CLR named .NETCore. Probably better known today as the codebase that spun-off the CoreCLR open source project. Keeping it small required unsubtle choices, pinvoke fell on the floor.
So no, you'll have no use at all for NAudio. You'll have to dip into the built-in support for audio. The relevant oversight MSDN page is this one. This blog post is relevant.
As you can tell, XAudio2 is your ticket with direct support for mixing. There is a learning curve of course, the language is probably the first obstacle given the question tags. Get started with this sample to get the basics.
Maybe you should consider taking the step to upgrade from WP8.1 Silverlight (WPS) project to WP8.1 (WinRT) one so that you have better access to audio APIs...
...or directly to a UWP/Win10 app (if you don't plan to release immediately to phones). If you choose that path, you could try maybe a free preview tool that converts WPS to UWP, just released from Microsoft and Mobilize.NET - https://blogs.windows.com/buildingapps/2015/09/17/initial-preview-of-silverlight-bridge-to-uwp/

How can I show an MP4 video inside a Winforms application without the need for installing missing codecs?

We're currenty building a little company presentation application for USB sticks that is used to display PDF files regardless of any PDF reader installed on the system. That works quite well, so we now also want to show videos directly inside the application. As we cannot ensure that the customers system is able to play the video file, I'd like to include everything that is neccessary to play the video regardless of the system configuration.
Before I reinvent the wheel - is there a preferred way to do so? Would another video format offer more possibilities? The target OS is supposed to be Windows XP up to Windows 8 and .NET 2.0. Is there any framework/assembly that I could use to become independent of any prerequisites on the target system? Thanks for your recommendations and thoughts on this!
Playing videos requires software to transform the video data into moving images. Unless you want to take on the mammoth task of writing your own MP4 decoder, you'll have to rely on what the user has installed.
Wikipedia lists Windows Media Player versions here. Version 12 is the only one to support MP4 out-of-the-box. That means your Windows XP and Vista users are going to need a third-party codec.

2 videos with DirectShow in c#

I would like to have 2 video windows playing a (same file for now) video. As I'm still new to c# and DirectShow I'm having problems with this and haven't found any working examples for multi-video solutions. I can get it to work for 1 window from samples, and would like to know what else is required to get the 2nd window working. Do I need to create a separate filter for the 2nd one aswell, or just fiddling around with the handles is enough?
What problems are you facing for multi-video rendering ?
As far as I know, you need to create one graph per video stream you want to have rendered, i.e. one Source/(Transform)/Render chain per stream. I don't think using a single render filter and playing with the windows handles is going to work (but I may be mistaken).
If you need to play the same video file in two different windows, just connect a Smart Tee filter after your source filter (or after your decompression filters), and connect a render filter to each of the Smart Tee's output pins.
If you want an easy method to test Directshow graphs, use GraphEdit (available in the DirectX SDK and in many other places on the Internet).

C# Video Playback

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).

Categories

Resources