Prevent subprocesses from constantly opening windows on Windows (#109)

* Add subprocess.CREATE_NO_WINDOW to blender_engine.py

* Convert ffmpeg_engine.py to use CREATE_NO_WINDOW

* Cleanup Blender implementation

* Cleanup subprocesses in base_worker.py

* Cleanup subprocesses in base_engine.py

* Fix main.spec for Windows (optimize=2 broke it)
This commit is contained in:
2024-08-13 22:16:03 -05:00
committed by GitHub
parent d30978bef0
commit 81e79a1996
5 changed files with 30 additions and 19 deletions

View File

@@ -3,6 +3,8 @@ import re
from src.engines.core.base_engine import *
_creationflags = subprocess.CREATE_NO_WINDOW if platform.system() == 'Windows' else 0
class FFMPEG(BaseRenderEngine):
binary_names = {'linux': 'ffmpeg', 'windows': 'ffmpeg.exe', 'macos': 'ffmpeg'}
@@ -22,8 +24,8 @@ class FFMPEG(BaseRenderEngine):
return FFMPEGUI.get_options(self)
def supported_extensions(self):
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'full'], stderr=subprocess.STDOUT)
.decode('utf-8'))
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'full'], stderr=subprocess.STDOUT,
creationflags=_creationflags).decode('utf-8'))
found = re.findall(r'extensions that .* is allowed to access \(default "(.*)"', help_text)
found_extensions = set()
for match in found:
@@ -33,8 +35,8 @@ class FFMPEG(BaseRenderEngine):
def version(self):
version = None
try:
ver_out = subprocess.check_output([self.renderer_path(), '-version'],
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
ver_out = subprocess.check_output([self.renderer_path(), '-version'], timeout=SUBPROCESS_TIMEOUT,
creationflags=_creationflags).decode('utf-8')
match = re.match(r".*version\s*([\w.*]+)\W*", ver_out)
if match:
version = match.groups()[0]
@@ -49,7 +51,8 @@ class FFMPEG(BaseRenderEngine):
'ffprobe', '-v', 'quiet', '-print_format', 'json',
'-show_streams', '-select_streams', 'v', project_path
]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, text=True,
creationflags=_creationflags)
video_info = json.loads(output)
# Extract the necessary information
@@ -80,7 +83,7 @@ class FFMPEG(BaseRenderEngine):
def get_encoders(self):
raw_stdout = subprocess.check_output([self.renderer_path(), '-encoders'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
timeout=SUBPROCESS_TIMEOUT, creationflags=_creationflags).decode('utf-8')
pattern = r'(?P<type>[VASFXBD.]{6})\s+(?P<name>\S{2,})\s+(?P<description>.*)'
encoders = [m.groupdict() for m in re.finditer(pattern, raw_stdout)]
return encoders
@@ -92,7 +95,8 @@ class FFMPEG(BaseRenderEngine):
def get_all_formats(self):
try:
formats_raw = subprocess.check_output([self.renderer_path(), '-formats'], stderr=subprocess.DEVNULL,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
timeout=SUBPROCESS_TIMEOUT,
creationflags=_creationflags).decode('utf-8')
pattern = r'(?P<type>[DE]{1,2})\s+(?P<id>\S{2,})\s+(?P<name>.*)'
all_formats = [m.groupdict() for m in re.finditer(pattern, formats_raw)]
return all_formats
@@ -104,7 +108,8 @@ class FFMPEG(BaseRenderEngine):
# Extract the common extension using regex
muxer_flag = 'muxer' if 'E' in ffmpeg_format['type'] else 'demuxer'
format_detail_raw = subprocess.check_output(
[self.renderer_path(), '-hide_banner', '-h', f"{muxer_flag}={ffmpeg_format['id']}"]).decode('utf-8')
[self.renderer_path(), '-hide_banner', '-h', f"{muxer_flag}={ffmpeg_format['id']}"],
creationflags=_creationflags).decode('utf-8')
pattern = r"Common extensions: (\w+)"
common_extensions = re.findall(pattern, format_detail_raw)
found_extensions = []
@@ -118,7 +123,7 @@ class FFMPEG(BaseRenderEngine):
def get_frame_count(self, path_to_file):
raw_stdout = subprocess.check_output([self.renderer_path(), '-i', path_to_file, '-map', '0:v:0', '-c', 'copy',
'-f', 'null', '-'], stderr=subprocess.STDOUT,
timeout=SUBPROCESS_TIMEOUT).decode('utf-8')
timeout=SUBPROCESS_TIMEOUT, creationflags=_creationflags).decode('utf-8')
match = re.findall(r'frame=\s*(\d+)', raw_stdout)
if match:
frame_number = int(match[-1])
@@ -126,8 +131,8 @@ class FFMPEG(BaseRenderEngine):
return -1
def get_arguments(self):
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'long'], stderr=subprocess.STDOUT)
.decode('utf-8'))
help_text = (subprocess.check_output([self.renderer_path(), '-h', 'long'], stderr=subprocess.STDOUT,
creationflags=_creationflags).decode('utf-8'))
lines = help_text.splitlines()
options = {}