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.

Find the installer's own Git and restore long lists of files in batches

Bowen Xue1f1b43ab2f41
diff --git a/freevideo_engine/encode_worker.py b/freevideo_engine/encode_worker.py
index 1ea774d..6f17358 100644
--- a/freevideo_engine/encode_worker.py
+++ b/freevideo_engine/encode_worker.py
@@ -263,6 +263,8 @@ def _encode(args, request, resident, trace):
return dict(state='skipped', resource_decision=decision,
reason='Foreground work or insufficient live memory for idle preloading')
phase('encoder_options')
+ from .encoder_source import ensure
+ ensure(args.comfy_root)
sys.path.insert(0, str(args.comfy_root.resolve()))
import comfy.options
comfy.options.enable_args_parsing()
diff --git a/freevideo_engine/encoder_source.py b/freevideo_engine/encoder_source.py
new file mode 100644
index 0000000..100bfd0
--- /dev/null
+++ b/freevideo_engine/encoder_source.py
@@ -0,0 +1,105 @@
+"""Keep the encoder's pinned ComfyUI source tree whole.
+
+The tree is a sparse Git checkout of one commit, so a file that disappears after
+installation (security software, a cleanup tool) is still in the local object
+store: put it back from there instead of downloading anything.
+"""
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+
+from . import subprocess_output
+from .paths import data_root
+from .windows_ux import hidden_console
+
+# Read when the native Qwen tokenizer is built. Without vocab.json or merges.txt
+# the tokenizers library fails with an error that names neither file.
+REQUIRED = ('comfy/text_encoders/qwen25_tokenizer/vocab.json',
+ 'comfy/text_encoders/qwen25_tokenizer/merges.txt',
+ 'comfy/text_encoders/qwen25_tokenizer/tokenizer_config.json')
+
+
+# A Windows command line holds 32767 characters; a deleted tree can name more paths than that.
+BATCH = 8000
+
+
+class EncoderSourceError(RuntimeError):
+ """Text encoder files are missing and could not be restored."""
+
+
+def executable(env=None):
+ """The Git to use: the one the installer exported, one on PATH, else the one it recorded.
+
+ Windows installs keep their own MinGit under the installation folder and
+ note it only in machine.json, so a machine without a system Git has neither
+ of the first two.
+ """
+ found = (env or os.environ).get('FREEVIDEO_GIT') or shutil.which('git')
+ if found:
+ return found
+ try:
+ recorded = json.loads((data_root() / 'machine.json').read_text(encoding='utf-8')).get('git')
+ except (OSError, ValueError, AttributeError):
+ return None
+ return recorded if recorded and Path(recorded).is_file() else None
+
+
+def missing(root):
+ return [name for name in REQUIRED if not (Path(root) / name).is_file()]
+
+
+def deleted(root, env=None):
+ """Tracked files that are gone from the work tree; None if Git cannot say."""
+ git = executable(env)
+ if not git or not (Path(root) / '.git').exists():
+ return None
+ try:
+ result = subprocess_output.run_external([git, '-C', str(root), 'ls-files', '-d', '-z'],
+ env=env, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, timeout=60, **hidden_console())
+ except (OSError, ValueError, subprocess.SubprocessError):
+ return None
+ if result.returncode:
+ return None
+ return [name for name in (result.stdout or '').split('\0') if name]
+
+
+def restore(root, names, env=None):
+ """Check the named tracked files out again; True if every command succeeded."""
+ git = executable(env)
+ if not git or not names:
+ return False
+ batches, used = [[]], 0
+ for name in names:
+ if batches[-1] and used + len(name) + 1 > BATCH:
+ batches.append([])
+ used = 0
+ batches[-1].append(name)
+ used += len(name) + 1
+ for batch in batches:
+ try:
+ result = subprocess_output.run_external([git, '-C', str(root), 'checkout', '--', *batch],
+ env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=120, **hidden_console())
+ except (OSError, ValueError, subprocess.SubprocessError):
+ return False
+ if result.returncode:
+ return False
+ return True
+
+
+def ensure(root, env=None):
+ """Restore the tokenizer files if they are gone; the usual case reads three paths only."""
+ absent = missing(root)
+ if not absent:
+ return []
+ gone = deleted(root, env)
+ # Another ComfyUI layout, or no Git to ask: leave it to the library.
+ lost = [name for name in absent if name in (gone or ())]
+ if not lost:
+ return []
+ restore(root, gone, env)
+ lost = missing(root)
+ if lost:
+ raise EncoderSourceError('FreeVideo text encoder files are missing: %s' % ', '.join(lost))
+ return gone
diff --git a/freevideo_engine/network.py b/freevideo_engine/network.py
index cb811ca..7515244 100644
--- a/freevideo_engine/network.py
+++ b/freevideo_engine/network.py
@@ -1607,6 +1607,11 @@ def clone(target, url, commit, *, sparse=None, run=None, network=None, env=None)
head, dirty = repository_state(target, git, env)
except (subprocess.CalledProcessError, OSError):
head, dirty = None, '' # Git cannot read it as a repository of its own.
+ if head == commit and dirty and all(line[:2] == ' D' for line in dirty.splitlines()):
+ # Files deleted after installation: the same commit's objects are still local, nothing is downloaded.
+ from . import encoder_source
+ if encoder_source.restore(target, encoder_source.deleted(target, env), env):
+ head, dirty = repository_state(target, git, env)
if head == commit and not dirty:
return target
if target.parent.name == 'vendor' and git_settings_out_of_reach(target):
diff --git a/web/error_panel.js b/web/error_panel.js
index 97c4d05..54d6e17 100644
--- a/web/error_panel.js
+++ b/web/error_panel.js
@@ -422,6 +422,11 @@ export function failureAdvice(value, t, known = knownError(value)) {
return row('model-files', ['The model is not fully installed', '模型没有装全'],
['Some of the model files FreeVideo needs are missing.', 'FreeVideo 需要的部分模型文件缺失。'],
repairAction());
+ // The second form is the tokenizers library's own error when its vocab or merges file is gone.
+ if (/FreeVideo text encoder files are missing|`vocab` and `merges` must be both be from memory/i.test(text))
+ return row('encoder-files', ['The text encoder is not fully installed', '文本编码器没有装全'],
+ ['Some of the text encoder files FreeVideo needs are missing.', 'FreeVideo 需要的部分文本编码器文件缺失。'],
+ repairAction());
if (/No space left on device|WinError 112|disk (?:is )?full/i.test(text))
return row('disk', ['Disk space is insufficient', '磁盘空间不足'],
['FreeVideo could not write a required file.', 'FreeVideo 无法写入所需文件。'],