how to capture with libvlcnet for .net

This forum is about all development around libVLC.
carlesls
Blank Cone
Blank Cone
Posts: 24
Joined: 17 Jun 2011 13:42

how to capture with libvlcnet for .net

Postby carlesls » 04 Jul 2011 17:54

I just wonder how I could capture frames with the libvlcnet. I get an idea about how to do it. The VlcPlayerControl vlcpc have a methode that allows it:

vlcpc.DrawToBitmap(bmp , rbmp); // but I do not know how it works. or how I can visualize this bmp.

Code: Select all

/* * Created by SharpDevelop. * User: carlesls * Date: 23/06/2011 * Time: 9:38 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; using Microsoft.Win32; using vlc_bool_t = System.Int32; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DZ.MediaPlayer.Io; using DZ.MediaPlayer.Vlc.WindowsForms; using DZ.MediaPlayer.Common; using DZ.MediaPlayer.Vlc.Windows; namespace libvlcprojectemagic { partial class MainForm { Button b1; Button b2; Button b3; Button b4; Panel p1; PictureBox pb; VlcPlayerControl vlcpc; /// <summary> /// Designer variable used to keep track of non-visual components. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Disposes resources used by the form. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); MessageBox.Show(components.Components.ToString()); } } base.Dispose(disposing); } /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Text = "MainForm"; this.Name = "MainForm"; this.b1 = new Button(); this.b2 = new Button(); this.b3 = new Button(); this.b4 = new Button(); this.vlcpc = new VlcPlayerControl(); pb = new PictureBox(); this.b1.Text = "butó 1"; this.b2.Text = "butó 2"; this.b3.Text = "butó 3"; this.b4.Text = "butó 4"; this.SuspendLayout(); this.Controls.Add(this.b1); this.Controls.Add(this.b2); this.Controls.Add(this.b3); this.Controls.Add(this.b4); this.Controls.Add(this.pb); this.Controls.Add(this.vlcpc); this.b1.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b1.Location = new Point(0 , this.ClientSize.Height * 2 / 3 ); this.b2.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b2.Location = new Point(this.ClientSize.Width/2 , this.ClientSize.Height * 2 / 3); this.b3.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b3.Location = new Point(0 , this.ClientSize.Height * 5 / 6 ); this.b4.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b4.Location = new Point(this.ClientSize.Width/2 , this.ClientSize.Height * 5 / 6); this.vlcpc.Initialize(); this.vlcpc.Volume = 0; this.vlcpc.Visible = true; this.vlcpc.Location = new Point(0,0); this.vlcpc.Size = new Size(this.ClientSize.Width, this.ClientSize.Height * 1 / 3); this.vlcpc.Size = new Size(this.ClientSize.Width, this.ClientSize.Height * 1 / 3); this.pb.Location = new Point(0, this.ClientSize.Height * 1 / 3 ); this.pb.Size = new Size(this.ClientSize.Width,this.ClientSize.Height * 1 / 3); this.Resize += new EventHandler(form_Resize); this.Move += new EventHandler(form_Move); this.MouseEnter += new EventHandler(form_Entered); this.Shown += new EventHandler(form_Shown); this.b1.Click += new EventHandler( b1_Click); this.b2.Click += new EventHandler( b2_Click); } private void b1_Click(object sender, EventArgs e) { //amb aquesta funció s'inicial el proces del video Console.WriteLine("boto 1 clicat"); try { if((this.vlcpc.IsDisposed)||(this.vlcpc == null)) { this.vlcpc = new VlcPlayerControl(); this.vlcpc.Initialize(); this.vlcpc.Visible = true; } if (!this.vlcpc.IsInitialized) { this.vlcpc.Initialize(); } MediaInput input = new MediaInput( MediaInputType.NetworkStream, "rtsp://admin:admin@192.168.1.44:8557/video.mp4"); this.vlcpc.Visible = true; if ((VlcPlayerControlState.IDLE == this.vlcpc.State) || (VlcPlayerControlState.PAUSED == this.vlcpc.State)) { Rectangle rbmp = new Rectangle(); Bitmap bmp= new Bitmap(this.ClientSize.Width,this.ClientSize.Height * 1 / 3); rbmp.Location = new Point(0,0); rbmp.Size = new Size(this.ClientSize.Width,this.ClientSize.Height * 1 / 3); this.vlcpc.DrawToBitmap(bmp , rbmp); this.pb.Image = bmp; this.vlcpc.Play(input); } } catch (Exception e1) { MessageBox.Show("Carles Lloret: "+e1.ToString()); } } private void b2_Click(object sender, EventArgs e) { //amb aquesta funció s'inicial el proces del video Console.WriteLine("boto 2 clicat"); try { MediaInput input = new MediaInput( MediaInputType.NetworkStream, "rtsp://admin:admin@192.168.1.44:8557/video.mp4"); if (!this.vlcpc.IsInitialized) { this.vlcpc.Initialize(); } if(((VlcPlayerControlState.PAUSED == this.vlcpc.State)|| (VlcPlayerControlState.PLAYING == this.vlcpc.State))&&(!this.vlcpc.IsDisposed) ) { Rectangle rbmp = new Rectangle(); Bitmap bmp= new Bitmap(this.ClientSize.Width,this.ClientSize.Height / 3); rbmp.Location = new Point(0,0); rbmp.Size = new Size(this.ClientSize.Width,this.ClientSize.Height * 1 / 3); this.vlcpc.DrawToBitmap(bmp , rbmp); this.pb.Image = bmp; this.vlcpc.Stop(); } } catch (Exception e2) { MessageBox.Show("Carles Lloret: "+e2.ToString()); } } private void form_Resize(object sender, EventArgs e) { this.recomposaForm(); } private void form_Move(object sender, EventArgs e) { this.recomposaForm(); } private void form_Entered(object sender, EventArgs e) { this.recomposaForm(); } private void form_Shown(object sender, EventArgs e) { this.recomposaForm(); } public void recomposaForm() { this.vlcpc.Location = new Point(0,0); this.vlcpc.Size = new Size(this.ClientSize.Width, this.ClientSize.Height * 1 / 3); this.pb.Location = new Point(0, this.ClientSize.Height * 1 / 3 ); this.pb.Size = new Size(this.ClientSize.Width,this.ClientSize.Height * 1 / 3); Rectangle rbmp = new Rectangle(); Bitmap bmp= new Bitmap(this.ClientSize.Width,this.ClientSize.Height / 3); rbmp.Location = new Point(0,0); rbmp.Size = new Size(this.ClientSize.Width,this.ClientSize.Height * 1 / 3); this.vlcpc.DrawToBitmap(bmp , rbmp); this.pb.Image = bmp; this.b1.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b1.Location = new Point(0 , this.ClientSize.Height * 2 / 3 ); this.b2.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b2.Location = new Point(this.ClientSize.Width/2 , this.ClientSize.Height * 2 / 3); this.b3.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b3.Location = new Point(0 , this.ClientSize.Height * 5 / 6 ); this.b4.Size = new Size(this.ClientSize.Width/2 , this.ClientSize.Height/6); this.b4.Location = new Point(this.ClientSize.Width/2 , this.ClientSize.Height * 5 / 6); } } }
I also wonder if I could do it everything invisible. visible = false;

carlesls
Blank Cone
Blank Cone
Posts: 24
Joined: 17 Jun 2011 13:42

Re: how to capture with libvlcnet for .net

Postby carlesls » 07 Jul 2011 17:57

I know that vlc output is hard to convert to bitmap because of its format, but would it be possible?

Thank you, guys.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 9 guests