On Windows, when running auto-editor from another process (such as from within an MPV script), the FFmpeg Popen call fails because of an OS error. The following is the traceback. Please don't mind the [autoeditor] prefix on each line, which is a result of the parent process processing the output.
[autoeditor] Traceback (most recent call last):
[autoeditor] File "<frozen runpy>", line 198, in _run_module_as_main
[autoeditor] File "<frozen runpy>", line 88, in _run_code
[autoeditor] File "C:\Users\moa17\AppData\Roaming\Python\Python311\Scripts\auto-editor.exe\__main__.py", line 7, in <module>
[autoeditor] File "C:\Users\moa17\AppData\Roaming\Python\Python311\site-packages\auto_editor\__main__.py", line 321, in main
[autoeditor] ffmpeg = FFmpeg(
[autoeditor] ^^^^^^^
[autoeditor] File "C:\Users\moa17\AppData\Roaming\Python\Python311\site-packages\auto_editor\ffwrapper.py", line 44, in __init__
[autoeditor] _version = get_stdout([self.path, "-version"]).split("\n")[0]
[autoeditor] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autoeditor] File "C:\Users\moa17\AppData\Roaming\Python\Python311\site-packages\auto_editor\utils\func.py", line 116, in get_stdout
[autoeditor] stdout, _ = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
[autoeditor] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autoeditor] File "C:\Program Files\Python311\Lib\subprocess.py", line 992, in __init__
[autoeditor] errread, errwrite) = self._get_handles(stdin, stdout, stderr)
[autoeditor] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autoeditor] File "C:\Program Files\Python311\Lib\subprocess.py", line 1365, in _get_handles
[autoeditor] p2cread = self._make_inheritable(p2cread)
[autoeditor] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[autoeditor] File "C:\Program Files\Python311\Lib\subprocess.py", line 1416, in _make_inheritable
[autoeditor] h = _winapi.DuplicateHandle(
[autoeditor] ^^^^^^^^^^^^^^^^^^^^^^^^
[autoeditor] OSError: [WinError 6] The handle is invalid
It seems to complain that one of the handles (maybe stdin? as it's not specified in Popen) is not a valid handle to replicate.
Invoked as a subprocess from within mpv's JavaScript runtime:
auto-editor file.mp4 --export json --quiet --frame-margin 12,6 --edit audio:threshold=4%
Below is example code from part of the mpv JavaScript plugin:
var AUTO_EDITOR_BIN = "auto-editor";
var AUTO_EDITOR_ARGS = ["--export", "json", "--quiet", "--frame-margin", "12,6", "--edit", "audio:threshold=4%"];
var cmd = {
name: "subprocess",
playback_only: false,
capture_stdout: true,
capture_stderr: true,
args: [AUTO_EDITOR_BIN, "file.mp4"].concat(AUTO_EDITOR_ARGS)
};
mp.command_native_async(cmd, function (success, result, error) {
if (result !== undefined) mp.msg.error(result.stdout);
if (result !== undefined) mp.msg.error(result.stderr);
});
// result.stdout is empty, and result.stderr contains the Python traceback.
I suspect this problem is because Windows (or the way mpv does it?) does not pass a valid stdin handle to its subprocesses, which means using Popen will try to duplicate that non-existent handle when launching the secondary nested subprocess.
A StackOverflow answer suggests that adding stdin=subprocess.DEVNULL would solve the problem, maybe it'll work.
It appears that this could also happen if you run as a Windows Service or as a packaged executable with PyInstaller, suggesting that it's an issue that should be fixed on auto-editor's side, not mpv's side.
Bug description
On Windows, when running
auto-editor
from another process (such as from within an MPV script), the FFmpegPopen
call fails because of an OS error. The following is the traceback. Please don't mind the [autoeditor] prefix on each line, which is a result of the parent process processing the output.It seems to complain that one of the handles (maybe stdin? as it's not specified in Popen) is not a valid handle to replicate.
What's your platform?
What command did you use
What properties does your input video have?
Comments
The same issue was previously reported here: https://github.com/WyattBlue/auto-editor/issues/382
I suspect this problem is because Windows (or the way mpv does it?) does not pass a valid stdin handle to its subprocesses, which means using
Popen
will try to duplicate that non-existent handle when launching the secondary nested subprocess.A StackOverflow answer suggests that adding
stdin=subprocess.DEVNULL
would solve the problem, maybe it'll work.It appears that this could also happen if you run as a Windows Service or as a packaged executable with PyInstaller, suggesting that it's an issue that should be fixed on auto-editor's side, not mpv's side.
Would you be able to take a look?