1
votes

I want to build application which needs to be able to capture video from web camera using C#. Captured video should be compressed using some codec (nothing special, anything available that saves space) and written to file while capturing. Live preview of capture is not necessary.

First question is which API is suitable for this and you would recommend (I have seen DirectShow, Windows Media Foundation wrapper, etc ... not sure which is would be best for managed environment and C#)?

I also need video player in WPF which will play captured video. This player must be able to play captured video from arbitrary position, pause and start/stop video. Putting it all together - video is captured from webcam in background and at the same time player plays that video being captured but it can be paused, re-winded, stopped - something like modern DVR.

Second question - is it possible to create such player using WPF MediaElement? (confusion is about file which is at the same time filled from capture and played in player)

5
You need to make your question a lot more specific - break it into chunks that deal with specific problems you're having after attempting something.Widor
I need a recommendation on which API (technology) to use for the capture, it is not question about problem it is about recommendation!Dusan
In that case, it's not suitable for StackOverflow I'm afraid.Widor

5 Answers

2
votes

Nice example how to make all what you want WebCam

1
votes

I have used the AForge(http://www.aforgenet.com/) set of libraries to accept the videos frame by frame. I used the (private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)) function to do this.

0
votes
0
votes

I've used VlcDotNet. It is very flexible and simple to use. It has a pretty active user base as well.

I've used it for displaying live video streams as well as recording to files.

0
votes

I can recommend WPF ffmediaelement. It's built on ffmpeg. So what can ffmpeg, can also ffmediaelement. Can capture video from both the webcam and the capture card. Unlike DirectShow, it's very simple. Here's how to set up a video source:

Media.Source = new Uri("device://dshow/?video=Osprey-460e Video Device 1C");

... and parameters for it in MediaOpening event:

Media.OnMediaOpening(s, e) =>
{
    e.Options.Input["framerate"] = "25";
    e.Options.Input["video_size"] = "768x576";
    e.Options.Input["pixel_format"] = "yuyv422";
};