使用MediaElement在UWP中播放UDP H.264字节流

时间:2018-12-29 01:02:51

标签: c# uwp video-streaming h.264

我正在从Tello无人机通过UDP接收H.264流。我想在UWP应用中实时显示视频。我尝试写入分配给MediaSource的MemoryStream,该Source分配给MediaElement。不开心

namespace TEST
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-93HPJ15\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
        public Form1()
        {
            InitializeComponent();
        }
        SqlCommand cmd;
        SqlDataAdapter da;
        DataSet ds;
        private int i;
        private IFormatProvider async;

        private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection(@"Data Source=DESKTOP-93HPJ15\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
            cmd = new SqlCommand("select * from Producten", con);
            da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {

                comboBox1.Items.Add(ds.Tables[0].Rows[i][0] + " | " + ds.Tables[0].Rows[i][1] + " | € " + ds.Tables[0].Rows[i][2]);

            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox1.Items.Add(comboBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string revomeItemFromList = listBox1.Text;
            listBox1.Items.Remove(revomeItemFromList);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}

几年前,我使用DirectShow。我当时在看Media Foundation,但好像这些东西早在多年前就已弃用。

在这一点上,我不知所措。如何获得UDP流H.264以在UWP应用中显示?

1 个答案:

答案 0 :(得分:1)

UWP MediaElement在其后端具有Media Foundation(Media Foundation信誉良好,它是Windows中包括UWP的当前低级媒体API)。但是,您要寻找的协议没有内置支持。您应该开发一个集成层,将您拥有的数据转换为MediaElement可以使用的数据。

例如,它可能是一个协议处理程序,因为您基本上想注入H.264数据并以Media Foundation友好的方式对其进行格式化,以便MediaElement可以应用标准解码器,并通过Media Foundation管道将内容路由到表示。就使用的API而言,Media Extensions presentation的第12页应该是一个很好的参考点。

或者它也可能是一个更简单的媒体流源,在Building video and audio streaming apps presentation中的幻灯片5、20中进行了解释。