Как для потоковой передачи RTSP камеры в Windows Forms c # с помощью Vlc.DotNet - PullRequest
0 голосов
/ 18 мая 2018

Я следовал этой инструкции link , чтобы добавить библиотеки Vlc.DotNet (.Core, .Core.Interops, .Forms и .Wpf) в решение моего проекта.

Я также добавил версию 3.0.0 библиотеки VideoLAN.LibVLC.Windows.

Я добавил vlcControl в свою форму, и в результате получается Designer.cs:

// 
// vlcControl1
// 
this.vlcControl1.BackColor = System.Drawing.Color.Black;
this.vlcControl1.Location = new System.Drawing.Point(384, 357);
this.vlcControl1.Name = "vlcControl1";
this.vlcControl1.Size = new System.Drawing.Size(75, 23);
this.vlcControl1.Spu = -1;
this.vlcControl1.TabIndex = 6;
this.vlcControl1.Text = "vlcControl1";
this.vlcControl1.VlcLibDirectory = ((System.IO.DirectoryInfo)(resources.GetObject("vlcControl1.VlcLibDirectory")));
this.vlcControl1.VlcMediaplayerOptions = null;

I 'Мы добавили фиктивный VlcLibDirectory в свойства, чтобы я мог изменить его позже.

Путь к x86-версии моего vlcLib: E:\testLouka\dansMaCamera2.0\dansMaCamera2.0\libvlc\win-x86

Я попытался использовать следующий код, чтобы получитьпоток видео из URL-адреса потока RTSP:

public partial class Form1 : Form
{
   public Form1()
   {
       InitializeComponent();

       this.vlcControl1 = new VlcControl()
       {
           Name = "vlc1",
           Location = new Point(0, 0),
           Dock = DockStyle.Fill,
           VlcLibDirectory = new DirectoryInfo(Path.Combine("E:\\testLouka\\dansMaCamera2.0\\dansMaCamera2.0", "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64")),
           Spu = -1,
           VlcMediaplayerOptions = null,
           Enabled = true
       };
       string[] options = { ":network-caching=500" };

       vlcControl1.Play(new Uri(m_stream.URL), options);
   }
}

переменная m_stream.URL возвращает ссылку RTSP, выглядящую как "rtsp://admin:admin123@190.19.191.19/Stream0"

Моя форма отображается, но мой vlcController неничего не показывать ...

Я посмотрел https://github.com/ZeBobo5/Vlc.DotNet's вики, но я застрял ...

Что я здесь не так делаю?

1 Ответ

0 голосов
/ 30 июля 2018

Все, что вам нужно сделать, это добавить vlcControl к вашей форме и добавить некоторый код к событию VlcLibDirectoryNeeded.

/// <summary>
/// Looks for the vlc directory on the opening of the app
/// Opens a dialog if the libvlc folder is not found for the user to pick the good one
/// Folder for 32bits should be "libvlc\win-x86\" and "libvlc\win-x64\" for 64 bits
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void myVlcControl_VlcLibDirectoryNeeded(object sender, VlcLibDirectoryNeededEventArgs e)
{
    var currentAssembly = Assembly.GetEntryAssembly();
    var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;

    if (currentDirectory == null)
        return;
    if (IntPtr.Size == 4)
        e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x86\"));
    else
        e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x64\"));

    if (!e.VlcLibDirectory.Exists)
    {
        var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
        folderBrowserDialog.Description = "Select Vlc libraries folder.";
        folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
        folderBrowserDialog.ShowNewFolderButton = true;
        if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
        {
            e.VlcLibDirectory = new DirectoryInfo(folderBrowserDialog.SelectedPath);
        }
    }
}

Затем вы можете добавить какую-нибудь кнопку воспроизведения к вашемуСформируйте и воспроизведите любой желаемый поток RTSP!

private void btnPlay_Click(object sender, EventArgs e)
{
    myVlcControl.Play(MyStream.URL);//can test with rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov
}

Если ссылка на поток в порядке, вы сможете передавать ее в приложении VLC под Media->Open Network Stream...

...