Encoding MJPEG from webcam in UWP development with C# - c#

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

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.

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/

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.

.NET Options Stream Video Files as WebCam Image

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

Categories