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:
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).