首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Vlc.DotNet在Windows Forms c#中流式传输RTSP摄像头源

如何使用Vlc.DotNet在Windows Forms c#中流式传输RTSP摄像头源
EN

Stack Overflow用户
提问于 2018-05-18 21:15:32
回答 1查看 6.6K关注 0票数 2

我遵循了这个link的说明,将Vlc.DotNet库(.Core.Core.Interops.Forms.Wpf)添加到我的项目解决方案中。

我还添加了3.0.0版本的VideoLAN.LibVLC.Windows库。

我在表单中添加了一个vlcControl,这就是生成的Designer.cs

代码语言:javascript
复制
// 
// 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;

我在属性中添加了一个虚拟的VlcLibDirectory,这样我以后就可以修改它了。

我的vlcLib的x86版本的路径是:E:\testLouka\dansMaCamera2.0\dansMaCamera2.0\libvlc\win-x86

我尝试使用以下代码从RTSP流url获取视频提要:

代码语言:javascript
复制
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);
   }
}

RTSP变量返回一个类似于"rtsp://admin:admin123@190.19.191.19/Stream0“的m_stream.URL链接。

我的表单出现了,但是我的vlcController没有显示任何东西...

我看了https://github.com/ZeBobo5/Vlc.DotNet的维基但我被卡住了。

我在这里做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-31 03:45:57

您所要做的就是向窗体中添加一个vlcControl,并向其VlcLibDirectoryNeeded事件中添加一些代码。

代码语言:javascript
复制
/// <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流!

代码语言:javascript
复制
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
}

如果流链接正常,您应该能够在Media->Open Network Stream...下的VLC应用程序上流式传输它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50412201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档