Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: offer video input only when llama-server can launch ffmpeg and ffprobe (#16094)
Daniel Han4e799e0fdc09
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex c65b4eb4dfb..5966276e340 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -5672,6 +5672,28 @@ def requested_video_fps(return rate if rate > 0 else None+def _video_tools_reachable(+ cmd: Sequence[str],+ env: Optional[Mapping[str, str]] = None,+ cwd: Optional[str] = None,+) -> bool:+ """Whether the child can launch ffmpeg and ffprobe, which /props' video modality never checks (#16065)."""+ source = os.environ if env is None else env+ try:+ bin_dir = _last_flag_value(cmd, frozenset({"--video-ffmpeg-dir"}))+ except Exception:+ return True+ search = bin_dir or source.get("LLAMA_ARG_VIDEO_FFMPEG_DIR")+ names = ("ffmpeg.exe", "ffprobe.exe") if sys.platform == "win32" else ("ffmpeg", "ffprobe")+ if not search:+ search = source.get("PATH", os.defpath)+ if sys.platform == "win32":+ # CreateProcess also searches the binary's folder and the working directory.+ launch_dir = os.path.dirname(str(cmd[0])) if cmd else ""+ search = os.pathsep.join(d for d in (launch_dir, cwd or os.getcwd(), search) if d)+ return all(shutil.which(name, path = search) for name in names)++def _env_sets_mmproj_offload(env: Optional[Mapping[str, str]] = None) -> bool:"""Presence, not value, decides: LLAMA_ARG_NO_MMPROJ_OFFLOAD= counts, as llama.cpp tests with getenv."""source = os.environ if env is None else env@@ -32390,6 +32412,13 @@ class LlamaCppBackend:self._has_video_input = False# Use _extra_args_as_requested: the drafter-drop snapshot would restore the Metal zero-context strip.self._reconcile_effective_ctx_with_server(ctx_override or 0)+ if self._has_video_input:+ self._has_video_input = _video_tools_reachable(_last_spawn_cmd, env, _spawn_cwd)+ if not self._has_video_input:+ logger.warning(+ "Video input disabled: llama-server decodes video with ffmpeg and "+ "ffprobe, and neither --video-ffmpeg-dir nor PATH provides both."+ )if self._kv_cache_context_total is not None:self._n_ubatch = min(self._n_ubatch,diff --git a/studio/backend/tests/test_video_needs_ffmpeg.py b/studio/backend/tests/test_video_needs_ffmpeg.pynew file mode 100644index 00000000000..63671b1afc7--- /dev/null+++ b/studio/backend/tests/test_video_needs_ffmpeg.py@@ -0,0 +1,105 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Video is offered only when llama-server can launch ffmpeg and ffprobe (#16065)."""++from __future__ import annotations++import sys+from pathlib import Path++import pytest++_TESTS_DIR = Path(__file__).resolve().parent+if str(_TESTS_DIR) not in sys.path:+ sys.path.insert(0, str(_TESTS_DIR))++import core.inference.llama_cpp as llama_cpp # noqa: E402+from test_mmproj_placement_policy import _backend, _launch # noqa: E402++_EXE = ".exe" if sys.platform == "win32" else ""+++def _tools_dir(root: Path, *names: str) -> Path:+ root.mkdir(parents = True, exist_ok = True)+ for name in names:+ tool = root / f"{name}{_EXE}"+ tool.write_text("#!/bin/sh\n")+ tool.chmod(0o755)+ return root+++def test_both_tools_on_path_keep_video(tmp_path):+ bin_dir = _tools_dir(tmp_path / "bin", "ffmpeg", "ffprobe")+ assert llama_cpp._video_tools_reachable(["llama-server"], {"PATH": str(bin_dir)})++[email protected]("present", [(), ("ffmpeg",), ("ffprobe",)])+def test_a_missing_tool_on_path_drops_video(tmp_path, present):+ bin_dir = _tools_dir(tmp_path / "bin", *present)+ assert not llama_cpp._video_tools_reachable(+ ["llama-server"], {"PATH": str(bin_dir)}, str(tmp_path)+ )+++def test_the_ffmpeg_dir_flag_beats_path_and_env(tmp_path):+ good = _tools_dir(tmp_path / "good", "ffmpeg", "ffprobe")+ empty = _tools_dir(tmp_path / "empty")+ env = {"PATH": str(empty), "LLAMA_ARG_VIDEO_FFMPEG_DIR": str(empty)}+ assert llama_cpp._video_tools_reachable(["llama-server", "--video-ffmpeg-dir", str(good)], env)+ assert llama_cpp._video_tools_reachable(["llama-server", f"--video-ffmpeg-dir={good}"], env)+ env = {"PATH": str(good), "LLAMA_ARG_VIDEO_FFMPEG_DIR": str(good)}+ assert not llama_cpp._video_tools_reachable(+ ["llama-server", "--video-ffmpeg-dir", str(empty)], env+ )++[email protected](sys.platform == "win32", reason = "no execute bit on Windows")+def test_non_executable_tools_in_the_ffmpeg_dir_drop_video(tmp_path):+ tools = _tools_dir(tmp_path / "tools", "ffmpeg", "ffprobe")+ for tool in tools.iterdir():+ tool.chmod(0o644)+ assert not llama_cpp._video_tools_reachable(+ ["llama-server", "--video-ffmpeg-dir", str(tools)], {}+ )+++def test_the_ffmpeg_dir_env_var_is_read_without_the_flag(tmp_path):+ good = _tools_dir(tmp_path / "good", "ffmpeg", "ffprobe")+ empty = _tools_dir(tmp_path / "empty")+ env = {"PATH": str(empty), "LLAMA_ARG_VIDEO_FFMPEG_DIR": str(good)}+ assert llama_cpp._video_tools_reachable(["llama-server"], env)+++def _load_with_video_props(tmp_path, monkeypatch, path, **load_kwargs):+ monkeypatch.setenv("PATH", str(path))+ monkeypatch.delenv("LLAMA_ARG_VIDEO_FFMPEG_DIR", raising = False)+ backend, gguf = _backend(tmp_path, memory = [(0, 12_000, 24_000)])+ backend._query_server_props = lambda: {+ "modalities": {"vision": True, "video": True},+ "default_generation_settings": {"n_ctx": 4096},+ }+ _launch(backend, gguf, **load_kwargs)+ return backend+++def test_a_load_without_ffprobe_does_not_offer_video(tmp_path, monkeypatch):+ backend = _load_with_video_props(tmp_path, monkeypatch, _tools_dir(tmp_path / "bin", "ffmpeg"))+ assert backend._has_video_input is False+++def test_a_load_with_both_tools_offers_video(tmp_path, monkeypatch):+ bin_dir = _tools_dir(tmp_path / "bin", "ffmpeg", "ffprobe")+ backend = _load_with_video_props(tmp_path, monkeypatch, bin_dir)+ assert backend._has_video_input is True+++def test_a_load_given_an_ffmpeg_dir_offers_video(tmp_path, monkeypatch):+ good = _tools_dir(tmp_path / "ffmpeg", "ffmpeg", "ffprobe")+ backend = _load_with_video_props(+ tmp_path,+ monkeypatch,+ _tools_dir(tmp_path / "bin"),+ extra_args = ("--video-ffmpeg-dir", str(good)),+ )+ assert backend._has_video_input is True