with this code: Show a tcp video stream (from FFPLAY / FFMPEG) in an C# application
I successfully grabbed FFmpeg output inside my c# winform. By changing args is also possible to play video directly (without streaming)... here my complete (short) code:
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 { }
}
}
}
Unfortunately the FFmpeg output is with a standard BorderType but i need to have it borderless or, at least, without title bar and Minimize/Maximize/Close button.
I really don't know Handles but as i can see i have a complete handle to the window:
MoveWindow(ffplay.MainWindowHandle, 0, 0, 320, 280, true);
Well, there is an easy way to remove FFplay borders?
Thanks for your patience, i moved from Mplayer (super-easy to encapsulate inside WinForms) because it seem to be less compatible with certain files...
Edit: I allready checked for FFplay options but there is not a 'borderless' one.
-noborder
literally cites this Stackoverflow post and its "avoid ugly hacks" as the motivation for creating this flag. Thank you @Steve Rogers ! – Forgotten