Ste*_*ers 3 c# handles winforms
使用此代码:在C#应用程序中显示tcp视频流(来自FFPLAY/FFMPEG)
我成功地在c#winform中抓取了FFmpeg输出.通过更改args也可以直接播放视频(无需流媒体)...这里是我的完整(简短)代码:
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 xFFplay
{
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);
//Process ffplay = null;
public Form1()
{
InitializeComponent();
Application.EnableVisualStyles();
this.DoubleBuffered = true;
}
public Process ffplay = new Process();
private void xxxFFplay()
{
// start ffplay
/*var ffplay = new Process
{
StartInfo =
{
FileName = "ffplay.exe",
Arguments = "Revenge.mp4",
// hides the command window
CreateNoWindow = true,
// redirect input, output, and error streams..
//RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false
}
};
* */
//public Process ffplay = new Process();
ffplay.StartInfo.FileName = "ffplay.exe";
ffplay.StartInfo.Arguments = "Revenge.mp4";
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();
Thread.Sleep(500); // 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 { }
}
}
}Run Code Online (Sandbox Code Playgroud)
不幸的是,FFmpeg输出是标准的BorderType,但我需要让它无边框,或者至少没有标题栏和最小化/最大化/关闭按钮.
我真的不知道Handles,但我可以看到我有一个完整的窗口句柄:
MoveWindow(ffplay.MainWindowHandle, 0, 0, 320, 280, true);
Run Code Online (Sandbox Code Playgroud)
那么,有一种简单的方法来删除FFplay边框?
感谢您的耐心,我从Mplayer移动(超级易于封装在WinForms中)因为它似乎与某些文件不太兼容......
编辑:我已经检查了FFplay选项,但没有'无边框'选项.
无法更改边框样式?没关系,我们把它隐藏起来吧!!
我通过处理面板解决了...是的面板而不是表单...负位置工作完成;-)我们现在可以让我们的媒体播放器无边框(通过完成面板)或者我们可以画一个很酷的用 Photoshop 制作个性化边框:-)
SetParent(ffplay.MainWindowHandle, this.panel1.Handle);
MoveWindow(ffplay.MainWindowHandle, -5, -30, 320, 280, true);
Run Code Online (Sandbox Code Playgroud)
我知道,这只是一个技巧,但结果与主要问题完全一致!
| 归档时间: |
|
| 查看次数: |
6951 次 |
| 最近记录: |