streaming video over LAN C#

user1426711 picture user1426711 · Jul 22, 2012 · Viewed 7.7k times · Source

I've recently learned about data streaming and C#. I've practice building a simple server-client Login program like so:

public static TcpClient SocketCLiente = new TcpClient(); 
NetworkStream _serverStream = default(NetworkStream);
public static string IPServer="127.0.0.1";

byte[] outStream = System.Text.Encoding.ASCII.GetBytes(this._txtUserName.Text + "%" + this.txtPassword.Text + "$");
_serverStream.Write(outStream, 0, outStream.Length);

This works great with text, but what if i want to stream a video to a client? How can I stream a live video from my webcam to a c# application over Lan?

Answer

devshorts picture devshorts · Oct 9, 2012

Like the comment mentioned you should check out How can I stream webcam video with C#?. In general all you stream out are bytes. As long as those bytes are formatted in a way that a player, such as flash, or silverlight, or whatever, can understand then it can play the video back.

Now I don't think that post really covers the internet streaming aspect. It really touches more on capturing and playing back locally. Thats what directshow is good at. It abstracts away all the driver nonsense that you used to have to deal with to capture video and audio frame data.

Streaming to the internet, short of rolling your own streaming server, is usually accomplished by hooking into something like red-5, wowza, adobe FMS, rtsp, silverlight streaming etc.

I would use one of those solutions to hook into wherever you are getting your video data from. The gist is that you capture video/audio packets from directshow and then funnel those packets (formatted however the solution wants) to one of these streaming platforms.

Another option, though it is a little more "hackish", would be to stream your video as motion jpeg. This wouldn't let you send audio though. Motion jpeg basically tells the client to keep a connection open and constantly download a new image and replace the old one. It's like a flipbook for web. The advantage here is you can roll your own motion jpeg code pretty easily and it'd be a fun little project.