Tuesday, November 4, 2008

STREAM VIDEO OVER A LAN USING C#.NET

TV SERVER

TV CLIENT





With the help of Video Lan Player we can easily stream video over a lan using c#.net.For This Project You must do the following steps.
Step 1:
Install vlc player in your computer.For more information about vlc player visit http://www.videolan.org/.

Step 2:
Just copy the libvlc.dll from the vlc installaling folder and paste it in to the windows->system32 folder.

Step 3:
Create a class named LibVlc.cs.You will get the Source code of LibVlc.cs from http://libvlc.blogspot.com/.

Step4:
Server Side
You design a form contain a picture box and a button.Just copy paste the source code in the button click event.
private void button1_Click(object sender, EventArgs e)
{
try
{
LibVlc vlc = new LibVlc();
vlc.Initialize();
vlc.VideoOutput = pictureBox1;
vlc.PlaylistClear();
string[] Options=new string[] { ":sout=#duplicate{dst=display,dst=std {access=udp,mux=ts,dst=224.100.0.1:1234}}" };
vlc.AddTarget("c:\\1.flv", Options);
vlc.Play();
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}

Step 5:
Client Side:
In client side we can play video from a stream produced by the server.Design a form contain a picture box and a button.Just copy paste the code in the button click event.
private void button1_Click(object sender, EventArgs e)
{
try
{
LibVlc vlc = new LibVlc();
vlc.Initialize();
vlc.VideoOutput = pictureBox1;
vlc.PlaylistClear();
string[] options = { ":sout=#duplicate{dst=display,dst=std{access=file,mux=asf,dst=\"F:\\My-Output-Video-Filename.asf\"}}" };
vlc.AddTarget("udp://@224.100.0.1:1234", options);
vlc.Play();
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
Code Explanation:
Server Side:
In server side first we create the object of the class LibVlc.cs created in step3.
Set the vlc.VideoOutput=our picture box name.

In vlc.AddTarget() method we pass two para metres.First one is the full path of the file name to be streamed.Second one is the string array contain the protocol type,address and a port number.Here protocol type is udp.

224.100.0.1-multi cast ipaddress.Also use unicast ip address or a loop back address(127.0.0.1) when you use a single system.
If you want to know more about multicast and unicast ipaddress vist
http://unicastandmulticast.blogspot.com/.
1234-port number.
When the vlc.play() method is executed,Video is playing locally and stream the video over the Lan at the same time.
Client Side:
In client side first four lines as same as the client side.In vlc.Addtarget() method we pass two parameters first one contain protocol type ipaddress and the port number.Second one is a string array.After this method we can call a method vlc.play().Then video is playing in our picture box from the Network stream.

We can easily make television broadcasting stations in the local lan in c#.net.I done a project using this codes view the screen shots of that project.http://videostreamscreenshots.blogspot.com/
Note:
I use vlc media player 0.8.6i.


About Me
Arun Sukumar










hit counter
hit counter