Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Keep unrelated plugins out of the FreeVideo ComfyUI environment (#11)

Bowen Xue2f4e3206e6f1
diff --git a/freevideo_engine/comfy_launcher_runtime.py b/freevideo_engine/comfy_launcher_runtime.py
index fc58f4b..3775976 100644
--- a/freevideo_engine/comfy_launcher_runtime.py
+++ b/freevideo_engine/comfy_launcher_runtime.py
@@ -71,7 +71,7 @@ def layout(path):
raise ValueError('This ComfyUI is too old for native VIDEO / V3 nodes. Update ComfyUI first; its files have not been changed.')
candidates = []
for parent in (root, root.parent):
- for name in ('python_embeded', 'python_embedded', '.venv', 'venv', 'env'):
+ for name in ('python_embeded', 'python_embedded', '.venv', 'venv', 'env', 'python'):
directory = parent / name
candidates.extend([directory / 'python.exe', directory / 'Scripts/python.exe', directory / 'bin/python'])
python = next((p.resolve() for p in candidates if p.is_file()), None)
@@ -98,6 +98,19 @@ def managed_python(engine, comfy):
return None
+def managed_frontend(selected):
+ """Identify our frontend even after reopening makes `separate` false.
+
+ Do not resolve the executable: venv Python is a symlink on Linux, but its
+ environment and installed packages still belong to the venv directory.
+ """
+ python = Path(os.path.abspath(selected['python']))
+ environment = python.parent.parent
+ return (python.parent.name in ('Scripts', 'bin')
+ and environment.name.startswith('comfyui-')
+ and environment.parent.resolve() == (Path(selected['engine']) / 'envs').resolve())
+
+
# Run with the host's Python, without importing Torch or creating __pycache__.
# Reading the same folder registry supports extra_model_paths.yaml correctly.
HOST_PROBE = r'''
@@ -445,7 +458,7 @@ class Controller:
raise ValueError('Place the engine beside the new ComfyUI folder, so ComfyUI can be downloaded atomically.')
cached_python = managed_python(engine, Path(descriptor['root']))
host = (dict(ready=False, python=None, libraries=[str(Path(descriptor['root']) / 'models')])
- if fresh and not cached_python else probe_host(descriptor, values.get('python') or cached_python))
+ if fresh and not cached_python else probe_host(descriptor, values.get('python') or descriptor.get('python') or cached_python))
descriptor.update(python=host.get('python'), separate=values.get('separate', False) or not host.get('ready'))
# Validate before copying even the small launcher payload.
folders = SimpleNamespace(base_path=descriptor['root'], models_dir=str(Path(descriptor['root']) / 'models'),
@@ -571,19 +584,31 @@ class Controller:
env['FREEVIDEO_COMFY_LOG'] = str(self.server_log)
command = [selected['python'], '-u', '-B', str(Path(selected['root']) / 'main.py'), '--listen', parsed.hostname,
'--port', str(parsed.port or 80), '--disable-auto-launch']
+ managed = managed_frontend(selected)
+ if managed:
+ # This environment has ComfyUI core dependencies, not the user's
+ # custom-node packages. Scope both prestartup scripts and imports;
+ # a plugin can otherwise run pip, replace Torch, or call sys.exit.
+ command += ['--disable-all-custom-nodes', '--whitelist-custom-nodes', node_target(selected['root']).name]
+ context = dict(environment='freevideo-managed' if managed else 'existing-comfyui',
+ custom_nodes='FreeVideo' if managed else 'all')
if selected.get('portable') and not selected['separate']:
command.append('--windows-standalone-build')
from .windows_ux import external_python
with self._server_lock, external_python(), self.server_log.open('wb') as log:
if self._closed or self.cancelled.is_set():
raise RuntimeError('ComfyUI startup cancelled')
+ if managed:
+ log.write(b'[FreeVideo] Separate environment: loading FreeVideo custom nodes only. '
+ b'Use your original ComfyUI launcher for other plugins.\n')
+ log.flush()
# Keep durable embedded output, but own the whole tree: Windows
# Job / Linux supervisor also reclaim independently grouped model
# workers when the launcher dies without running Python cleanup.
server = processes.popen(command, cwd=selected['root'], env=env, stdin=subprocess.DEVNULL,
stdout=log, stderr=subprocess.STDOUT, start_new_session=True, supervise=True)
self.server = server
- save(directory / 'launch.json', dict(command=command, pid=server.pid, root=selected['root'], url=url))
+ save(directory / 'launch.json', dict(command=command, pid=server.pid, root=selected['root'], url=url, **context))
self.state = dict(self.state, task=dict(progress=dict(label='Starting ComfyUI', detail='Loading nodes and the web interface'), log=str(directory)))
deadline = time.monotonic() + 180
while time.monotonic() < deadline:
@@ -593,7 +618,8 @@ class Controller:
raise RuntimeError('ComfyUI startup cancelled')
if server.poll() is not None:
from .failure_details import startup_failure
- raise RuntimeError(startup_failure('ComfyUI could not start.', directory / 'comfy.log'))
+ raise RuntimeError(startup_failure('ComfyUI could not start.', directory / 'comfy.log',
+ exit_code=server.returncode, context=context))
info = server_info(url)
if matches_server(info, selected['root'], selected['engine'], selected['source']):
self.stage('open', done=1, label='Ready')
diff --git a/freevideo_engine/failure_details.py b/freevideo_engine/failure_details.py
index ed38c99..48aa3d4 100644
--- a/freevideo_engine/failure_details.py
+++ b/freevideo_engine/failure_details.py
@@ -73,6 +73,12 @@ def launcher_failure(value, *, zh=False):
return dict(title='', detail='', action='', kind='')
text = str(value)
summary = text.partition(STEP_OUTPUT)[0]
+ if text.startswith('ComfyUI could not start.'):
+ return dict(title='ComfyUI 启动失败' if zh else 'ComfyUI could not start',
+ detail='ComfyUI 进程在启动时退出。' if zh else 'The ComfyUI process exited during startup.',
+ action='展开详情查看退出码与插件错误;已有 ComfyUI 可使用原启动器检查。' if zh else
+ 'Open details for the exit code and plugin errors. For an existing ComfyUI, also check its original launcher.',
+ kind='comfy-startup')
if 'Failed step: kernels (' in summary:
detail = summary[summary.index('Failed step: kernels ('):]
detail = detail.partition('\nRetained step log:')[0]
@@ -202,6 +208,10 @@ def generation_failure(run, exit_code=None):
return re.sub(r'[\x00-\x08\x0b-\x1f\x7f]', '', value)
-def startup_failure(message, log):
+def startup_failure(message, log, *, exit_code=None, context=None):
detail = _read(Path(log), 8192, tail=True).strip()
+ if exit_code is not None:
+ message += '\nProcess exit code: ' + str(exit_code)
+ if context:
+ message += '\nEnvironment: ' + context['environment'] + '\nCustom nodes: ' + context['custom_nodes']
return Redactor().text(message + ('\n\n' + detail if detail else '\nNo readable process output was produced.') + '\n\nLog: ' + str(log))
diff --git a/freevideo_engine/launcher/Main.qml b/freevideo_engine/launcher/Main.qml
index 2507870..4b3bc4e 100644
--- a/freevideo_engine/launcher/Main.qml
+++ b/freevideo_engine/launcher/Main.qml
@@ -263,7 +263,7 @@ ApplicationWindow {
FField { objectName: "installationPath"; Layout.fillWidth: true; text: s.form.new_comfy ? s.form.destination : s.form.comfy; placeholderText: t("Choose a folder", "选择文件夹"); enabled: !s.busy; onEditingFinished: backend.edit(s.form.new_comfy ? "destination" : "comfy", text) }
FButton { text: t("Browse…", "浏览…"); implicitHeight: theme.height + 4; onClicked: backend.browse(s.form.new_comfy ? "destination" : "comfy") }
}
- FText { visible: !s.form.new_comfy; text: t("A separate environment is prepared if needed.", "必要时会准备独立环境。"); color: theme.muted; font.pixelSize: theme.micro; Layout.fillWidth: true }
+ FText { visible: !s.form.new_comfy; text: t("Uses your existing Python when available. A separate environment loads only FreeVideo.", "优先使用已有 Python;独立环境仅加载 FreeVideo。"); color: theme.muted; font.pixelSize: theme.micro; Layout.fillWidth: true }
}
}