<div dir="ltr"><div style><span style="font-family:arial,sans-serif;font-size:14px">Another version with better layout:)</span></div><div style><span style="font-family:arial,sans-serif;font-size:14px"><br></span></div><span style="font-family:arial,sans-serif;font-size:14px">Hi:</span><div style="font-family:arial,sans-serif;font-size:14px">
<br></div><div style="font-family:arial,sans-serif;font-size:14px">I am a newbee for vlc developing, now I want to do such thing in my corrent project:</div><div style="font-family:arial,sans-serif;font-size:14px"><br></div>
<div style="font-family:arial,sans-serif;font-size:14px">A Win7 App(written in WPF & C#), which:</div><div style="font-family:arial,sans-serif;font-size:14px"><br></div><div style="font-family:arial,sans-serif;font-size:14px">
1. Can Show living streaming video from an DirectShow USB WebCam to a window of the App</div><div style="font-family:arial,sans-serif;font-size:14px"><br></div><div style="font-family:arial,sans-serif;font-size:14px">2. Can record the video into a mp4 file</div>
<div style="font-family:arial,sans-serif;font-size:14px"><br></div><div style="font-family:arial,sans-serif;font-size:14px">3. Can stop recording the video, but the living show should always there</div><div style="font-family:arial,sans-serif;font-size:14px">
<br></div><div style="font-family:arial,sans-serif;font-size:14px">To make that work, I created two VLC media player instances: one if for living streaming show on screen, the other is for recording streaming video into file.</div>
<div style="font-family:arial,sans-serif;font-size:14px"><br></div><div style="font-family:arial,sans-serif;font-size:14px">==========================================================================================</div><div style="font-family:arial,sans-serif;font-size:14px">
Copy some code here:</div><div style="font-family:arial,sans-serif;font-size:14px"><br></div><div style="font-family:arial,sans-serif;font-size:14px">+++++++++++++++++++++++++++++++++ MyVLCPlayer.cs++++++++++++++++++++++++++++++++++++++++<br>
</div><div style="font-family:arial,sans-serif;font-size:14px"><br></div><div><div><font face="arial, sans-serif"><span style="font-size:14px"> class MyVLCPlayer</span></font></div><div><font face="arial, sans-serif"><span style="font-size:14px"> {</span></font></div>
<div><font face="arial, sans-serif"><span style="font-size:14px"> private IntPtr libvlc_instance_;</span></font></div><div><font face="arial, sans-serif"><span style="font-size:14px"> private IntPtr libvlc_media_player_;</span></font></div>
<div><font face="arial, sans-serif"><span style="font-size:14px"> private double duration_;</span></font></div></div><div style="font-family:arial,sans-serif;font-size:14px">....</div><div style="font-family:arial,sans-serif;font-size:14px">
<div> public MyVLCPlayer()</div><div> {</div><div> string[] arguments = { "-I", "dummy", "--ignore-config", "--no-video-title", @"--plugin-path=C:\Program Files (x86)\VideoLAN\VLC\plugins" };</div>
<div> libvlc_instance_ = LibVlc.libvlc_new(arguments.Length, arguments);</div><div> if (libvlc_instance_ != IntPtr.Zero)</div><div> {</div><div> libvlc_media_player_ = LibVlc.libvlc_media_player_new(libvlc_instance_);</div>
<div> }</div><div> }</div></div><div style="font-family:arial,sans-serif;font-size:14px">....</div><div style="font-family:arial,sans-serif"><div style="font-size:14px"> public void PlayDirectShow()</div>
<div style="font-size:14px"> {</div><div style="font-size:14px"> if (libvlc_instance_ != IntPtr.Zero)</div><div style="font-size:14px"> {</div><div style="font-size:14px"> IntPtr libvlc_media = LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");</div>
<div style="font-size:14px"> if (libvlc_media != IntPtr.Zero)</div><div style="font-size:14px"> {</div><div style="font-size:14px"> string[] options = new string[]</div>
<div style="font-size:14px"> {</div><div style="font-size:14px"><span style="white-space:pre-wrap"> </span> ":dshow-vdev=USB 2861 Device",</div><div style="font-size:14px">
":dshow-size=640*480",</div><div style="font-size:14px"> </div><div style="font-size:14px"> };</div><div style="font-size:14px"> foreach (string option in options)</div>
<div style="font-size:14px"> {</div><div style="font-size:14px"> LibVlc.libvlc_media_add_option(libvlc_media, option);</div><div style="font-size:14px"> }</div>
<div style="font-size:14px"> if (libvlc_media_player_ != IntPtr.Zero)</div><div style="font-size:14px"> {</div><div style="font-size:14px"> LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);</div>
<div style="font-size:14px"> }</div><div style="font-size:14px"> LibVlc.libvlc_media_release(libvlc_media);</div><div style="font-size:14px"> LibVlc.libvlc_media_player_play(libvlc_media_player_);</div>
<div style="font-size:14px"> //LibVlc.libvlc_media_player_pause(libvlc_media_player_);</div><div style="font-size:14px"> }</div><div style="font-size:14px"> }</div><div style="font-size:14px">
}</div><div style="font-size:14px"><div> public void RecordDirectShow(string filePath)</div><div> {</div><div> if (libvlc_instance_ != IntPtr.Zero)</div><div> {</div><div> IntPtr libvlc_media = LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");</div>
<div> if (libvlc_media != IntPtr.Zero)</div><div> {</div><div> string[] options = new string[]</div><div> {</div><div><span style="white-space:pre-wrap"> </span> ":dshow-vdev=USB 2861 Device",</div>
<div> ":dshow-size=640*480",</div><div> </div><div> ":sout=#duplicate{dst=\'transcode{venc=x264{keyint=15,bframes=0},vcodec=h264,vb=400,scale=1,fps=25,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access=file,mux=mp4,dst=" + filePath + "}\'}"</div>
<div> };</div><div> foreach (string option in options)</div><div> {</div><div> LibVlc.libvlc_media_add_option(libvlc_media, option);</div>
<div> }</div><div> if (libvlc_media_player_ != IntPtr.Zero)</div><div> {</div><div> LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);</div>
<div> }</div><div> LibVlc.libvlc_media_release(libvlc_media);</div><div> LibVlc.libvlc_media_player_play(libvlc_media_player_);</div><div> //LibVlc.libvlc_media_player_pause(libvlc_media_player_);</div>
<div> }</div><div> }</div><div> }</div></div><div style="font-size:14px"><br></div><div style="font-size:14px"><div> public void Stop()</div><div> {</div><div> if (libvlc_media_player_ != IntPtr.Zero)</div>
<div> {</div><div> LibVlc.libvlc_media_player_stop(libvlc_media_player_);</div><div> }</div><div> }</div></div><div style="font-size:14px"><br></div><div style="font-size:14px">
.....</div><div style="font-size:14px">}</div><div style="font-size:14px"><br></div><div style="font-size:14px">+++++++++++++++++++++++++++++++++++++MainWindow.xaml.cs+++++++++++++++++++++++++++++++++++++++++<br></div><div style="font-size:14px">
<br></div><div style="font-size:14px"><div>private MyVLCPlayer player;</div><div> private MyVLCPlayer recorder;</div></div><div style="font-size:14px"><br></div><div><div style="font-size:14px"> public MainWindow()</div>
<div style="font-size:14px"> {</div><div style="font-size:14px"> InitializeComponent();</div><div style="font-size:14px">....</div><div style="font-size:14px"><div>player = new MyVLCPlayer();</div><div> recorder = new MyVLCPlayer();</div>
</div><div style="font-size:14px">....</div><div style="font-size:14px"><br></div><div style="font-size:14px"> }</div><div style="font-size:14px"><br></div><div style="font-size:14px"><div><br></div><div>Then, do something like that:</div>
<div><br></div><div>1. player. PlayDirectShow();</div></div><div style="font-size:14px">2. recorder.RecordDirectShow(filepath);</div><div style="font-size:14px">3. recorder.Stop();</div><div style="font-size:14px"><br></div>
<div style="font-size:14px">The 1 and 2 works well, I can see the living video on screen and the mp4 file recorded on the fly, but</div><div style="font-size:14px"><br></div><div><b><font size="6">the stop will never return!!</font></b></div>
<div style="font-size:14px"><br></div><div style="font-size:14px">can someone tell me why?</div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/16 cong fu <span dir="ltr"><<a href="mailto:fc4976@gmail.com" target="_blank">fc4976@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi:<div><br></div><div>I am a newbee for vlc developing, now I want to do such thing in my corrent project:</div>
<div><br></div><div>a windows application, which can:</div><div>1. Show living show from an directshow usb device on screen forever</div>
<div>2. click a button to start to record the video into a mp4 file</div><div>3. click another button to stop recording the video, but the living show should always there</div><div><br></div><div>to make it work, I created two VLC media player instances, one if for living show on screen, the other is for recording into file, copy some code here:</div>
<div><br></div><div>MyVLCPlayer.cs<br></div><div><br></div><div><div> public MyVLCPlayer()</div><div> {</div><div> string[] arguments = { "-I", "dummy", "--ignore-config", "--no-video-title", @"--plugin-path=C:\Program Files (x86)\VideoLAN\VLC\plugins" };</div>
<div> libvlc_instance_ = LibVlc.libvlc_new(arguments.Length, arguments);</div><div> if (libvlc_instance_ != IntPtr.Zero)</div><div> {</div><div> libvlc_media_player_ = LibVlc.libvlc_media_player_new(libvlc_instance_);</div>
<div> }</div><div> }</div></div><div><br></div><div><div> public void PlayDirectShow()</div><div> {</div><div> if (libvlc_instance_ != IntPtr.Zero)</div><div> {</div>
<div> IntPtr libvlc_media = LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");</div><div> if (libvlc_media != IntPtr.Zero)</div><div> {</div><div> string[] options = new string[]</div>
<div> {</div><div><span style="white-space:pre-wrap"> </span> ":dshow-vdev=USB 2861 Device",</div><div> ":dshow-size=640*480",</div>
<div> </div><div> };</div><div> foreach (string option in options)</div><div> {</div><div> LibVlc.libvlc_media_add_option(libvlc_media, option);</div>
<div> }</div><div> if (libvlc_media_player_ != IntPtr.Zero)</div><div> {</div><div> LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);</div>
<div> }</div><div> LibVlc.libvlc_media_release(libvlc_media);</div><div> LibVlc.libvlc_media_player_play(libvlc_media_player_);</div><div> //LibVlc.libvlc_media_player_pause(libvlc_media_player_);</div>
<div> }</div><div> }</div><div> }</div><div><div> public void RecordDirectShow(string filePath)</div><div> {</div><div> if (libvlc_instance_ != IntPtr.Zero)</div>
<div>
{</div><div> IntPtr libvlc_media = LibVlc.libvlc_media_new_path(libvlc_instance_, @"dshow://");</div><div> if (libvlc_media != IntPtr.Zero)</div><div> {</div>
<div> string[] options = new string[]</div><div> {</div><div><span style="white-space:pre-wrap"> </span> ":dshow-vdev=USB 2861 Device",</div><div>
":dshow-size=640*480",</div><div> </div><div> ":sout=#duplicate{dst=\'transcode{venc=x264{keyint=15,bframes=0},vcodec=h264,vb=400,scale=1,fps=25,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access=file,mux=mp4,dst=" + filePath + "}\'}"</div>
<div> };</div><div> foreach (string option in options)</div><div> {</div><div> LibVlc.libvlc_media_add_option(libvlc_media, option);</div>
<div> }</div><div> if (libvlc_media_player_ != IntPtr.Zero)</div><div> {</div><div> LibVlc.libvlc_media_player_set_media(libvlc_media_player_, libvlc_media);</div>
<div> }</div><div> LibVlc.libvlc_media_release(libvlc_media);</div><div> LibVlc.libvlc_media_player_play(libvlc_media_player_);</div><div> //LibVlc.libvlc_media_player_pause(libvlc_media_player_);</div>
<div> }</div><div> }</div><div> }</div></div><div><br></div><div>MainWindow.xaml.cs<br></div><div><br></div><div><div>private MyVLCPlayer player;</div><div> private MyVLCPlayer recorder;</div>
</div><div><br></div><div><div> public MainWindow()</div><div> {</div><div> InitializeComponent();</div><div>....</div><div><div>player = new MyVLCPlayer();</div><div> recorder = new MyVLCPlayer();</div>
</div><div>....</div><div><br></div><div> }</div><div><br></div><div><div> Then,</div><div><br></div><div>1. player. PlayDirectShow();</div></div><div>2. recorder.RecordDirectShow(filepath);</div>
<div>3. recorder.Stop();</div><div><br></div><div>the stop will never return!!</div><div><br></div><div>can someone tell me why?</div><div><br></div></div></div></div>
</blockquote></div><br></div>