樹莓派zero w VLC視頻傳輸 C#上位機實時顯示

上位機實現的功能:播放、停止、截屏保存

延時:由局域網內wifi網速而定,1~2s 或 4~5s

效果展示:

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

登陸以後輸入如下命令:根據用戶需求,修改IP和端口(下面的IP和端口 對應的樹莓派的)

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);
                }
            }
        }

    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章