fix: find FFmpeg in more Windows locations and explain compose failures

Windows PATH edits only reach processes started afterwards, so a freshly
installed FFmpeg stays invisible to a running ComfyUI, and portable users
often drop ffmpeg.exe next to the run bat without any PATH entry at all.

get_ffmpeg_path now probes, after which() fails: the classic C:\ffmpeg\bin
and %LOCALAPPDATA% locations, winget Links / scoop shims / chocolatey bin,
the ComfyUI base folder and portable root (root, bin/, ffmpeg/bin/), and
finally the ffmpeg binary bundled with ComfyUI's own imageio-ffmpeg
dependency (ffmpeg only - imageio-ffmpeg bundles no ffprobe).

The H3 compose failure message now also points at concrete remedies
instead of only listing search locations.

Verified with scripts/test_merge_failure_reason.py: 19/19 stubbed checks
(portable-layout resolution, imageio-ffmpeg last resort, ffprobe exclusion,
and every compose failure reason).
This commit is contained in:
Z User 2026-09-29 06:41:26 +00:00
parent 4dccb4fb4c
commit d26e3297a6
3 changed files with 106 additions and 12 deletions

View File

@ -6,6 +6,7 @@
### ⚡ Improvements
- **FFmpeg resolution & diagnostics**: The pack now finds FFmpeg on far more Windows setups and tells you exactly what is wrong when it cannot. When `ffmpeg` is not on the ComfyUI process's PATH (PATH edits only reach processes started afterwards), it is additionally looked up in the classic `C:\ffmpeg\bin`, the ComfyUI/portable folders (including `ffmpeg\bin` next to the run bat), winget/scoop/chocolatey shim locations, and finally the ffmpeg binary bundled with ComfyUI's own `imageio-ffmpeg` dependency. When composing an H3 project still fails, the error dialog now names the concrete cause instead of a generic message: the missing executable, the exact missing segment/locked-audio file paths, odd canvas sizes, or the tail of FFmpeg's own stderr output (e.g. `Unknown encoder 'libx264'`).
- **Installation**: The pack now ships a **`requirements.txt`**, so ComfyUI Manager installs the dependencies automatically and manual/portable installs have a one-line command (`python_embeded\python.exe -m pip install -r ...` for ComfyUI Portable — see the new "Installing dependencies" section in the README). Because this pack targets **NVIDIA RTX 3060+ GPUs only**, every feature dependency is mandatory: `soundfile`, `jieba`, `huggingface_hub`, `ffmpeg-python`, `opencv-python`, `imageio` (smart split), `nvidia-vfx` (RTX VSR upscale), `openai-whisper` and `qwen-asr` (subtitle recognition), and `voxcpm` (speech). No optional extras remain — previously these were installed on demand with error messages naming the missing package. The file also routes `nvidia-vfx` to NVIDIA's own index (`--extra-index-url https://pypi.nvidia.com/` + `--only-binary=nvidia-vfx`): the PyPI copy is a stub sdist whose `wheel_stub` build backend can abort the whole install (`Cannot import 'wheel_stub.buildapi'`), while NVIDIA's index serves real prebuilt wheels.
- **Installation**: Removed the bundled `download_models.sh` downloader. All model files live in the Hugging Face version of the repository — cloning it downloads the complete model set, so there is no separate downloader step (the README's Models section now explains this).
- **MultiTrack Editor**: The editor frontend was **reverted to the pristine upstream v1.3.3 source** — the MiniMax/Moxie format display-label mapping and every workaround built around it were removed. The shipped editor bundle is now built from that pristine source, so its behavior is exactly the battle-tested upstream editor (Shot/Context continuity, reference-size, audio lock, and MiniMax prompt placeholders all key on the native `MiniMax` format value again).

View File

@ -238,6 +238,59 @@ finally:
shutil.which = _real_which
fake_ffmpeg.unlink(missing_ok=True)
# ---------------------------------------------------------------------------
# 3b. get_ffmpeg_path expanded Windows fallbacks (portable folder, winget/
# scoop/choco shims, imageio-ffmpeg bundled binary). On this POSIX sandbox
# os.name must be forced to "nt" so the fallback branches run.
# ---------------------------------------------------------------------------
import utils.video as _video_mod # noqa: E402
_real_os_name = os.name
_real_base = getattr(_video_mod.folder_paths, "base_path", "")
shutil.which = lambda name, **k: None
os.name = "nt"
try:
# Portable layout: <base>/ffmpeg/bin/ffmpeg.exe found via the portable
# root (dirname of folder_paths.base_path).
fake_base = PACKAGE_ROOT / ".tmp-fake-base" / "ComfyUI"
portable_exe = fake_base.parent / "ffmpeg" / "bin" / "ffmpeg.exe"
portable_exe.parent.mkdir(parents=True, exist_ok=True)
portable_exe.write_bytes(b"")
_video_mod.folder_paths.base_path = str(fake_base)
found = _video_mod.get_ffmpeg_path("ffmpeg")
check(
"portable ffmpeg/bin layout resolved",
found == str(portable_exe),
repr(found),
)
portable_exe.unlink()
shutil.rmtree(PACKAGE_ROOT / ".tmp-fake-base", ignore_errors=True)
_video_mod.folder_paths.base_path = _real_base
# ffmpeg (not ffprobe) falls back to the imageio-ffmpeg bundled binary.
fake_imageio = types.ModuleType("imageio_ffmpeg")
bundled = str(PACKAGE_ROOT / ".tmp-bundled-ffmpeg.exe")
fake_imageio.get_ffmpeg_exe = lambda: bundled
sys.modules["imageio_ffmpeg"] = fake_imageio
found = _video_mod.get_ffmpeg_path("ffmpeg")
check(
"imageio-ffmpeg bundled binary used as last resort",
found == bundled,
repr(found),
)
# ffprobe is NOT bundled by imageio-ffmpeg: must NOT resolve to it.
found = _video_mod.get_ffmpeg_path("ffprobe")
check(
"ffprobe never resolved from imageio-ffmpeg",
found is None,
repr(found),
)
del sys.modules["imageio_ffmpeg"]
finally:
os.name = _real_os_name
_video_mod.folder_paths.base_path = _real_base
shutil.which = _real_which
# ---------------------------------------------------------------------------
# 4. compose_h3_project_video propagates the reason into the RuntimeError.
# ---------------------------------------------------------------------------

View File

@ -327,9 +327,11 @@ def merge_video_track_with_ffmpeg(
resize_filter = _ffmpeg_resize_filter(width, height, resize_method) if resize_method else None
if ffmpeg is None:
record(
"FFmpeg executable not found (searched PATH for ffmpeg/ffmpeg.exe, "
r"C:\ffmpeg\bin, %LOCALAPPDATA%\Programs\ffmpeg\bin). "
"Install FFmpeg, ensure ffmpeg.exe is on PATH and restart ComfyUI"
"FFmpeg executable not found (checked PATH, common install folders, "
"package-manager shims and the imageio-ffmpeg bundled binary). "
"Install FFmpeg with ffmpeg.exe on PATH - or simply copy ffmpeg.exe "
"into C:\\ffmpeg\\bin - and restart ComfyUI from a NEW terminal so "
"the updated PATH is picked up"
)
return None
if total_length <= 0:
@ -566,19 +568,57 @@ def merge_video_track_with_ffmpeg(
def get_ffmpeg_path(name: str = "ffmpeg") -> str | None:
"""Find FFmpeg/ffprobe executable, with Windows-specific fallbacks."""
"""Find FFmpeg/ffprobe executable, with Windows-specific fallbacks.
PATH edits on Windows only reach processes started afterwards, and
Portable users routinely have ffmpeg.exe sitting next to the run bat or
installed via winget/scoop/choco without the ComfyUI process ever seeing
it. After ``which`` fails, probe the locations such installs actually
use, and finally fall back to the binary bundled with imageio-ffmpeg
(a ComfyUI core dependency) so a zero-setup machine can still encode.
"""
# Try standard which first (works on all platforms)
ffmpeg = shutil.which(name) or shutil.which(f"{name}.exe")
if ffmpeg:
return ffmpeg
# Windows fallback: common installation paths
if os.name == "nt":
for path in (
r"C:\ffmpeg\bin\{}.exe".format(name),
os.path.expandvars(r"%LOCALAPPDATA%\Programs\{}\bin\{}.exe".format(name, name)),
):
if os.path.isfile(path):
return path
if os.name != "nt":
return None
exe = f"{name}.exe"
candidates: list[str] = [
r"C:\ffmpeg\bin\{}".format(name),
os.path.expandvars(r"%LOCALAPPDATA%\Programs\{}\bin\{}".format(name, name)),
# Package-manager shims/links.
os.path.expandvars(r"%LOCALAPPDATA%\Microsoft\WinGet\Links\{}".format(exe)),
os.path.expandvars(r"%USERPROFILE%\scoop\shims\{}".format(exe)),
r"C:\ProgramData\chocolatey\bin\{}".format(exe),
]
# Relative to the ComfyUI install: the portable root (parent of the
# ComfyUI folder) and the folder itself. ffmpeg.exe next to the run bat
# or in an ffmpeg/bin subfolder is a very common portable layout.
base = str(getattr(folder_paths, "base_path", "") or "")
roots: list[str] = []
if base:
roots.append(base)
roots.append(os.path.dirname(os.path.abspath(base)))
roots.append(os.getcwd())
for root in roots:
candidates.extend([
os.path.join(root, exe),
os.path.join(root, "bin", exe),
os.path.join(root, "ffmpeg", "bin", exe),
])
for candidate in candidates:
if os.path.isfile(candidate):
return candidate
# Last resort: imageio-ffmpeg ships a full ffmpeg build (libx264
# included). It bundles no ffprobe, so only use it for ffmpeg itself.
if name == "ffmpeg":
try:
import imageio_ffmpeg
return imageio_ffmpeg.get_ffmpeg_exe()
except Exception:
pass
return None