tag:blogger.com,1999:blog-63872871792355519002024-03-04T21:44:29.346-08:00C#.NET MAGICSStream video using c#.net with the help of vlc media player.Arun Sukumarhttp://www.blogger.com/profile/02810817292909357671noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-6387287179235551900.post-15127185897710100462008-11-04T08:21:00.000-08:002009-10-22T10:55:06.948-07:00STREAM VIDEO OVER A LAN USING C#.NET<span style="font-weight: bold;">TV SERVER</span><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCNJ89GqoRb9-n9oMpdofgRgyXscej18Dv2-kQst12eHNR71d2uJRgwcZr6zJaCHSznNJN14xEXgh_2oN4EDxx2Fn9N_KR3baCCtok2FvF4Cvduoh0CF1Szp6PXOUJfSpZE4cma9uIj0B1/s1600-h/tvserverworking.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 557px; height: 322px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCNJ89GqoRb9-n9oMpdofgRgyXscej18Dv2-kQst12eHNR71d2uJRgwcZr6zJaCHSznNJN14xEXgh_2oN4EDxx2Fn9N_KR3baCCtok2FvF4Cvduoh0CF1Szp6PXOUJfSpZE4cma9uIj0B1/s400/tvserverworking.jpg" alt="" id="BLOGGER_PHOTO_ID_5395482884451349858" border="0" /></a><br /><span style="font-weight: bold;"> TV CLIENT</span><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW1rm0TVxftWQil2eRZBu_fekP8yQuQ4eu1V9KPJZ6d37qyH3Ncv9i2DAUSAxK68uSYxlB5NY5Eh8urYEtaArba9GkhPd9iJFGtmWo53Q01wQM6oVle2Ts9BjN6YOTUI5Ov989xyArW8cp/s1600-h/client.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 317px; height: 318px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW1rm0TVxftWQil2eRZBu_fekP8yQuQ4eu1V9KPJZ6d37qyH3Ncv9i2DAUSAxK68uSYxlB5NY5Eh8urYEtaArba9GkhPd9iJFGtmWo53Q01wQM6oVle2Ts9BjN6YOTUI5Ov989xyArW8cp/s400/client.jpg" alt="" id="BLOGGER_PHOTO_ID_5395483320103098802" border="0" /></a><br /><br /><div id="vizu" class="vizuClass" style="width: 200px; text-align: center;"><br /><br /><div style="line-height: 0px;"><script language="JavaScript" src="http://wp.vizu.com/zones/5249/exportPoll_5794.js" type="text/javascript"></script></div></div><br /><span style="font-weight: bold;">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.</span><br /><strong style="font-weight: bold;"><span style="font-size:130%;">Step 1:</span></strong><br /><div style="font-weight: bold; color: rgb(0, 0, 0); font-family: verdana; text-align: justify;">Install vlc player in your computer.For more information about vlc player visit <a style="color: rgb(0, 51, 0);" href="http://www.videolan.org/"><span style="color: rgb(102, 0, 0);">http://www.videolan.org/</span></a><span style="color: rgb(0, 51, 0);">.</span><br /></div><br /><strong style="font-weight: bold;"><span style="font-size:130%;">Step 2:</span></strong><br /><div style="color: rgb(0, 0, 0); text-align: justify;"><strong style="font-weight: bold;" face="verdana"></strong><span style="font-weight: bold;font-family:verdana;" >Just copy the libvlc.dll from the vlc installaling folder and paste it in to the windows->system32 folder.</span><br /></div><br /><strong style="font-weight: bold;"><span style="font-size:130%;">Step 3:</span></strong><br /><div style="color: rgb(0, 0, 0); text-align: justify;"><strong style="font-weight: bold;" face="verdana"></strong><span style="font-weight: bold;font-family:verdana;" >Create a class named LibVlc.cs.You will get the Source code of LibVlc.cs from </span><a style="font-weight: bold; font-family: verdana;" href="http://libvlc.blogspot.com/"><span style="color: rgb(102, 0, 0);">http://libvlc.blogspot.com/</span></a><span style="font-weight: bold;font-family:verdana;" >.</span><br /></div><br /><strong style="font-weight: bold;"></strong><strong style="font-weight: bold;"><span style="font-size:130%;">Step4:</span></strong><br /><span style="font-weight: bold;font-size:130%;" ><strong>Server Side </strong><br /></span><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;" >You design a form contain a picture box and a button.Just copy paste the source code in the button click event.</span><br /></div><span style="font-weight: bold;">private void button1_Click(object sender, EventArgs e)</span><br /><span style="font-weight: bold;">{</span><br /><span style="font-weight: bold;">try</span><br /><span style="font-weight: bold;">{</span><br /><span style="font-weight: bold;">LibVlc vlc = new LibVlc();</span><br /><span style="font-weight: bold;">vlc.Initialize();</span><br /><span style="font-weight: bold;">vlc.VideoOutput = pictureBox1;</span><br /><span style="font-weight: bold;">vlc.PlaylistClear();</span><br /><span style="font-weight: bold;">string[] Options=new string[] { ":sout=#duplicate{dst=display,dst=std {access=udp,mux=ts,dst=224.100.0.1:1234}}" };</span><br /><span style="font-weight: bold;">vlc.AddTarget("c:\\1.flv", Options);</span><br /><span style="font-weight: bold;">vlc.Play();</span><br /><span style="font-weight: bold;">}</span><br /><span style="font-weight: bold;">catch (Exception e1)</span><br /><span style="font-weight: bold;">{</span><br /><span style="font-weight: bold;">MessageBox.Show(e1.ToString());</span><br /><span style="font-weight: bold;">}</span><br /><span style="font-weight: bold;">}</span><br /><br /><span style="font-weight: bold;font-size:130%;" ><strong>Step 5:</strong><br /><strong>Client Side:</strong><br /></span><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;font-size:130%;" ><strong></strong></span><span style="font-weight: bold;font-family:verdana;" >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.</span><br /></div><span style="font-weight: bold;">private void button1_Click(object sender, EventArgs e)</span><br /><span style="font-weight: bold;">{</span><br /><span style="font-weight: bold;">try</span><br /><span style="font-weight: bold;">{</span><br /><span style="font-weight: bold;">LibVlc vlc = new LibVlc();</span><br /><span style="font-weight: bold;">vlc.Initialize();</span><br /><span style="font-weight: bold;">vlc.VideoOutput = pictureBox1;</span><br /><span style="font-weight: bold;">vlc.PlaylistClear();</span><br /><span style="font-weight: bold;">string[] options = { ":sout=#duplicate{dst=display,dst=std{access=file,mux=asf,dst=\"F:\\My-Output-Video-Filename.asf\"}}" };</span><br /><span style="font-weight: bold;">vlc.AddTarget("udp://@224.100.0.1:1234", options);</span><br /><span style="font-weight: bold;">vlc.Play();</span><br /><span style="font-weight: bold;">}</span><br /><span style="font-weight: bold;">catch (Exception e1)</span><br /><span style="font-weight: bold;">{</span><br /><span style="font-weight: bold;">MessageBox.Show(e1.ToString());</span><br /><span style="font-weight: bold;">}</span><br /><span style="font-weight: bold;">}</span><br /><strong style="font-weight: bold; color: rgb(0, 0, 0);font-family:verdana;"><span style="font-size:130%;">Code Explanation:</span></strong><br /><strong style="font-weight: bold; color: rgb(0, 0, 0);font-family:verdana;"><span style="font-size:130%;">Server Side:</span></strong><br /><span style="font-weight: bold;font-size:130%;" ><strong></strong></span><span style="font-weight: bold;font-size:100%;" >In server side first we create the object of the class LibVlc.cs created in step3</span><span style="font-weight: bold;font-size:130%;" >.</span><br /><span style="font-weight: bold;font-size:0pt;" ><span style="font-size:100%;"><span style="font-family:verdana;">Set the vlc.VideoOutput=our picture box</span> name</span>.</span><br /><br /><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;font-size:100%;" >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.</span><span style="font-weight: bold;font-family:verdana;" >Here protocol type is udp.</span><br /><br /></div><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;" >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.<br />If you want to know more about multicast and unicast ipaddress vist<span style="text-decoration: underline;"> </span></span><a style="font-weight: bold; font-family: verdana;" href="http://unicastandmulticast.blogspot.com/">http://unicastandmulticast.blogspot.com/</a><span style="font-weight: bold;">.</span><br /></div><span style="font-weight: bold;">1234-port number.</span><br /><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;" >When the vlc.play() method is executed,Video is playing locally and stream the video over the Lan at the same time.</span><br /></div><span style="font-weight: bold;font-size:130%;" >Client Side:</span><br /><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;font-size:100%;" >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()</span><span style="font-weight: bold;font-family:verdana;" >.Then video is playing in our picture box from the Network stream.</span><br /></div><br /><div style="color: rgb(0, 0, 0); text-align: justify;"><span style="font-weight: bold;font-family:verdana;" >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.</span><a style="font-weight: bold; font-family: verdana;" href="http://videostreamscreenshots.blogspot.com/"><span style="color: rgb(102, 0, 0);">http://videostreamscreenshots.blogspot.com/</span></a><br /></div><strong style="font-weight: bold; color: rgb(0, 0, 0); font-family: verdana;">Note:</strong><br /><strong style="font-weight: bold; color: rgb(0, 0, 0); font-family: verdana;">I use vlc media player 0.8.6i.</strong><br /><span style="font-weight: bold;"><br /><br />About Me</span><a style="font-weight: bold; color: rgb(0, 0, 0); font-family: verdana;" href="http://arun--sukumar.blogspot.com/">Arun Sukumar</a><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><strong></strong><br /><table width="133" border="0" cellpadding="3" cellspacing="0"><tbody><tr><td align="middle"><a href="http://www.website-hit-counters.com/" target="_blank"><img alt="hit counter" src="http://www.website-hit-counters.com/cgi-bin/image.pl?URL=161774-1337" border="0" /></a></td></tr><tr><td align="middle"><span style="color: rgb(51, 0, 6); text-decoration: none;font-family:Geneva,Arial,Helvetica,sans-serif;font-size:9px;" ><a title="hit counter" style="font-size: 9px; color: rgb(85, 85, 86); font-family: Geneva,Arial,Helvetica,sans-serif; text-decoration: none;" href="http://www.website-hit-counters.com/" target="_blank">hit counter</a> </span></td></tr></tbody></table>Arun Sukumarhttp://www.blogger.com/profile/02810817292909357671noreply@blogger.com61