如何在 C# 中停止 ffmpeg 视频录制? [英] How to stop ffmpeg video recording in c#?

查看:88
本文介绍了如何在 C# 中停止 ffmpeg 视频录制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用 FFmpeg,它完美地启动和录制视频但是当我想停止它要求按q"时,我收到了 System.EntryPointNotFoundException 错误消息.

I am using FFmpeg in application and it start and record video perfectly but when I want to stop it ask for press "q", I got a System.EntryPointNotFoundException Error message.

如何从应用程序向处于运行状态的进程发送消息q"

How can I send message "q" to process which is in running state from application

    int key_q = 81; 

    [DllImport("user32.dll", EntryPoint = "postmessage")]       
    private static extern bool postmessage(IntPtr hwnd, uint msg, int wparam, int lparam);



    private void button_stop_Click(object sender, EventArgs e)
    {
          string process = "ffmpeg";

          Process[] pro = Process.GetProcessesByName("ffmpeg");

          pro[0].Refresh();

          IntPtr h = pro[0].MainWindowHandle;



          postmessage(h, 0x100, key_q, 0);


    }

推荐答案

如果您最初创建了该进程,您可以保留其标准输入的句柄并将其发送q"(可能还需要向其发送 "之后).

If you created the process initially, you can keep a handle to its stdin and send it "q" (possibly need to also send it a " " after).

如果没有,那么您可以通过某些第三方 .exe(或内部等效程序)向其发送一个 ctrl+c/ctrl+break 到其进程 ID.

If you didn't, then you could some third party .exe (or an internal equivalent) to send it a ctrl+c/ctrl+break to its process ID.

FFmpeg 没有窗口句柄,因为它是一个控制台应用程序,所以你不能用 PostMessage 等人向它发送击键.只能通过控制台信号(即 ctrl+c/break)

FFmpeg doesn't have a window handle since it's a console app, so you can't send it keystrokes with PostMessage et al. only through console signals (i.e. ctrl+c/break)

这篇关于如何在 C# 中停止 ffmpeg 视频录制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆