start recording stream on button click with VLC dot net library

大城市里の小女人 提交于 2019-12-24 08:24:08

问题


i have got a win form application that stream video from a ip camera... i use a lib that is already avaliable.. lib site VideoLan DotNet for WinForm, WPF & Silverlight 5

in order to stram the video i do this:

string path = "rtsp://****:****@192.168.5.223/profile2/media.smp";
LocationMedia media = new LocationMedia(path);
vlcControl1.Media = media;
vlcControl1.Play();

what i want now is to save the stream to a file on a button click, i mean , the video is playing, and then i press the button to record the video...

How can i do it?

when starting the video i can do this to save..

 string path = ....
 LocationMedia media = new LocationMedia(path);        media.AddOption(":sout=#transcode{vcodec=theo,vb=800,scale=1,acodec=flac,ab=128,channels=2,samplerate=44100}:std{access=file,mux=ogg,dst=C:\\Users\\hsilva\\Desktop\\123.mp4}");
 vlcControl1.Media = media;
 vlcControl1.Play();

so how can i add option if the video is already playing...


回答1:


I'm using libVlc and just stumbled on your question and answers. I took a similar approach but I also grabbed the time(libvlc_media_player_get_time(IntPtr p_mi)) when I clicked on the record (start) button. I then used that time as the start time(libvlc_media_player_set_time(IntPtr p_mi, Int64 newTime)) to resume playback and begin recording.

In my implementation, clicking on the record button again stops the recording, gets and sets the time, and resumes playing of the video on the screen.

The drawback to this approach is a noticeable delay in resumption of play, only a second or so, but not seamless as I had hoped. I suspect this is due to having to seek to the specified time.

I also found some references to libvlc_media_player_record_[start|stop](IntPtr p_mi,...) api's but nothing official. I am interested in finding out if you were able to find a better way to accomplish this and how you did it.




回答2:


see there: https://mykb.cipindanci.com/archive/SuperKB/4164/ for RTSP live streaming, just do it like below:

IntPtr p_md = LibVlcAPI.libvlc_media_player_get_media(this.libvlc_media_player_);
LibVlcAPI.libvlc_media_add_option(p_md, pMrl);
LibVlcAPI.libvlc_media_player_set_media(libvlc_media_player_, p_md);
LibVlcAPI.libvlc_media_player_play(libvlc_media_player_);

and call below to stop recording:

IntPtr p_md = LibVlcAPI.libvlc_media_player_get_media(this.libvlc_media_player_);
LibVlcAPI.libvlc_media_player_set_media(libvlc_media_player_, p_md);
LibVlcAPI.libvlc_media_player_play(libvlc_media_player_);

also that link demo two function:

LibVlcAPI.libvlc_media_player_recorder_start(this.libvlc_media_player_, pMrl);
IntPtr pMrl = IntPtr.Zero;
byte[] bytes = Encoding.UTF8.GetBytes(FILE_PATH);
pMrl = Marshal.AllocHGlobal(bytes.Length + 1);
Marshal.Copy(bytes, 0, pMrl, bytes.Length);
Marshal.WriteByte(pMrl, bytes.Length, 0);
return LibVlcAPI.libvlc_media_player_recorder_start(this.libvlc_media_player_, pMrl);

stop recording:

return LibVlcAPI.libvlc_media_player_recorder_stop(this.libvlc_media_player_);

libvlc_media_player_recorder_stop & libvlc_media_player_recorder_start only available in VLC x86 libs, not avaiable for x64 dlls.

but for file playing, you had to do it like BitMask777.



来源:https://stackoverflow.com/questions/24202812/start-recording-stream-on-button-click-with-vlc-dot-net-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!