在C#应用程序中显示tcpvideo流(来自FFPLAY / FFMPEG)

我尝试让我的Parrot AR Drone 2.0与windows机器配合使用。

我有一个简单的C#应用​​程序来控制它 – 但现在我想要我的应用程序内的video流。

如果我执行ffplay tcp://192.168.1.1:5555它会连接到video流并显示一个带video的窗口。

我如何在我的应用程序中获得此video? 比如,一个简单的“框架”或“图像”充满了这些内容?

我从来没有用C#做过那么多,所以任何帮助都会很棒。

您可以启动ffplay进程,然后启动PInvoke SetParent以将播放器窗口放置在窗体内,并使用MoveWindow来定位它。

为此,您需要定义以下内容。

 [DllImport("user32.dll", SetLastError = true)] private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 

然后你可以使用两个本机方法,如此。

 // start ffplay var ffplay = new Process { StartInfo = { FileName = "ffplay", Arguments = "tcp://192.168.1.1:5555", // hides the command window CreateNoWindow = true, // redirect input, output, and error streams.. RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false } }; ffplay.EnableRaisingEvents = true; ffplay.OutputDataReceived += (o, e) => Debug.WriteLine(e.Data ?? "NULL", "ffplay"); ffplay.ErrorDataReceived += (o, e) => Debug.WriteLine(e.Data ?? "NULL", "ffplay"); ffplay.Exited += (o, e) => Debug.WriteLine("Exited", "ffplay"); ffplay.Start(); Thread.Sleep(200); // you need to wait/check the process started, then... // child, new parent // make 'this' the parent of ffmpeg (presuming you are in scope of a Form or Control) SetParent(ffplay.MainWindowHandle, this.Handle); // window, x, y, width, height, repaint // move the ffplayer window to the top-left corner and set the size to 320x280 MoveWindow(ffplay.MainWindowHandle, 0, 0, 320, 280, true); 

ffplay进程的标准输出,您通常在命令窗口中看到的文本是通过ErrorDataReceived处理的。 在-loglevel-loglevel的参数中将-loglevel设置为fatal的类似允许您减少引发的事件数量,并允许您仅处理真正的故障。

你试过用媒体播放器流媒体吗? 只需从表单上的工具箱中添加控件,然后将以下代码添加到form.cs

  private void Form1_Load(object sender, EventArgs e) { axWindowsMediaPlayer1.URL = "your URL"; } } 

以下链接中的详细信息

 http://msdn.microsoft.com/en-us/library/bb383953%28v=vs.90%29.aspx 
 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Drawing.Text; using System.Text.RegularExpressions; using System.Configuration; using Microsoft.Win32; using System.Windows.Forms.VisualStyles; namespace FfplayTest { public partial class Form1 : Form { [DllImport("user32.dll", SetLastError = true)] private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); [DllImport("user32.dll")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", EntryPoint = "SetWindowPos")] public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags); public Form1() { InitializeComponent(); Application.EnableVisualStyles(); this.DoubleBuffered = true; } private void Form1_Load(object sender, EventArgs e) { } public Process ffplay = new Process(); private void xxxFFplay() { ffplay.StartInfo.FileName = "ffplay.exe"; string _argString = "-fflags nobuffer \"rtsp://admin:admin@192.168.0.163/live0.264\" -x 640 -y 480"; string _newArgString = _argString.Replace("\",\"", ";"); ffplay.StartInfo.Arguments = _newArgString; ffplay.StartInfo.CreateNoWindow = true; ffplay.StartInfo.RedirectStandardOutput = true; ffplay.StartInfo.UseShellExecute = false; ffplay.EnableRaisingEvents = true; ffplay.OutputDataReceived += (o, e) => Debug.WriteLine(e.Data ?? "NULL", "ffplay"); ffplay.ErrorDataReceived += (o, e) => Debug.WriteLine(e.Data ?? "NULL", "ffplay"); ffplay.Exited += (o, e) => Debug.WriteLine("Exited", "ffplay"); ffplay.Start(); IntPtr intPtr = ffplay.MainWindowHandle; Thread.Sleep(200); // you need to wait/check the process started, then... // child, new parent // make 'this' the parent of ffmpeg (presuming you are in scope of a Form or Control) SetParent(ffplay.MainWindowHandle, this.Handle); // window, x, y, width, height, repaint // move the ffplayer window to the top-left corner and set the size to 320x280 MoveWindow(ffplay.MainWindowHandle, 0, 0, 320, 280, true); } private void button1_Click(object sender, EventArgs e) { xxxFFplay(); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { try { ffplay.Kill(); } catch { } } } } 

我的代码是这样的,它是如何加载ffplay但不移动到面板或不将它定位给给定