【问题标题】:How can I send command "q" to FFMPEG with c#如何使用 c# 将命令“q”发送到 FFMPEG
【发布时间】:2015-09-16 01:31:25
【问题描述】:

如何发送命令“q”以使用 C# 处理打开的 FFMPEG?在下面看我的代码:

        var p = Process.GetProcessesByName("ffmpeg").FirstOrDefault();

        if (p != null)
        {
            //Here my test
            p.StandardInput.Write("q");

        }

我在下面出现了这个错误:

【问题讨论】:

  • 我试过这个并得到这个错误:StandardIn não foi redirecionado。
  • 我认为这行不通,因为您没有“拥有”其标准输入的句柄,因为您没有启动该过程...无论如何请参阅stackoverflow.com/a/32505963/32453

标签: c# ffmpeg


【解决方案1】:

您可以使用 user32 api 的SendMessage 调用。

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,          string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

 static void Send(string message)
 {
 Process[] notepads = Process.GetProcessesByName("notepad");
 if (notepads.Length == 0)
 return;
 if (notepads[0] != null)
 {
 IntPtr child = FindWindowEx(notepads[0].MainWindowHandle, new   IntPtr(0), "Edit", null);
 SendMessage(child, 0x000C, 0, message);
 }

根据您的需要更改它。我不确定它是否适合您的情况,但尝试总是好的。

祝你好运。

【讨论】:

    猜你喜欢
    • 2013-07-14
    • 2011-04-21
    • 2019-11-03
    • 2018-09-09
    • 1970-01-01
    • 2013-11-05
    • 2018-10-27
    • 2020-01-28
    • 1970-01-01
    相关资源
    最近更新 更多