57

I want to make a simple server application where people can connect using a browser-based client (which I will make later) to watch streaming video. And I want to use C#.

What do I need to capture video or rapid images through a webcam and send them over the network?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
The.Anti.9
  • 43,474
  • 48
  • 123
  • 161
  • For anyone looking to capture images from WebCam in C# - try this article - http://www.codeproject.com/KB/miscctrl/webcam_c_sharp.aspx. – nikib3ro Nov 09 '10 at 04:24
  • Maybe this will help: - http://sourceforge.net/projects/ispysoftware/ - http://www.ispyconnect.com/ –  Jan 07 '12 at 05:31

6 Answers6

22

If you want a "capture/streamer in a box" component, there are several out there as others have mentioned.

If you want to get down to the low-level control over it all, you'll need to use DirectShow as thealliedhacker points out. The best way to use DirectShow in C# is through the DirectShow.Net library - it wraps all of the DirectShow COM APIs and includes many useful shortcut functions for you.

In addition to capturing and streaming, you can also do recording, audio and video format conversions, audio and video live filters, and a whole lot of stuff.

Microsoft claims DirectShow is going away, but they have yet to release a new library or API that does everything that DirectShow provides. I suspect many of the latest things they have released are still DirectShow under the hood. Because of its status at Microsoft, there aren't a whole lot of books or references on it other than MSDN and what you can find on forums. Last year when we started a project using it, the best book on the subject - Programming Microsoft DirectShow - was out of print and going for around $350 for a used copy!

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
CMPalmer
  • 8,571
  • 5
  • 40
  • 49
  • 5
    I know I'm replying to an old question but read the Amazon reviews before shelling out the money for that book. It's every bit as horrible as everyone claims. Buying GraphEditPlus and looking at the code it generates would be a better value for simple tasks. – dgnorton Jan 26 '11 at 05:12
  • 2
    Is there any new solution on this topic or is DirectShow still state of the tech now? – daniel Jan 16 '14 at 15:43
7

The usual API for this is DirectShow.

You can use P/Invoke to import the C++ APIs, but I think there are already a few projects out there that have done this.

http://channel9.msdn.com/forums/TechOff/93476-Programatically-Using-A-Webcam-In-C/

http://www.codeproject.com/KB/directx/DirXVidStrm.aspx

To get the streaming part, you probably want to use DirectShow to apply a compression codec to reduce lag, then you can get a Stream and transmit it. You could consider using multicast to reduce network load.

Excel Kobayashi
  • 578
  • 1
  • 6
  • 19
  • 2
    You can't really use P/Invoke to import the C++ API for DirectShow as it's COM based. You can use the DirectShow wrapper called DirectShow.Net. – faulty Dec 07 '08 at 03:42
5

You could just use VideoLAN. VideoLAN will work as a server (or you can wrap your own C# application around it for more control). There are also .NET wrappers for the viewer that you can use and thus embed in your C# client.

Chris Holmes
  • 11,444
  • 12
  • 50
  • 64
3

I've used VideoCapX for our project. It will stream out as MMS/ASF stream which can be open by media player. You can then embed media player into your webpage.

If you won't need much control, or if you want to try out VideoCapX without writing a code, try U-Broadcast, they use VideoCapX behind the scene.

faulty
  • 8,117
  • 12
  • 44
  • 61
2

Another option to stream images from a webcam to a browser is via mjpeg. This is just a series of jpeg images that most modern browsers support as part of the tag. Here's a sample server written in c#:

https://www.codeproject.com/articles/371955/motion-jpeg-streaming-server

This works well over a LAN, but not as well over the internet as mjpeg is not as effcient as other video codecs (h264, VP8 etc..)

mark gamache
  • 389
  • 3
  • 12
1

If you want to record video from within a web browser, I think your only option is Flash. We are looking to do the same thing. We are also primarily a .NET house and I don't see a way to use .NET to capture the webcam _from_within_the_browser_. All of the other solutions mentioned here would probably work great if you are happy to settle for a desktop app

gillonba
  • 897
  • 9
  • 24