static async Task Main(string[] args) { Core.Initialize(); var rendererItems = new HashSet <RendererItem>(); using var libvlc = new LibVLC("--verbose=2"); using var mediaPlayer = new MediaPlayer(libvlc); using var media = new Media(libvlc, "screen://", FromType.FromLocation); var renderer = libvlc.RendererList.FirstOrDefault(); var discoverer = new RendererDiscoverer(libvlc, renderer.Name); discoverer.ItemAdded += (object sender, RendererDiscovererItemAddedEventArgs args) => { rendererItems.Add(args.RendererItem); }; discoverer.Start(); media.AddOption(":screen-fps=24"); media.AddOption(":sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mp4a,ab=128,channels=2,samplerate=44100}:standard{access=http,mux=ts,dst=localhost:8080}"); media.AddOption(":sout-keep"); await Task.Delay(TimeSpan.FromSeconds(5)); // wait for 5 seconds mediaPlayer.SetRenderer(rendererItems.First()); mediaPlayer.Play(media); // start recording await Task.Delay(TimeSpan.FromMinutes(2.0)); // record for 2 minutes mediaPlayer.Stop(); // stop recording and saves the file }
static void Main(string[] args) { // Record in a file "record.ts" located in the bin folder next to the app var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var destination = Path.Combine(currentDirectory, "record.ts"); // Load native libvlc library Core.Initialize(); using (var libvlc = new LibVLC()) using (var mediaPlayer = new MediaPlayer(libvlc)) { // Redirect log output to the console libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}"); // Create new media with HLS link var media = new Media(libvlc, "http://hls1.addictradio.net/addictrock_aac_hls/playlist.m3u8", Media.FromType.FromLocation); // Define stream output options. // In this case stream to a file with the given path and play locally the stream while streaming it. media.AddOption(":sout=#file{dst=" + destination + "}"); media.AddOption(":sout-keep"); // Start recording mediaPlayer.Play(media); Console.WriteLine($"Recording in {destination}"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }
public MainPage() { //_libVLC = new LibVLC(VideoView.SwapChainOptions); InitializeComponent(); TestException(); Loaded += (s, e) => { _libVLC = new LibVLC(VideoView.SwapChainOptions); //_libVLC.Log += (sender, ee) => Debug.WriteLine($"[{ee.Level}] {ee.Module}:{ee.Message}"); _mediaPlayer = new MediaPlayer(_libVLC); VideoView.MediaPlayer = _mediaPlayer; //this._mediaPlayer.Play(new Media(_libVLC, "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", FromType.FromLocation)); //rtsp://b1.dnsdojo.com:1935/live/sys3.stream //_mediaPlayer.Volume = 0; //var mmm = new Media(_libVLC, "http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4", FromType.FromLocation); var mmm = new Media(_libVLC, "rtsp://:@tonyw.selfip.com:6002/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif", FromType.FromLocation); mmm.AddOption($":rtsp-tcp"); mmm.AddOption($":network-caching=1200"); _mediaPlayer.Play(mmm); _mediaPlayer.Mute = true; _mediaPlayer.Buffering += (ss, ee) => { _mediaPlayer.Volume = 0; }; }; Unloaded += (s, e) => { VideoView.MediaPlayer = null; this._mediaPlayer.Dispose(); this._libVLC.Dispose(); }; }
private void VideoView2_Loaded(object sender, RoutedEventArgs e) { //throw new NotImplementedException(); var l = new LibVLC(VideoView2.SwapChainOptions); var m = new MediaPlayer(l); VideoView2.MediaPlayer = m; var md = new Media(l, "http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4", FromType.FromLocation); //var mmm = new Media(_libVLC, "rtsp://:@tonyw.selfip.com:6002/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif", FromType.FromLocation); md.AddOption($":rtsp-tcp"); md.AddOption($":network-caching=1200"); m.Play(md); }
private async Task DisplayVideoDecoding() { var videoDecodings = new List <string>(); videoDecodings.Add("Software decoding"); videoDecodings.Add("Hardware decoding"); var userSelection = await DisplayActionSheet("Video decodings", "Cancel", null, videoDecodings.ToArray()); if (!string.IsNullOrWhiteSpace(userSelection) && videoDecodings.Any(x => x.Equals(userSelection))) { _firstTimePlaying = true; videoView.MediaPlayer.Stop(); var media = new Media(videoView.LibVLC, _fd); if (userSelection.Equals(videoDecodings[0])) { videoView.MediaPlayer.Play(media); } else { var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding(); media.AddOption(configuration); videoView.MediaPlayer.Play(media); } } }
public void AddOption() { using var stream = new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate); using var input = new StreamMediaInput(stream); using var media = new Media(_libVLC, input); media.AddOption("-sout-all"); }
private Task RecordInit() { var liboptions = new string[] { $"--no-osd", $"--no-spu", $"--realrtsp-caching=500", $"--udp-caching=500", $"--tcp-caching=500", $"--sout-file-overwrite", $"--network-caching=1200", $"--rtsp-tcp" }; rLIB = new LibVLC(liboptions); if (libLog.IsChecked == true) { //assign log event handler rLIB.Log += async(sender, ee) => await log(ee); } mprec = new MediaPlayer(rLIB); urlstring = (string)CBurl.SelectedValue; mrec = new Media(rLIB, urlstring, FromType.FromLocation); mrec.AddOption(option); OT.Text += $"Option was added:\n{option}\n"; mrec.StateChanged += Mrec_StateChanged; //mrec.AddOption(":sout-keep"); return(Task.CompletedTask); }
public async Task PlayVideo(string videoId, ClosedCaption caption) { Caption = caption; var videoMedia = await YouTubeWebsite.GetVideoMediaStreamInfosAsync(videoId); var media = new Media(_libVLC, videoMedia.Muxed.WithHighestVideoQuality().Url, FromType.FromLocation); media.AddOption($":start-time={string.Format("{0:D2}.{1:D2}", (int)caption.Offset.TotalSeconds, caption.Offset.Milliseconds)}"); media.AddOption($":run-time={string.Format("{0:D2}.{1:D2}", (int)caption.Duration.TotalSeconds, caption.Duration.Milliseconds)}"); _mediaPlayer = new MediaPlayer(_libVLC); _videoView.MediaPlayer = _mediaPlayer; _mediaPlayer.Play(media); }
static async Task Main(string[] args) { Core.Initialize(); using var libvlc = new LibVLC(); using var mediaPlayer = new MediaPlayer(libvlc); using var media = new Media(libvlc, "screen://", FromType.FromLocation); media.AddOption(":screen-fps=24"); media.AddOption(":sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mp4a,ab=128,channels=2,samplerate=44100}:file{dst=record.mp4}"); media.AddOption(":sout-keep"); mediaPlayer.Play(media); // start recording await Task.Delay(5000); // record for 5 seconds mediaPlayer.Stop(); // stop recording and saves the file }
public MediaPlayer GetMediaPlayer(string filePath, List <string> options) { var media = new Media(LibVLC, filePath); if (Settings.UseHardwareAcceleration) { var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding(); media.AddOption(configuration); } foreach (var option in options) { media.AddOption(option); } var mediaPlayer = new MediaPlayer(media); return(mediaPlayer); }
private async void Button_Click(object sender, RoutedEventArgs e) { var name = $"{DateTime.Now.ToString("HH\\:mm\\:ss").Replace(":", ".")}.ts"; var storageFileVideo = await ApplicationData.Current.LocalFolder.CreateFileAsync(name); var LibVLC = new LibVLC(); var mediaPlayer = new MediaPlayer(LibVLC); using (var media = new Media(LibVLC, new Uri("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"))) { media.AddOption($":sout=#file{{dst={storageFileVideo.Path}}}"); media.AddOption(":sout-keep"); mediaPlayer.Play(media); await Task.Delay(5000); mediaPlayer.Stop(); } }
public async Task Record(string endpoint, string destination) { //var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); destination = Path.Combine(destination, DateTime.Now.ToString("yyyyMMddHHmmss_") + "record.ts"); // Load native libvlc library Core.Initialize(); using (var libvlc = new LibVLC()) using (var mediaPlayer = new MediaPlayer(libvlc)) { // Redirect log output to the console libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}"); // Create new media with HLS link var media = new Media(libvlc, $"https://1-{endpoint}/hls/{_channelName}/index.m3u8", FromType.FromLocation); // Define stream output options. // In this case stream to a file with the given path // and play locally the stream while streaming it. media.AddOption(":sout=#file{dst=" + destination + "}"); media.AddOption(":sout-keep"); var semaphore = new SemaphoreSlim(0, 1); mediaPlayer.EndReached += delegate(object o, EventArgs a) { semaphore.Release(); }; // Start recording mediaPlayer.Play(media); Console.WriteLine($"Recording in {destination}"); await semaphore.WaitAsync(); mediaPlayer.Stop(); } }
public MediaPlayer GetMediaPlayerForTrimming(string filePath, string outputPath, string startSec, string endSec) { var lib = new LibVLC($"--start-time={startSec}", $"--stop-time={endSec}"); var media = new Media(lib, filePath); var option = ":sout=#transcode{scodec=none}:std{access=file{overwrite},mux=mp4,dst='" + outputPath + "'}"; media.AddOption(option); var mediaPlayer = new MediaPlayer(media); return(mediaPlayer); }
public Form1() { InitializeComponent(); // Record in a file "record.ts" located in the bin folder next to the app var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var destination1 = Path.Combine(currentDirectory, "record.ts"); var destination2 = Path.Combine(currentDirectory, "record2.ts"); var destination3 = Path.Combine(currentDirectory, "record3.ts"); // this will load the native libvlc library (if needed, depending on the platform). Core.Initialize(); // instanciate the main libvlc object _libvlc = new LibVLC(); // Redirect log output to the console _libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}"); // Create new media with HLS link Media media = new Media(_libvlc, VIDEO_URL1, FromType.FromLocation); Media media2 = new Media(_libvlc, VIDEO_URL2, FromType.FromLocation); Media media3 = new Media(_libvlc, VIDEO_URL3, FromType.FromLocation); // Define stream output options. // In this case stream to a file with the given path and play locally the stream while streaming it. media.AddOption(":sout=#transcode{scodec=none}:duplicate{dst=display,dst=std{access=file,mux=ts,dst='" + destination1 + "'}}"); media.AddOption(":no-sout-all:sout-keep"); media2.AddOption(":sout=#transcode{scodec=none}:duplicate{dst=display,dst=std{access=file,mux=ts,dst='" + destination2 + "'}}"); media2.AddOption(":no-sout-all:sout-keep"); media3.AddOption(":sout=#transcode{scodec=none}:duplicate{dst=display,dst=std{access=file,mux=ts,dst='" + destination3 + "'}}"); media3.AddOption(":no-sout-all:sout-keep"); // Start recording videoView1.MediaPlayer = new MediaPlayer(_libvlc); videoView1.MediaPlayer.Play(media); videoView2.MediaPlayer = new MediaPlayer(_libvlc); videoView2.MediaPlayer.Play(media2); videoView3.MediaPlayer = new MediaPlayer(_libvlc); videoView3.MediaPlayer.Play(media3); }
protected override void OnResume() { base.OnResume(); Core.Initialize(); var _libVLC = new LibVLC(); var _mediaPlayer = new MediaPlayer(_libVLC); var _videoView = FindViewById <VideoView>(Resource.Id.videoView1); _videoView.MediaPlayer = _mediaPlayer; var mediaUri = Android.Net.Uri.Parse("rtsp://*****:*****@190.117.54.230:554/ISAPI/Streaming/channels/101"); var m = new Media(_libVLC, mediaUri.ToString(), FromType.FromPath); var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding = true; //m.AddOption(":fullscreen"); m.AddOption(":codec=avcodec"); m.AddOption(configuration); m.AddOption(":file-caching=1500"); _mediaPlayer.Media = m; _videoView.MediaPlayer.Play(m); }
protected override void OnResume() { base.OnResume(); _videoView = new VideoView(this); AddContentView(_videoView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)); var media = new Media(_videoView.LibVLC, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation); var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding(); media.AddOption(configuration); _videoView.MediaPlayer.Play(media); }
private byte[] ReadAsync(string file) { FileInfo f = new FileInfo(file); if (!f.Exists) { Console.WriteLine("文件不存在..."); return(none); } lock (this) { } using (var libvlc = new LibVLC()) using (var mediaPlayer = new MediaPlayer(libvlc)) { Console.WriteLine("创建VLC播放器成功."); var processingCancellationTokenSource = new CancellationTokenSource(); mediaPlayer.Stopped += (s, e) => processingCancellationTokenSource.CancelAfter(1); //Stream s = new FileStream(file, FileMode.Open); // Create new media using var media = new Media(libvlc, new Uri(file)); media.AddOption(":no-audio"); // Set the size and format of the video here. mediaPlayer.SetVideoFormat("RV32", Width, Height, Pitch); mediaPlayer.SetVideoCallbacks(Lock, null, Display); // Start recording mediaPlayer.Play(media); //try var data = ProcessThumbnailsAsync("E:\\", processingCancellationTokenSource.Token); mediaPlayer.Stop(); //catch (OperationCanceledException) //{ } return(data); } return(none); }
public Media GetMedia(StartupConfiguration startupConfiguration) { var media = new Media(LibVLC, startupConfiguration.FilePath); if (Settings.UseHardwareAcceleration) { var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding = true; media.AddOption(configuration); } //if (!startupConfiguration.AutoPlay) //{ // media.AddOption(":start-paused"); //} if (!string.IsNullOrWhiteSpace(Settings.MediaOption)) { try { media.AddOption(Settings.MediaOption); } catch (Exception ex) { App.DebugLog(ex.ToString()); } } if (startupConfiguration.IsFileSubtitlesSelected) { media.AddOption(startupConfiguration.SelectedSubtitlesFile.EncodingOption); } //media.AddOption(":freetype-font=/storage/emulated/0/Download/arial.ttf"); //media.AddOption(":freetype-color=16711680"); foreach (var sub in startupConfiguration.ExternalSubtitles) { media.AddSlave(MediaSlaveType.Subtitle, 0, sub.FileUrl); } return(media); }
public MediaPlayer GetMediaPlayer(string filePath) { var media = new Media(LibVLC, filePath); if (Settings.UseHardwareAcceleration) { var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding = true; media.AddOption(configuration); } var mediaPlayer = new MediaPlayer(media); return(mediaPlayer); }
protected override void OnResume() { base.OnResume(); _mVideoView = new VideoView(this); var lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); _mVideoWrapper.AddView(_mVideoView, lp); var media = new Media(_mVideoView.LibVLC, "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov", Media.FromType.FromLocation); var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding(); media.AddOption(configuration); _mVideoView.MediaPlayer.Play(media); }
public MainWindow() { InitializeComponent(); // this will load the native libvlc library (if needed, depending on the platform). Core.Initialize(); // instantiate the main libvlc object _libvlc = new LibVLC(); VideoView.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc); var rtsp1 = new Media(_libvlc, VIDEO_URL, FromType.FromLocation); //Create a media object and then set its options to duplicate streams - 1 on display 2 as RTSP rtsp1.AddOption(":sout=#duplicate" + "{dst=display{noaudio}," + "dst=rtp{mux=ts,dst=192.168.0.110,port=8080,sdp=rtsp://192.168.0.110:8080/go.sdp}"); //The address has to be your local network adapters addres not localhost VideoView.MediaPlayer.Play(rtsp1); VideoView1.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(_libvlc); VideoView1.MediaPlayer.Mute = true; VideoView1.MediaPlayer.Play(new Media(_libvlc, "rtsp://192.168.0.110:8080/go.sdp", FromType.FromLocation)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.vlc_view); string link = Intent.GetStringExtra("link"); source_link = Intent.GetStringExtra("source_link"); _videoView = new VideoView(this); AddContentView(_videoView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)); var media = new Media(_videoView.LibVLC, link, Media.FromType.FromLocation); var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding(); media.AddOption(configuration); _videoView.MediaPlayer.Play(media); }
static async Task Main(string[] args) { // Extract thumbnails in the "preview" folder next to the app var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var destination = Path.Combine(currentDirectory, "preview"); Directory.CreateDirectory(destination); // Load native libvlc library Core.Initialize(); using (var libvlc = new LibVLC()) using (var mediaPlayer = new MediaPlayer(libvlc)) { // Listen to events var processingCancellationTokenSource = new CancellationTokenSource(); mediaPlayer.Stopped += (s, e) => processingCancellationTokenSource.CancelAfter(1); // Create new media var media = new Media(libvlc, new Uri("http://www.caminandes.com/download/03_caminandes_llamigos_1080p.mp4")); media.AddOption(":no-audio"); // Set the size and format of the video here. mediaPlayer.SetVideoFormat("RV32", Width, Height, Pitch); mediaPlayer.SetVideoCallbacks(Lock, null, Display); // Start recording mediaPlayer.Play(media); // Waits for the processing to stop try { await ProcessThumbnailsAsync(destination, processingCancellationTokenSource.Token); } catch (OperationCanceledException) { } Console.WriteLine("Done. Press any key to exit."); Console.ReadKey(); } }
protected override void OnResume() { base.OnResume(); Core.Initialize(); _libVLC = new LibVLC(); _mediaPlayer = new MediaPlayer(_libVLC); _videoView = new VideoView(this) { MediaPlayer = _mediaPlayer }; AddContentView(_videoView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)); var media = new Media(_libVLC, "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", FromType.FromLocation); var configuration = new MediaConfiguration(); configuration.EnableHardwareDecoding(); media.AddOption(configuration); _videoView.MediaPlayer.Play(media); }
private void btnPlayMedia_Click(object sender, EventArgs e) { log("btnPlayMedia_Click"); mMediaInput = new MyMediaInput(); MP4Streamer mp4Streamer = new MP4Streamer(mMediaInput); mp4StreamerThread = new Thread(mp4Streamer.DoWork); mp4StreamerThread.Start(); mMedia = new Media(libVLC, mMediaInput); MediaConfiguration mediaConfiguration = new MediaConfiguration(); mediaConfiguration.EnableHardwareDecoding = true; mediaConfiguration.NetworkCaching = 150; mMedia.AddOption(mediaConfiguration); /*mMedia.AddOption(":clock-jitter=0"); * mMedia.AddOption(":clock-synchro=0");*/ videoView.MediaPlayer.Play(mMedia); }
private void Form1_Load(object sender, EventArgs e) { var mess_form = ""; //define a variable message winform string[] passedInArgs = Environment.GetCommandLineArgs(); if (passedInArgs.Contains("/0")) //this will load rtsp { var stream_CCTV_SENA_OFFICE = "rtsp://*****:*****@175.139.231.133:554/Streaming/Channels/1"; //public IP for testing //var stream_CCTV = "rtsp://*****:*****@10.20.5.23:554/Streaming/Channels/1";//need VPN //var stream_file = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"; var mmm = new Media(_libVLC, stream_CCTV_SENA_OFFICE, FromType.FromLocation); //mmm.AddOption($":rtsp-tcp"); //mmm.AddOption($":rtsp-tcp"); mmm.AddOption($":network-caching=1200"); _mp.Play(mmm); } if (passedInArgs.Contains("/1"))//this won't load rtsp { mess_form = "This VMS doesn't have CCTV. You can safely close this window when it appears"; MessageBox.Show(mess_form); } }
static async Task Main(string[] args) { var filename = "video1.mp4"; var filename2 = "video2.mp4"; Core.Initialize(); var libvlc = new LibVLC("--verbose=2"); // mosaic 1 var media = new Media(libvlc, filename); media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=1,height=200,width=300}}"); //media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=1,height=200,width=300},dst=display}"); var mp1 = new MediaPlayer(media); media.Dispose(); // mosaic 2 media = new Media(libvlc, filename2); media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=2,height=200,width=300}}"); //media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=2,height=200,width=300},dst=display}"); var mp2 = new MediaPlayer(media); media.Dispose(); // mosaic 3 media = new Media(libvlc, filename); media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=3,height=200,width=300}}"); //media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=3,height=200,width=300},dst=display}"); var mp3 = new MediaPlayer(media); media.Dispose(); // mosaic 4 media = new Media(libvlc, filename2); media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=4,height=200,width=300}}"); //media.AddOption(":sout=#duplicate{dst=mosaic-bridge{id=4,height=200,width=300},dst=display}"); var mp4 = new MediaPlayer(media); media.Dispose(); // mosaic out media = new Media(libvlc, "cone.png"); //var soutOption = ":sout=#transcode{sfilter=mosaic{keep-picture,width=600,height=400,cols=2,rows=2},vcodec=mp4v,vb=20000,acodec=none,fps=10,scale=1}:file{dst=lol.ts,mux=ts}"; var soutOption = ":sout=#transcode{sfilter=mosaic{keep-picture,width=600,height=400,cols=2,rows=2},vcodec=mp4v,vb=20000,acodec=none,fps=10,scale=1}:duplicate{dst=file{dst=lol.ts,mux=ts},dst=display}"; media.AddOption(soutOption); media.AddOption(":image-duration=-1"); var mpOut = new MediaPlayer(media); media.Dispose(); mpOut.Play(); mp1.Play(); mp2.Play(); mp3.Play(); mp4.Play(); await Task.Delay(10000); mp1.Stop(); mp2.Stop(); mp3.Stop(); mp4.Stop(); mpOut.Stop(); mp1.Dispose(); mp2.Dispose(); mp3.Dispose(); mp4.Dispose(); mpOut.Dispose(); libvlc.Dispose(); }
private void ConnectHalovisionDevice() { try { Core.Initialize(); if (txtDeviceURL.Text.Contains("://")) { libvlc = new LibVLC(enableDebugLogs: true); libvlc.SetLogFile($"{lucidScribeDataPath}\\vlc.log"); using (Media media = new Media(libvlc, txtDeviceURL.Text, FromType.FromLocation)) { player = new MediaPlayer(media); player.Hwnd = pbDisplay.Handle; player.Play(); } return; } libvlc = new LibVLC(enableDebugLogs: false, "--rtsp-tcp"); // Use TCP messaging. videoChannel = new TcpMessagingSystemFactory().CreateDuplexOutputChannel("tcp://" + txtDeviceURL.Text + ":8093/"); videoChannel.ResponseMessageReceived += OnResponseMessageReceived; // Use unique name for the pipe. string aVideoPipeName = Guid.NewGuid().ToString(); // Open pipe that will be read by VLC. videoPipe = new NamedPipeServerStream(@"\" + aVideoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 65528); ManualResetEvent vlcConnectedPipe = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(x => { videoPipe.WaitForConnection(); // Indicate VLC has connected the pipe. vlcConnectedPipe.Set(); }); // VLC connects the pipe and starts playing. using (Media media = new Media(libvlc, @"stream://\\\.\pipe\" + aVideoPipeName, FromType.FromLocation)) { // Setup VLC so that it can process raw h264 data media.AddOption(":demux=H264"); player = new MediaPlayer(media); player.Hwnd = pbDisplay.Handle; // Note: This will connect the pipe and read the video. player.Play(); } // Wait until VLC connects the pipe so that it is ready to receive the stream. if (!vlcConnectedPipe.WaitOne(5000)) { throw new TimeoutException($"VLC did not open connection with {txtDeviceURL.Text}."); } // Open connection with service running on Raspberry. videoChannel.OpenConnection(); } catch (Exception ex) { MessageBox.Show(ex.Message, "LucidScribe.InitializePlugin()", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Init() { _mediaPlayer?.Dispose(); _videoFormat = VideoFormat; _lockCB = LockVideo; _unlockCB = UnlockVideo; _displayCB = DisplayVideo; //_cleanupVideoCB = CleanupVideo; _audioSetup = AudioSetup; _processAudio = ProcessAudio; _cleanupAudio = CleanupAudio; _pauseAudio = PauseAudio; _resumeAudio = ResumeAudio; _flushAudio = FlushAudio; _drainAudio = DrainAudio; string overrideURL = null; if (_camera != null) { switch (_camera.Camobject.settings.sourceindex) { case 9: var od = _camera.ONVIFDevice; if (od != null) { var ep = od.StreamEndpoint; if (ep != null) { var u = ep.Uri.Uri; overrideURL = u; } } break; } } FromType ftype = FromType.FromLocation; Seekable = false; var murl = overrideURL ?? Source; if (string.IsNullOrEmpty(murl)) { throw new Exception("Video source is empty"); } try { var p = Path.GetFullPath(overrideURL ?? Source); Seekable = !string.IsNullOrEmpty(p); if (Seekable) { ftype = FromType.FromPath; } } catch (Exception) { Seekable = false; } using (var media = new Media(LibVLC, murl, ftype)) { Duration = Time = 0; foreach (var opt in _options) { media.AddOption(opt); } _mediaPlayer = new MediaPlayer(media); _mediaPlayer.SetVideoFormatCallbacks(_videoFormat, null);// _cleanupVideoCB); _mediaPlayer.SetVideoCallbacks(_lockCB, _unlockCB, _displayCB); _mediaPlayer.TimeChanged += _mediaPlayer_TimeChanged; _mediaPlayer.EnableHardwareDecoding = false; _mediaPlayer.SetAudioFormatCallback(_audioSetup, _cleanupAudio); _mediaPlayer.SetAudioCallbacks(_processAudio, _pauseAudio, _resumeAudio, _flushAudio, _drainAudio); _mediaPlayer.EncounteredError += (sender, e) => { ErrorHandler?.Invoke("VLC Error"); _res = ReasonToFinishPlaying.VideoSourceError; }; _mediaPlayer.EndReached += (sender, e) => { _res = ReasonToFinishPlaying.VideoSourceError; }; _mediaPlayer.Stopped += (sender, e) => { Logger.LogMessage("VLC stopped"); Task.Run(() => { Debug.WriteLine("CLEANUP"); IsRunning = false; _stopping = false; _stopped?.Set(); PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(_res)); AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(_res)); }); }; } _lastTimeUpdate = DateTime.UtcNow; _mediaPlayer.Play(); }
public void AddOption() { var media = new Media(new LibVLC(), new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate)); media.AddOption("-sout-all"); }