Playing video in a .NET application - c#

Lately, I've been trying to setup a media center PC. I've played around with all the common media center applications like XBMC, Plex, Boxee, and WMC. But all of them have one issue or another. So I was thinking about writing my own application from scratch.
My problem is I have no experience with developing software that plays media such as videos or music. I'm also not interested in spending a huge amount of time trying to figure this out, considering all the different file formats and codecs out there. I'm really more interested in developing the database and library interface for my application and reusing someone else's control or code for actually playing the media.
One option I was thinking was to just control an existing media player externally. So for example you may browse for a video to play in my application, and then when you hit play it would fire up VideoLAN or some other popular video player.
However, I was wondering if there was an easy way to play video inside a .NET application. I'm looking for something that is capable of playing a wide variety of formats such as MKV files, and DVD ISOs. I'm more experience with WinForms, but was also thinking about using this project as an opportunity to learn WPF.

i've spent many years looking at playing video under wpf.
The short answer
There is no easy way to guarantee to be able to play a variety of formats under wpf ( mkv,dvd etc etc ) or under windows for that matter.
the long answer
If you are looking just to run this at home and not release it, install all the codecs you need and most of the formats will run via mediaelement in wpf.
Getting all the codecs to cooperate can sometimes be frustrating.
Now moving into slightly harder territory.
if you want to play DVD then you need to replace mediaelement with wpfmediakit
http://wpfmediakit.codeplex.com/
wpfmediakit gives a base library to get access to the low level directshow functionality.
There is already a code base for playing DVDs based on wpfmediakit.
Now moving onto the very hard territory.
if you want to distribute your application and have users be able to "just watch" most/all media formats means you need to be able to completely control their codecs, which generally means distributing the codecs with your package and building the directshow filter graph in code rather than let windows build it.

The easiest way is to use the existing .Net hooks to Microsoft's standard MediaPlayer:
http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562851%28v=vs.85%29.aspx

was trying myself a while ago for something to play media in winforms, and found out there is vlc wrappers for .Net, dunno how good they are as i gave up, but you can try
here is one them:
http://vlcdotnet.codeplex.com/

Thanks for all the great answers. But just found out that VLC can actually be controlled through HTTP. So I think I'm just going to use that to point an instance of VLC running with the HTTP interface at whatever file I want to play.

Related

How to trim a mp4 video in a Windows Phone 8 App

I want to trim a MP4 video in a Windows Phone 8 Application.
Say when saving a video, I only want to save the last two minutes.
I have tried converting the video stream into a byte array and altering it. Since the mp4 format has headers and lot of other metadata it is not easy to achieve this fiddling with the byte array of the stream.
If it is a Windows Store app I can use MediaTranscode class in the Windows.Media.Transcoding API to achieve this like in the article below.
Trim Video Windows Store App Example
I pretty much want to do something similar in windows phone.
Is there a similar API I can use in WP?
I also have been looking into Microsoft Media Foundation to achieve this? I am no C++ expert and wanting achieve this in C#.
Any help or direction would be much appreciated.
Thanks
C# in general is not setup to do movie editing. It's older sibling c++ is where this done. I know that's not the answer you want to hear but sometimes that's the only reality there is. I was going to offer a hack to make it happen but after digging through the MSDN libraries I don't even see a worthy hack for this.
Find a C++ example and work from there. It will be a little headache but you are much better off than attempting to make C# bend beyond its elasticity point.
Here is a similar thread expressing your concerns.
http://forums.wpcentral.com/windows-phone-apps/204490-video-editing-apps.html
They have made the point that there isn't a single video editing tool on the entire market.
With how long the market has been around I would assume this is because it's not a capability in C#. Which happens to be 99% of the developers working on windows phone right now.

Easiest way to play audio in an openTK application, using any method

My goal here is to be able to play an MP3 in an OpenTK/OpenGL application (.NET but NOT windows forms), being able to stop/play/pause it, access/set the position of the audio file, and have it play to within a few milliseconds of when I tell it to.
I've tried using WindowsMediaPlayer (WMPLib) but for whatever reason the audio doesn't start playing until I resize or move the window. Not sure why but it probably has something to do with the fact that it's meant to be a control on Windows Forms, and this is a GL application.
I've tried using .NET's soundplayer but that incurs a huge delay of up to a second, and I can't set/access the position of the file.
I've looked into OpenTK and OpenAL but that seems way too complex to figure out.
Does anyone have any ideas?
THANKS!
Oh and worst case scenario I could also deal with playing WAV or OGG files instead, and if the play timing is accurate enough I wouldn't need access to the position of the audio.
OpenAL may seem complicated, but it sounds like the best solution to your problem. There's plenty out there on it, though most examples might be in other languages, but the API is the same. Perhaps this thread has some solutions as well.

FFPlay interface in C#?

I recently found a way to convert video's through the FFMpeg converter through command line, but ive recently been interested in making a video player! and i heard that VLC player and various other systems use FFPlay, and i dont know anything about it! so i have some main points of interest..
Questions:
What exactly does the ffplay.exe do?
If it allows me to stream videos, how would i create an interface to C# to use that
How would i display the video on a windows forms app.
If one of those is not possible, im welcome to other alternatives.. or even perhaps writing my own. Suggestions welcome! :)
Edit: im looking for possible solutions with a framework requirement of 3 or below, and also would perfer to not make them install anything additional to my program.
I am not expert but based on what I know,
You can perhaps look at DirectShow technology for developing your video player as there are managed lib such as directshow.net available for it.
To my knowledge, FFPlay is GUI on top of FFmpeg libraries - the main part of FFmpeg is audio/video codec library supporting many formats including MPEG-4 implementation.
To use FFmpeg via DirectShow, you need another component known as ffdshow.

C# Grab frame from wmv file

Does anyone know if it is possible to grab a frame/image from a video (.wmv) on position X using C# without installing DirectX and working on Windows 2008 (a webserver I would like to install as less as possible).
Or even a simple solution with directx could be nice.
Henk
What you'll actually need to look into is DirectShow, the general-purpose media (both audio and video) library for Windows. It used to be part of DirectX but several years ago it branched off and became part of the Windows (Platform) SDK. I should also point out here that it's now been deprecated since Windows Vista in favour of Media Foundation. From what I've read it's a much better library (DirectShow is hell for complex tasks), but unfortunately it's not really feasible to only target Media Foundation at the moment because of the lack of support for XP and earlier...
The best I can really do is point you to DirectShow.NET, a .NET wrapper library for DirectShow, which is rather stable and well tested at the moment. It includes various samples which should help you get going, but by no means will it be a straightforward solution. Also, I strongly recommend you take a look at this CodeProject article/sample application. It deals with both webcam video capture and video playback from files (including WMV). A bit of playing around with that, and learning how to do frame seeking/single frame capture (I think that project might even some code to do that) should get you what you need. Perhaps you'll even find the precise solution somewhere within the DirectShow.NET samples of that CodeProject app.
Of course, I would suggest an easier solution if I could here, but you're pretty much stuck with the horribleness that is DirectShow for the moment. Good luck anyway!
You should try FFmpeg.
Take a look at the Windows Media Format SDK, which is designed to give you pretty direct access to the frames inside a WMV (/WMA/ASF) file.
http://msdn.microsoft.com/en-us/library/dd757738(VS.85).aspx
In particular, you're interested in the synchronous API for reading these files (IWMSyncReader is the interface name). There are some pretty decent samples in the WMFSDK; I believe the most interesting one for you here will be WMSyncReader, which will show you how to dig through a WMV file and get frames, starting at position X.

Does XNA provide audio input (line in)?

Does XNA provide a means of audio input from the line-in? I looked at the MSDNA website but can't find anything on audio input. If it is indeed possible, a snippet of code or a tutorial website would be great.
Edit:
I need to do buffered reads from the audio-line in. I'm not so much interested in the implementation but rather if it has low latency.
Also development will be implemented into a PC only game.
I think all sound files need to be compiled by XACT before they can be used in XNA.
So either you get hold of DirectSound and look at the sample in:
\Samples\Managed\DirectSound\CaptureSound
...or you could interop with winmm.dll. This guy has made a small example of how to do it:
http://www.codeproject.com/KB/audio-video/cswavrec.aspx
And this guy writes some more about enumerating all sound recording devices:
http://www.codeproject.com/KB/cs/Enum_Recording_Devices.aspx
Hope it helps!
Edit:
I'm not sure what you want to do with your audio stream so this tutorial might be of interest as well:
http://nyxtom.vox.com/library/post/recording-audio-in-c.html
Edit 2:
What he said (in the comment)
|
|
V
If you're looking at doing a Windows only project, you could certainly capture the audio coming in with code from outside the XNA framework and play it back with the same. Because of how the XNA content manager works, you wouldn't be able to use the regular playback methods because the content manager translates everything into .xnb files at compile time and reads them from there. Nothing keeping you from playing using standard windows API calls though. You wouldn't really have an XNA project at that point, but I don't suppose the distinction is all that important since you're not looking to be compatible with the other platforms anyway.
To answer your question, no, you can't access audio line-in through the XNA APIs. You'd have to look at some other library such as Port Audio that would give you access to features like that. But then you'd be restricted to running on windows (ie. no xbox or zune).
disclaimer: not sure if port audio specifically has this functionality as I just found it quickly via google. Was just trying to illustrate that you'd have to use some other API.

Categories