欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

树莓派zero w VLC视频传输 C#上位机实时显示

程序员文章站 2022-07-14 18:47:47
...

上位机实现的功能:播放、停止、截屏保存

延时:由局域网内wifi网速而定,1~2s 或 4~5s

效果展示:

树莓派zero w VLC视频传输 C#上位机实时显示

硬件使用:树莓派zero w + picamera

登陆以后输入如下命令:根据用户需求,修改IP和端口(下面的IP和端口 对应的树莓派的)

树莓派zero w VLC视频传输 C#上位机实时显示

raspivid -o - -t 0 -w 640 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264 &> /dev/null
http://192.168.2.243:8082/

C#上位机代码:

using System;
using System.Windows.Forms;

using System.Reflection;
using System.IO;


namespace VLC_test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        private void VlcControl1_VlcLibDirectoryNeeded(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
        {
            var currentAssembly = Assembly.GetEntryAssembly();
            var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
            // Default installation path of VideoLAN.LibVLC.Windows
            var v = IntPtr.Size == 4 ? "win-x86" : "win-x64";  //自己可以在项目属性 -> 生成 -> 平台目标,选择x86或者x64,注意勾选下面的首选32位
            e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", v));
          
            // vlcControl1.Dock = DockStyle.Fill;//全屏显示

            if (!e.VlcLibDirectory.Exists)
            {
                var folderBrowserDialog = new 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);
                }
            }
        }
        string[] options = { ":network-caching=10" };//设置延时时间;:network-caching=300"意思是延迟300毫秒, 应该和网速也有关系
        private void button1_Click(object sender, EventArgs e)
        {
            vlcControl1.Play("http://192.168.2.243:8090/", options);//can test with rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov            
        }

        private void button_stop_Click(object sender, EventArgs e)
        {
            vlcControl1.Stop();
        }

        private void button_capture_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Filter = "jpg文件|*.jpg|peg文件| *.jpg";
                if (sfd.ShowDialog(this) == DialogResult.OK)
                {
                    vlcControl1.TakeSnapshot(sfd.FileName);
                }
            }
        }

    }

}

 

相关标签: 浩瀚物联 C#