After investigating the reasons for such behaviour (without --windowed everything works fine), I narrowed it down to this part of code in _io.py
p = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=None,
**_popen_kwargs(prevent_sigint=True)
)
The comment that follows explains that stderr was deliberately set to None because if redirected to pipe on Windows, it causes ffmpeg to hang. On the other hand, stderr=None causes a problem with --windowed option on Windows (OSError: [WinError 6] The handle is invalid). My understanding is that Windows is trying to recreate stderr handle as it is set to None, but unable to do this due to --windowed mode.
A possible solution is to redirect stderr (and probably stdout too) to subprocess.DEVNULL instead of None, i.e.
After investigating the reasons for such behaviour (without --windowed everything works fine), I narrowed it down to this part of code in _io.py
The comment that follows explains that stderr was deliberately set to None because if redirected to pipe on Windows, it causes ffmpeg to hang. On the other hand, stderr=None causes a problem with --windowed option on Windows (OSError: [WinError 6] The handle is invalid). My understanding is that Windows is trying to recreate stderr handle as it is set to None, but unable to do this due to --windowed mode.
A possible solution is to redirect stderr (and probably stdout too) to subprocess.DEVNULL instead of None, i.e.