如何将quit命令发送到当前的ffmpeg.exe

时间:2021-04-01 20:49:50
 var fpath="C:\\TVT_"+cur_date+"_"+cur_time+".avi";

 Components.utils.import("resource://gre/modules/FileUtils.jsm");

 var env = Components.classes["@mozilla.org/process/environment;1"]
                .getService(Components.interfaces.nsIEnvironment);
 var shell = new FileUtils.File(env.get("COMSPEC"));

 var args = ["/c", "cd.. & cd.. & C: & cd C:/ffmpeg/bin & record.bat "+fpath];

 var process = Components.classes["@mozilla.org/process/util;1"]
                 .createInstance(Components.interfaces.nsIProcess);
 process.init(shell);
 process.runAsync(args, args.length);
  1. I don't want to use taskkill.exe, /MIN, /C, /B, rather I want to quit this ffmpeg process
  2. 我不想使用taskkill.exe,/ MIN,/ C,/ B,而是我想退出这个ffmpeg进程

  3. I read about CMDOW but did not find cmdow.exe inside system32 directory.
  4. 我读过有关CMDOW但未在system32目录中找到cmdow.exe的内容。

  5. So how can I send quit command within the same window which is running ffmpeg process?
  6. 那么如何在运行ffmpeg进程的同一个窗口中发送quit命令呢?

Using Windows XP service pack 2 with Firefox 12

在Firefox 12中使用Windows XP Service Pack 2

Thanks..

1 个解决方案

#1


0  

That's not quite trivial - Firefox doesn't have any built-in functionality for that meaning that you would need to use js-ctypes for that and call Win32 API functions directly. Win32 - Get Main Wnd Handle of application describes how you would get hold of the top-level window for an application, after that you can send WM_QUIT message to it. This approach actually works:

这并不是一件容易的事 - Firefox没有任何内置功能,你需要使用js-ctypes并直接调用Win32 API函数。 Win32 - Get Main Wnd应用程序句柄描述了如何获取应用程序的*窗口,之后您可以向其发送WM_QUIT消息。这种方法实际上有效:

Components.utils.import("resource://gre/modules/ctypes.jsm");

var userlib = ctypes.open("user32");

var HWND = ctypes.voidptr_t;
var UINT = ctypes.uint32_t;
var WPARAM = ctypes.uint16_t;
var LPARAM = ctypes.uint32_t;
var LRESULT = ctypes.uint32_t;
var DWORD = ctypes.uint32_t;
var WNDENUMPROC = ctypes.FunctionType(ctypes.stdcall_abi,
                                      ctypes.bool,
                                      [HWND, LPARAM]).ptr;
var WM_CLOSE = 0x0010;

var EnumWindows = userlib.declare(
  "EnumWindows", ctypes.winapi_abi,
  ctypes.bool,
  WNDENUMPROC, LPARAM
);

var GetWindowThreadProcessId = userlib.declare(
  "GetWindowThreadProcessId", ctypes.winapi_abi,
  DWORD,
  HWND, DWORD.ptr
);

var IsWindowVisible = userlib.declare(
  "IsWindowVisible", ctypes.winapi_abi,
  ctypes.bool,
  HWND
);

var SendMessage = userlib.declare(
  "SendMessageW", ctypes.winapi_abi,
  LRESULT,
  HWND, UINT, WPARAM, LPARAM
);

var callback = WNDENUMPROC(function(hWnd, lParam)
{
  var procId = DWORD();
  GetWindowThreadProcessId(hWnd, procId.address());
  if (procId.value == pid && IsWindowVisible(hWnd))
    SendMessage(hWnd, WM_CLOSE, 0, 0);
  return true;
});
EnumWindows(callback, 0);

userlib.close();

I tested this and could successfully close a Notepad window with it (the usual warning will appear if the text hasn't been saved so it is a clean shutdown). In your case the problem might be however that you aren't running your ffmpeg directly but rather via the command line shell - so you will close the command line window which might not terminate ffmpeg. I guess you will just have to try, if it doesn't work you will probably have to look at the title of the window instead of its process ID (which is obviously a less reliable approach).

我测试了这个并且可以用它成功关闭一个记事本窗口(如果文本没有被保存则会出现通常的警告,因此它是一个干净的关闭)。在您的情况下,问题可能是您没有直接运行ffmpeg而是通过命令行shell运行 - 因此您将关闭可能不会终止ffmpeg的命令行窗口。我想你只需要尝试,如果它不起作用,你可能不得不查看窗口的标题而不是它的进程ID(这显然是一种不太可靠的方法)。

#1


0  

That's not quite trivial - Firefox doesn't have any built-in functionality for that meaning that you would need to use js-ctypes for that and call Win32 API functions directly. Win32 - Get Main Wnd Handle of application describes how you would get hold of the top-level window for an application, after that you can send WM_QUIT message to it. This approach actually works:

这并不是一件容易的事 - Firefox没有任何内置功能,你需要使用js-ctypes并直接调用Win32 API函数。 Win32 - Get Main Wnd应用程序句柄描述了如何获取应用程序的*窗口,之后您可以向其发送WM_QUIT消息。这种方法实际上有效:

Components.utils.import("resource://gre/modules/ctypes.jsm");

var userlib = ctypes.open("user32");

var HWND = ctypes.voidptr_t;
var UINT = ctypes.uint32_t;
var WPARAM = ctypes.uint16_t;
var LPARAM = ctypes.uint32_t;
var LRESULT = ctypes.uint32_t;
var DWORD = ctypes.uint32_t;
var WNDENUMPROC = ctypes.FunctionType(ctypes.stdcall_abi,
                                      ctypes.bool,
                                      [HWND, LPARAM]).ptr;
var WM_CLOSE = 0x0010;

var EnumWindows = userlib.declare(
  "EnumWindows", ctypes.winapi_abi,
  ctypes.bool,
  WNDENUMPROC, LPARAM
);

var GetWindowThreadProcessId = userlib.declare(
  "GetWindowThreadProcessId", ctypes.winapi_abi,
  DWORD,
  HWND, DWORD.ptr
);

var IsWindowVisible = userlib.declare(
  "IsWindowVisible", ctypes.winapi_abi,
  ctypes.bool,
  HWND
);

var SendMessage = userlib.declare(
  "SendMessageW", ctypes.winapi_abi,
  LRESULT,
  HWND, UINT, WPARAM, LPARAM
);

var callback = WNDENUMPROC(function(hWnd, lParam)
{
  var procId = DWORD();
  GetWindowThreadProcessId(hWnd, procId.address());
  if (procId.value == pid && IsWindowVisible(hWnd))
    SendMessage(hWnd, WM_CLOSE, 0, 0);
  return true;
});
EnumWindows(callback, 0);

userlib.close();

I tested this and could successfully close a Notepad window with it (the usual warning will appear if the text hasn't been saved so it is a clean shutdown). In your case the problem might be however that you aren't running your ffmpeg directly but rather via the command line shell - so you will close the command line window which might not terminate ffmpeg. I guess you will just have to try, if it doesn't work you will probably have to look at the title of the window instead of its process ID (which is obviously a less reliable approach).

我测试了这个并且可以用它成功关闭一个记事本窗口(如果文本没有被保存则会出现通常的警告,因此它是一个干净的关闭)。在您的情况下,问题可能是您没有直接运行ffmpeg而是通过命令行shell运行 - 因此您将关闭可能不会终止ffmpeg的命令行窗口。我想你只需要尝试,如果它不起作用,你可能不得不查看窗口的标题而不是它的进程ID(这显然是一种不太可靠的方法)。