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/
Related
this is my first question in StackOverflow.
How can I encode video being captured from webcam as a MJPEG using C# in UWP enviroment (Visual Studio 2017)?
Perhaps using FFMPEG or DirectShow? Any particular bindings required to use them in UWP?
I've been through these walk-throughs trying to go the official way using MediaCapture:
https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/basic-photo-video-and-audio-capture-with-mediacapture
https://learn.microsoft.com/en-us/uwp/api/windows.media.capture.mediacapture
According to Microsoft though, there is no MJPEG encoder included in MediaEncoder (only decoder): https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/supported-codecs
About FFMPEG UWP integration, I found this:
https://github.com/Microsoft/FFmpegInterop
https://blogs.windows.com/buildingapps/2015/06/05/using-ffmpeg-in-windows-applications/#HHYbWAVcM7LhkvYZ.97
But it's geared towards decoding, and I want to encode.
Just in case someone is wondering, I want to use MJPEG for Two reasons:
1) less CPU intensive (much less) because it doesn't do inter-frame compression, means my Surface Pro (and other similar computers) will keep quiet without fans running like crazy
2) I need all frames (i.e. not one every 30) to be crystal clear because of an algorithm I need to run on each of them after
Any pointers would be greatly appreciated.
Thank you,
Federico
I'm a complete beginner in C#, but I'm trying to write a very simple application in C# (VS2013) to simply view video stream or capture frames from a Sony FCB-EV7500 camera. The camera connects to a small USB3 board using CN401, and the board connects to the laptop via USB3. I can view video in VLC for example, but i'd like to write code in a C# application to get video/grab frames.
Google searching this brought me to DirectShow which apparently is only a C++ library. There used to be a DirectShow.NET wrapper available here: http://directshownet.sourceforge.net/about.html but it seems they haven't updated the project since 2010 and a lot of functions/interfaces at that time remained untested.
Are there any commonly used libraries for accomplishing this in C#? Perhaps something included in the .NET framework? Thanks for any advice or direction.
You really don't want to be marshaling full frame rate video into a C# application.
You should probably take a look at the .net bindings for gstreamer, I have personally only used the C and python bindings so YMMV. If that doesn't work you will need to:
Use direct show, gstreamer, or ffmpeg to deal with media.
Write a native wrapper around your media handling code.
Write C# code to interop with your wrapper.
depending on if you are using winforms or wpf you will either use a NativeWindow or D3DImageSource as your render target.
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.
I'm making a game with some friends for our last highschool project .
I'm having trouble finding out how to play the music I've written in c# and I'm turning here for answers.
We're using Microsoft Visual studio 2010, and I've mainly been writing music for the game during this time so I'm quite a beginner at programming in C#.
The Music I've made is made in a program called Famitracker don't know if your familiar with it but I can export the files to NSF which is good since they take up low disk space.
So my real question is how do I make our game play the music and loop it until the play gets to the next stage?
NSF, or the Nintendo Sound Format is not something that Windows nor .NET supports natively... instead you would have to either write or find your own player for it... or redo your music in something more common like MP3 or WAV.
If you want to stick with NSF, I'd suggest looking at one of the open source NES emulators out there and see if you can't use of of their code. (Example 1) (Example 2) (Example 3)
Your easiest solution would probably be to output is as a wav and play it using XNA as Matthew describes. The file size may be larger, but unless you are having file size issues, I think that will by far be the easiest way to go. There doesn't seem to be any easy implementation of a nsf player in C#, although you might look into how NES emulators are doing it.
Use the XNA framework for audio, etc in games.
Here is a good starting point: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=xna+framework+play+audio
I am interested in developing an application that will allow me to build a list of videos from xml (containing video title, duration, etc) and play that list as my webcam stream. Meaning, if I were to visit ustream.tv, or activate my webcam on live messenger my video playlist would register as my active webcam.
Does anybody have experience in this area, and perhaps have some advice to offer?
If you want this to work so that third party apps see your video as a standard webcam stream (and is sounds very much like you do) then the only way to do it is to write a virtual webcam driver. You will then then be able to "play" your video content as your webcam's streaming output. This will involve writing code to decode the video content - probably using DirectShow - and then copying the raw video stream to the webcam's output stream. You'll need to either write a custom DirectShow renderer filter or use the sample grabber to access the raw, decoded frames.
It's certainly an achievable goal, but not particularly easy given that both DirectShow and driver development have fairly steep learning curves. There are a variety of different driver models you could use for this, depending on exactly what your aims are. The easiest thing would be to create a Video for Windows (VfW) virtual camera driver. The huge benefit of this approach is that the driver will be entirely user mode code - much easier to debug and to write in general.
I don't have a lot of experience in this area, but I would start by looking at the MSDN docs for the DirectShow API.
A couple of .NET wrapper libraries exist as well:
Managed DirectShow
DirectShow.NET
Another DirectShow.NET