Skip to content

Local video editor for coding agents: 42 FFmpeg tools with a machine-readable contract and an MCP server, for Claude Code, Cursor and Codex. Cut, captions, reframe, loudness, platform exports. No cloud, no API keys.

fix(macos): use Homebrew's keg-only ffmpeg-full when PATH has the lean ffmpeg (#321)

Shogo Kajiyamac1a9d4386926
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 013bfd9..2de6798 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,10 @@
## Unreleased
-(nothing yet)
+### Fixed
+
+- **macOS: a lean Homebrew `ffmpeg` on `PATH` no longer hides `ffmpeg-full`.** When the `ffmpeg` on `PATH` is Homebrew's `ffmpeg` / `ffmpeg@N` formula and the same prefix has the keg-only `ffmpeg-full`, every tool (and `doctor`) runs `ffmpeg-full`'s `ffmpeg` and `ffprobe`, so `brew install ffmpeg-full` is enough to get `drawtext`, `subtitles` and `zscale`. Any other `ffmpeg` on `PATH` is used unchanged. `doctor --json` gains `ffmpeg_path`, `ffmpeg_source`, `ffprobe_path` and `ffprobe_source`; the existing `ffmpeg` / `ffprobe` keys are unchanged (#317).
+- **`doctor` no longer says drawtext "crashed" when it is simply absent.** A build without the `drawtext` filter now gets the install hint; the crash wording (#100) is kept for a build that lists it and then crashes.
## 2.8.2
diff --git a/README.md b/README.md
index 3ed824a..6ef6097 100644
--- a/README.md
+++ b/README.md
@@ -484,7 +484,7 @@ FFmpeg itself:
| Ubuntu / Debian | `sudo apt install ffmpeg` |
| Windows | `winget install Gyan.FFmpeg` |
-**On macOS, `ffmpeg-full` is keg-only:** Homebrew installs it without linking it, so after `brew install ffmpeg-full` the `ffmpeg` on `PATH` is still the lean `ffmpeg` formula (often present as a dependency of another formula), or no `ffmpeg` at all, so `doctor` keeps reporting `ffmpeg`, or the `subtitles` and `drawtext` filters, as missing. Make it the one the tools find, in one of two ways:
+**On macOS, `ffmpeg-full` is keg-only:** Homebrew installs it without linking it, so after `brew install ffmpeg-full` the `ffmpeg` on `PATH` is still the lean `ffmpeg` formula (often present as a dependency of another formula), or no `ffmpeg` at all. **If the `ffmpeg` on `PATH` is Homebrew's lean formula, the skill uses the `ffmpeg-full` of the same Homebrew prefix by itself** (`ffmpeg` and `ffprobe` both, from `opt/ffmpeg-full/bin`; `doctor` says so, and `doctor --json` gives `ffmpeg_path` / `ffmpeg_source`); any other `ffmpeg` on `PATH` (a tap build, MacPorts, a static download) is used as it is. With no `ffmpeg` on `PATH` at all, or to make the whole shell use it, do one of two things:
- **Put it first on `PATH`.** Add `export PATH="$(brew --prefix ffmpeg-full)/bin:$PATH"` to your shell profile. `brew --prefix ffmpeg-full` is the stable `opt/` path, so this survives upgrades, but it only reaches processes started from a shell that read the profile.
- **Link it over the lean formula:** `brew unlink ffmpeg 2>/dev/null; brew link --overwrite --force ffmpeg-full`. Every process finds this one, but `brew doctor` warns about a linked keg-only formula, and an upgrade of the lean `ffmpeg` has been seen to link the lean build back on top without a message. After upgrading, check that `command -v ffmpeg` still resolves into `ffmpeg-full`, and re-run the link if it doesn't.
diff --git a/docs/contract.md b/docs/contract.md
index 4ec86db..97dce4a 100644
--- a/docs/contract.md
+++ b/docs/contract.md
@@ -359,9 +359,12 @@ Names: `ffmpeg`, `ffprobe`, `encoder:<name>`, `filter:<name>`, `bsf:<name>`,
`optional` the union of the conditional ones. With detection (the default)
`available`, `missing` and `missing_optional` are added from `doctor`, which reads
`ffmpeg -encoders / -filters / -bsfs` and looks for a local whisper or Parakeet. Pass `--static`
-to omit detection. Nothing from the environment other than those lists and the
-ffmpeg/ffprobe/python versions is printed; no environment variables, no paths (`doctor`'s
-`hw.default_on` is a boolean derived from `FFMPEG_SKILL_HW`, never its value).
+to omit detection. Nothing from the environment other than those lists, the
+ffmpeg/ffprobe/python versions and the paths of the ffmpeg/ffprobe binaries the tools run
+(`ffmpeg_path`, `ffprobe_path`; a font file's path under `fonts` is the other one) is printed; no
+environment variables (`doctor`'s `hw.default_on` is a boolean derived from `FFMPEG_SKILL_HW`,
+never its value). The two binary paths can sit under a home directory, so read a pasted `doctor`
+before posting it.
`external:whisper` is **optional** for two tools since 1.17: `caption.py`
(`--transcribe`) and `silence.py` (`--filler --transcribe`). Neither requires
@@ -418,6 +421,15 @@ capabilities by hand to answer "can I run `caption.py` on this machine right now
passing overall does not mean every tool is usable (a plain Homebrew `ffmpeg` on macOS is `ok`
for tools that don't need `subtitles`/`drawtext`/`zscale`, but `caption.usable` is `"no"`).
+`doctor`'s `ffmpeg_path`, `ffmpeg_source`, `ffprobe_path` and `ffprobe_source` name the binary the
+tools actually run (`null` when none is on PATH). `*_source` is `"path"` (what PATH resolves) or
+`"homebrew-ffmpeg-full"`: on macOS, when the binary PATH resolves is Homebrew's lean `ffmpeg` /
+`ffmpeg@N` formula (its real path is under `<prefix>/Cellar/ffmpeg…`) and the same prefix has the
+keg-only `opt/ffmpeg-full/bin/<name>`, the tools run that one (#317), because `brew install
+ffmpeg-full` does not put it on PATH and the lean build has no drawtext/subtitles/zscale. Nothing
+else is substituted. `ffmpeg` and `ffprobe` (version strings) keep their meaning; the four keys are
+additive.
+
`doctor`'s `gpu_encoders` field reports GPU-backed encoders (`nvenc`, `videotoolbox`, `qsv`,
`vaapi`, `amf`) present in this ffmpeg *build*, read from `-encoders` alone — `{"status":
"parsed"|"unparsed"|"failed"|"missing", "present": [...]}`. It proves the build shipped the
diff --git a/scripts/_common/__init__.py b/scripts/_common/__init__.py
index 66f9ecf..c044898 100644
--- a/scripts/_common/__init__.py
+++ b/scripts/_common/__init__.py
@@ -55,7 +55,7 @@ from _common.runner import (
add_common, apply_common, _check_existing_output, refuse_existing_outputs, _check_no_overwrite_input, _check_output_path, child_args,
child_limit, _CHILDREN, _cleanup_partial_output, _cmdline, CODECS, Context, DEFAULT_TIMEOUT,
_DRAWTEXT_PENDING, _DRAWTEXT_TMPDIR, _drawtext_tmpdir, dry_run_input_pending, _ENCODERS, _env_timeout,
- ERROR_CODE, ERROR_RETRYABLE, EVEN_SCALE, _execute, _fail, ffmpeg_base, ffmpeg_encoders, _FFMPEG_VERSION,
+ ERROR_CODE, ERROR_RETRYABLE, EVEN_SCALE, _execute, _fail, ffmpeg_base, ffmpeg_encoders, ffmpeg_exe, _FFMPEG_VERSION,
ffmpeg_version, flush_drawtext_textfiles, INSTALL_HINTS, install_signal_handlers, _is_ffmpeg, _limit_for,
_odd_dimension_retry, _on_signal, _OutputLock, _pid_dead, place_output, PROBE_TIMEOUT, _progress_line,
read_text_or_die, refuse_output_is_input, _remember_output, require_tool, run, run_analysis, _run_captured,
@@ -195,7 +195,7 @@ __all__ = [
"_emoji_name_candidates", "EMOJI_RANGES", "_EMOJI_REGIONAL", "emoji_support", "_EMOJI_SUPPORT_CACHE",
"_EMOJI_TAIL", "encoder_args", "_ENCODERS", "_env_timeout", "ERROR_CODE", "ERROR_RETRYABLE", "escape_drawtext",
"escape_filter_path", "EVEN_SCALE", "_execute", "_fail", "_family_rank", "FC_LANG", "_fc_list_fonts",
- "FC_UNKNOWN", "ffmpeg_base", "ffmpeg_encoders", "_FFMPEG_VERSION", "ffmpeg_version", "fingerprint",
+ "FC_UNKNOWN", "ffmpeg_base", "ffmpeg_encoders", "ffmpeg_exe", "_FFMPEG_VERSION", "ffmpeg_version", "fingerprint",
"flush_drawtext_textfiles", "fmt_secs", "fmt_smpte_time", "fmt_srt_time", "font_covers_script",
"font_family_for_script", "font_family_of_file", "FONT_FLAG_HINT", "font_for_script", "FONT_INSTALL_HINT",
"fonts_dir_covers_script", "_fraction", "has_emoji", "info", "INSTALL_HINTS", "install_signal_handlers",
diff --git a/scripts/_common/drawtext.py b/scripts/_common/drawtext.py
index 925b1c0..c130d42 100644
--- a/scripts/_common/drawtext.py
+++ b/scripts/_common/drawtext.py
@@ -10,7 +10,7 @@ import shutil
import subprocess
from typing import Dict, Optional
from _common.decision import escape_filter_path
-from _common.runner import STATE, _DRAWTEXT_PENDING, _drawtext_tmpdir, ffmpeg_version
+from _common.runner import STATE, _DRAWTEXT_PENDING, _drawtext_tmpdir, ffmpeg_exe, ffmpeg_version
def drawtext_boxborderw(vertical: int, horizontal: int) -> str:
@@ -43,7 +43,7 @@ def drawtext_shaping() -> "Dict[str, bool]":
if _SHAPING_BUILD_CACHE:
return dict(_SHAPING_BUILD_CACHE)
text = ""
- exe = shutil.which("ffmpeg")
+ exe = ffmpeg_exe("ffmpeg")[0]
if exe:
for flag in ("-buildconf", "-version"):
try:
diff --git a/scripts/_common/emoji.py b/scripts/_common/emoji.py
index 7e82809..b555054 100644
--- a/scripts/_common/emoji.py
+++ b/scripts/_common/emoji.py
@@ -9,6 +9,7 @@ import shutil
import subprocess
from typing import Any, Dict, List, Tuple, Optional
from _common.emit import die
+from _common.runner import ffmpeg_exe
# --------------------------------------------------------------------------- emoji (1.15)
@@ -192,7 +193,7 @@ def _libass_color_probe() -> "Optional[bool]":
the font listing: Noto Color Emoji installs happily on builds whose freetype/libass has no
colour-bitmap path at all, and those render a monochrome outline instead (measured). ~80 ms.
None means the probe could not be run (no ffmpeg, a failure) -- unknown, not false."""
- exe = shutil.which("ffmpeg")
+ exe = ffmpeg_exe("ffmpeg")[0]
if not exe:
return None
import tempfile
diff --git a/scripts/_common/runner.py b/scripts/_common/runner.py
index 52aa955..f4b99d5 100644
--- a/scripts/_common/runner.py
+++ b/scripts/_common/runner.py
@@ -102,7 +102,7 @@ def ffmpeg_version() -> "Tuple[int, int]":
if _FFMPEG_VERSION is None:
_FFMPEG_VERSION = (0, 0)
try:
- out = subprocess.run(["ffprobe", "-version"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, encoding="utf-8", errors="replace",
+ out = subprocess.run([ffmpeg_exe("ffprobe")[0] or "ffprobe", "-version"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, encoding="utf-8", errors="replace",
timeout=PROBE_TIMEOUT).stdout
m = re.search(r"ffprobe version\s+n?(\d+)\.(\d+)", out)
if m:
@@ -125,9 +125,43 @@ def ffmpeg_version() -> "Tuple[int, int]":
return _FFMPEG_VERSION
+def _homebrew_full_build(path: str, name: str) -> str:
+ """On macOS, the keg-only `ffmpeg-full` binary that should replace `path`, or "".
+
+ Homebrew splits FFmpeg in two: the `ffmpeg` formula is lean (no freetype, libass, fontconfig,
+ harfbuzz, so no drawtext/subtitles/ass) and the keg-only `ffmpeg-full` is not linked onto
+ PATH. `brew install ffmpeg-full` therefore changes nothing for a user whose PATH still reaches
+ the lean one (#317). The swap happens only when `path` resolves into THIS Homebrew prefix's
+ Cellar as `ffmpeg` / `ffmpeg@N` and the same prefix has `opt/ffmpeg-full/bin/<name>`; a tap
+ build, MacPorts, a static download or a custom prefix is left exactly as the user put it."""
+ if platform.system() != "Darwin":
+ return ""
+ real = os.path.realpath(path)
+ prefix, sep, rest = real.partition("/Cellar/")
+ if not sep:
+ return ""
+ formula = rest.split("/", 1)[0]
+ if formula != "ffmpeg" and not re.fullmatch(r"ffmpeg@\d+", formula):
+ return ""
+ full = os.path.join(prefix, "opt", "ffmpeg-full", "bin", name)
+ return full if os.path.isfile(full) and os.access(full, os.X_OK) else ""
+
+
+def ffmpeg_exe(name: str) -> Tuple[str, str]:
+ """`(path, source)` of the ffmpeg/ffprobe the tools run; `("", "")` when none is on PATH.
+
+ `source` is "path" (what PATH resolves) or "homebrew-ffmpeg-full" (see _homebrew_full_build).
+ Not cached: PATH is read every time, as `shutil.which` was before this existed."""
+ found = shutil.which(name)
+ if not found:
+ return "", ""
+ full = _homebrew_full_build(found, name)
+ return (full, "homebrew-ffmpeg-full") if full else (found, "path")
+
+
def require_tool(name: str) -> str:
"""Return the absolute path of ffmpeg/ffprobe or exit with install steps."""
- path = shutil.which(name)
+ path = ffmpeg_exe(name)[0] if name in ("ffmpeg", "ffprobe") else shutil.which(name)
if path:
return path
system = platform.system()
@@ -1297,7 +1331,7 @@ def ffmpeg_encoders() -> set:
_ENCODERS = set()
tool = "ffprobe" if STATE.dry_run else "ffmpeg"
try:
- out = subprocess.run([shutil.which(tool) or tool, "-hide_banner", "-encoders"], stdout=subprocess.PIPE,
+ out = subprocess.run([ffmpeg_exe(tool)[0] or tool, "-hide_banner", "-encoders"], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, text=True, encoding="utf-8", errors="replace", timeout=PROBE_TIMEOUT).stdout
_ENCODERS = set(re.findall(r"^\s*[VAS][.\w]{5}\s+(\S+)", out, re.M))
except (OSError, subprocess.SubprocessError):
diff --git a/scripts/_contract.py b/scripts/_contract.py
index c958f26..d6da5d6 100644
--- a/scripts/_contract.py
+++ b/scripts/_contract.py
@@ -632,13 +632,20 @@ def _parse_ff_list(flag: str, text: str) -> List[str]:
return names
+def _exe(binary: str) -> str:
+ """The ffmpeg/ffprobe the tools run (PATH, or Homebrew's keg-only ffmpeg-full over a lean one:
+ _common.runner.ffmpeg_exe), so doctor reports the build the tools will use, not the one PATH names."""
+ from _common.runner import ffmpeg_exe
+ return ffmpeg_exe(binary)[0]
+
+
def _ff_listing(binary: str, flag: str) -> Dict[str, Any]:
"""`{"names": [...], "status": parsed | unparsed | failed | missing, "detail": str}` for `ffmpeg <flag>`.
`parsed`: rows recognised. `unparsed`: ffmpeg ran but no row matched, so the capabilities it
covers are unknown, not absent. `failed`: ffmpeg exited non-zero. `missing`: no binary on PATH.
"""
- exe = shutil.which(binary)
+ exe = _exe(binary)
if not exe:
return {"names": [], "status": "missing", "detail": f"{binary} not on PATH"}
try:
@@ -684,7 +691,7 @@ def _gpu_encoders(encoders_listing: Dict[str, Any]) -> Dict[str, Any]:
def _version_line(binary: str) -> Optional[str]:
- exe = shutil.which(binary)
+ exe = _exe(binary)
if not exe:
return None
try:
@@ -696,6 +703,19 @@ def _version_line(binary: str) -> Optional[str]:
return m.group(1) if m else (first[0] if first else "unknown")
+def _exe_report() -> Dict[str, Any]:
+ """`ffmpeg_path` / `ffmpeg_source` / `ffprobe_path` / `ffprobe_source`: which binary the tools run
+ and why ("path": what PATH resolves; "homebrew-ffmpeg-full": macOS, a lean Homebrew ffmpeg on
+ PATH replaced by the keg-only ffmpeg-full of the same prefix, #317). None when not on PATH."""
+ from _common.runner import ffmpeg_exe
+ out: Dict[str, Any] = {}
+ for name in ("ffmpeg", "ffprobe"):
+ path, source = ffmpeg_exe(name)
+ out[f"{name}_path"] = path or None
+ out[f"{name}_source"] = source or None
+ return out
+
+
def _whisper_available() -> bool:
if shutil.which("whisper-cli") or shutil.which("whisper-cpp") or shutil.which("whisper"):
return True
@@ -742,7 +762,7 @@ def _drawtext_probe() -> Dict[str, Any]:
fontfile= render works but a bare one crashes, drawtext stays available and the result
carries a `note`: only a fontconfig lookup (`--font <family>` with no file) would crash.
"""
- exe = shutil.which("ffmpeg")
+ exe = _exe("ffmpeg")
if not exe:
return {"status": "unknown", "detail": "ffmpeg not on PATH"}
# Probe the way the tools call drawtext: with the fontfile= they pick by default (#298). On a
@@ -867,6 +887,7 @@ def doctor() -> Dict[str, Any]:
state: Dict[str, str] = {} # capability -> available | missing | unknown
wanted = required_capabilities()
drawtext_probe: Optional[Dict[str, Any]] = None
+ drawtext_crashed = False # listed but crashed (#100), as opposed to absent from the build
def _from(kind: str, name: str) -> str:
lst = listings[kind]
@@ -878,9 +899,9 @@ def doctor() -> Dict[str, Any]:
for cap in wanted["required"] + wanted["optional"]:
if cap == "ffmpeg":
- state[cap] = "available" if shutil.which("ffmpeg") else "missing"
+ state[cap] = "available" if _exe("ffmpeg") else "missing"
elif cap == "ffprobe":
- state[cap] = "available" if shutil.which("ffprobe") else "missing"
+ state[cap] = "available" if _exe("ffprobe") else "missing"
elif cap.startswith("encoder:"):
state[cap] = _from("encoders", cap[8:])
elif cap == "filter:drawtext":
@@ -897,6 +918,7 @@ def doctor() -> Dict[str, Any]:
drawtext_probe = probe
if probe["status"] == "missing":
drawtext_probe = probe
+ drawtext_crashed = True
state[cap] = "missing"
else:
state[cap] = "available"
@@ -926,6 +948,7 @@ def doctor() -> Dict[str, Any]:
"python": ".".join(str(x) for x in sys.version_info[:3]),
"ffmpeg": _version_line("ffmpeg"),
"ffprobe": _version_line("ffprobe"),
+ **_exe_report(),
"available": available,
"missing": missing_required,
"missing_optional": missing_optional,
@@ -934,7 +957,7 @@ def doctor() -> Dict[str, Any]:
"errors": errors,
**({"notes": notes} if notes else {}),
"ok": not missing_required and not unknown_required,
- "tools": _tool_usability(state),
+ "tools": _tool_usability(state, drawtext_crashed),
"gpu_encoders": _gpu_encoders(listings["encoders"]),
"hw": _hw_default(),
"fonts": _fonts_capability(probe=True),
@@ -1006,7 +1029,7 @@ def _fonts_summary_line(fonts: Dict[str, Any]) -> str:
return "; ".join(parts)
-def _capability_fix_hint(cap: str) -> str:
+def _capability_fix_hint(cap: str, drawtext_crashed: bool = False) -> str:
"""One-line, plain-language remedy for a single missing/unknown capability."""
if cap in ("ffmpeg", "ffprobe"):
from _common import INSTALL_HINTS
@@ -1026,6 +1049,8 @@ def _capability_fix_hint(cap: str) -> str:
full_hint = "install/build ffmpeg with it enabled"
if cap.startswith("encoder:"):
return f"this ffmpeg build has no {cap[8:]} encoder; {full_hint}"
+ if cap == "filter:drawtext" and not drawtext_crashed:
+ return f"this ffmpeg build has no drawtext filter (no freetype); {full_hint}"
if cap == "filter:drawtext":
return ("drawtext crashed instead of rendering a frame (see errors[] for the exit detail) -- "
"every drawtext tool already resolves a concrete font file automatically when one can "
@@ -1054,7 +1079,7 @@ def _capability_fix_hint(cap: str) -> str:
return f"'{cap}' is not available; see docs/contract.md"
-def _tool_usability(state: Dict[str, str]) -> Dict[str, Dict[str, Any]]:
+def _tool_usability(state: Dict[str, str], drawtext_crashed: bool = False) -> Dict[str, Dict[str, Any]]:
"""Per-tool usable/missing/unknown, folded from the same capability `state` doctor already
computed. Answers "can I run this tool on this machine today", not just "what capabilities
exist" -- a caller reading only `available`/`missing` still has to cross-reference each tool's
@@ -1067,7 +1092,7 @@ def _tool_usability(state: Dict[str, str]) -> Dict[str, Dict[str, Any]]:
entry: Dict[str, Any] = {"usable": "no" if missing else ("unknown" if unknown else "yes")}
if missing:
entry["missing"] = missing
- entry["fix"] = "; ".join(dict.fromkeys(_capability_fix_hint(c) for c in missing))
+ entry["fix"] = "; ".join(dict.fromkeys(_capability_fix_hint(c, drawtext_crashed) for c in missing))
if unknown:
entry["unknown"] = unknown
tools[name] = entry
@@ -1507,6 +1532,9 @@ def main() -> int:
else:
print(f"ffmpeg-skill {d['version']} (this installed copy; re-run `npx ffmpeg-skill` to refresh it -- copies are not updated automatically)")
print(f"python {d['python']}; ffmpeg {d['ffmpeg'] or 'MISSING'}; ffprobe {d['ffprobe'] or 'MISSING'}")
+ for name in ("ffmpeg", "ffprobe"):
+ if d[f"{name}_source"] == "homebrew-ffmpeg-full":
+ print(f"{name} runs from {d[f'{name}_path']}: Homebrew's keg-only ffmpeg-full, used because the {name} on PATH is the lean formula (no drawtext/subtitles)")
# counts, not the full capability list: the names of the ~60 available capabilities
# answer no question a caller has (they are in `doctor --json .available` when one
# does), while what is MISSING is the whole reason to run doctor (1.11.0 token diet).
diff --git a/scripts/look.py b/scripts/look.py
index dd53b8f..bf9fcd1 100755
--- a/scripts/look.py
+++ b/scripts/look.py
@@ -17,7 +17,7 @@ from pathlib import Path
from typing import List, Optional
from _platforms import PLATFORMS, PLATFORM_CHOICES, resolve as resolve_platform
-from _common import STATE, add_common, apply_common, default_font_file, die, emit, escape_drawtext, escape_filter_path, ffmpeg_base, info, parse_time, probe, run, run_analysis, time_arg
+from _common import STATE, require_tool, add_common, apply_common, default_font_file, die, emit, escape_drawtext, escape_filter_path, ffmpeg_base, info, parse_time, probe, run, run_analysis, time_arg
FONT = "fontcolor=white:fontsize=h/18:box=1:[email protected]:boxborderw=6:x=8:y=8"
@@ -37,7 +37,7 @@ def _png_size(png_path: str) -> "Optional[tuple]":
# ffprobe/ffmpeg measurement in this codebase, check=False since a probe failure here is
# an unknown-metric result (has_ink: None), not a reason to die -- a stall still does,
# exactly like every other measurement's timeout.
- proc = run_analysis(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries",
+ proc = run_analysis([require_tool("ffprobe"), "-v", "error", "-select_streams", "v:0", "-show_entries",
"stream=width,height", "-of", "csv=p=0", png_path], check=False)
parts = proc.stdout.strip().split(",")
if len(parts) != 2:
@@ -49,7 +49,7 @@ def _png_size(png_path: str) -> "Optional[tuple]":
def _png_pixels(png_path: str, w: int, h: int) -> "Optional[bytes]":
- proc = run_analysis(["ffmpeg", "-v", "error", "-i", png_path, "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
+ proc = run_analysis([require_tool("ffmpeg"), "-v", "error", "-i", png_path, "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
check=False, text=False)
data = proc.stdout
return data if len(data) >= w * h * 3 else None
diff --git a/scripts/render.py b/scripts/render.py
index aecbad3..b44a3f1 100755
--- a/scripts/render.py
+++ b/scripts/render.py
@@ -64,7 +64,7 @@ from typing import Any, Dict, List, Optional, Sequence
from export import PRESETS, PLATFORM_OF
from _platforms import PLATFORMS, caption_defaults, resolve as resolve_platform
-from _common import STATE, add_common, aspect_ratio, brand_caption_style, load_brand, apply_common, child_args, die, emit, info, probe, require_tool, run, run_tool, place_output, refuse_output_is_input, _check_existing_output, _check_output_path, fingerprint, PLAN_VERSION, ffmpeg_version
+from _common import STATE, add_common, aspect_ratio, brand_caption_style, load_brand, apply_common, child_args, die, emit, info, probe, require_tool, run, run_tool, place_output, refuse_output_is_input, _check_existing_output, _check_output_path, fingerprint, PLAN_VERSION, ffmpeg_version, ffmpeg_exe
from _common.runner import HW_ENV, HW_FORCED_ENV, add_hw_orchestrator_args
from _common.emit import absorb_stage_hw
import subprocess
@@ -605,7 +605,7 @@ def ffmpeg_banner() -> str:
key. Unreadable falls back to the parsed pair, which still separates the major releases.
"""
try:
- out = subprocess.run(["ffprobe", "-version"], stdout=subprocess.PIPE,
+ out = subprocess.run([ffmpeg_exe("ffprobe")[0] or "ffprobe", "-version"], stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, text=True, encoding="utf-8", errors="replace", timeout=20).stdout
first = (out or "").strip().splitlines()
if first:
diff --git a/tests/test_contract.py b/tests/test_contract.py
index 4c355a6..4f2793a 100644
--- a/tests/test_contract.py
+++ b/tests/test_contract.py
@@ -796,6 +796,86 @@ class ContractTests(unittest.TestCase):
readme = (ROOT / "README.md").read_text(encoding="utf-8")
self.assertIn("Gyan.FFmpeg", readme)
+ def _brew_tree(self, formula="ffmpeg", full=True, other_prefix_full=False):
+ """A fake Homebrew prefix: PATH's bin/ffmpeg(+ffprobe) symlink into Cellar/<formula>, and
+ opt/ffmpeg-full/bin/* when `full`. Returns (prefix, bin_dir)."""
+ td = Path(tempfile.mkdtemp(prefix="brew-", dir=OUT))
+ self.addCleanup(shutil.rmtree, td, True)
+ prefix = td / "prefix"
+ for name in ("ffmpeg", "ffprobe"):
+ real = prefix / "Cellar" / formula / "7.1" / "bin" / name
+ real.parent.mkdir(parents=True, exist_ok=True)
+ real.write_text("#!/bin/sh\n")
+ real.chmod(0o755)
+ (prefix / "bin").mkdir(exist_ok=True)
+ (prefix / "bin" / name).symlink_to(real)
+ if full:
+ f = prefix / "opt" / "ffmpeg-full" / "bin" / name
+ f.parent.mkdir(parents=True, exist_ok=True)
+ f.write_text("#!/bin/sh\n")
+ f.chmod(0o755)
+ if other_prefix_full:
+ f = td / "other" / "opt" / "ffmpeg-full" / "bin" / "ffmpeg"
+ f.parent.mkdir(parents=True)
+ f.write_text("#!/bin/sh\n")
+ f.chmod(0o755)
+ return prefix, prefix / "bin"
+
+ def _exe(self, name, bindir, system="Darwin"):
+ from unittest import mock
+ from _common.runner import ffmpeg_exe
+ with mock.patch("platform.system", return_value=system), mock.patch.dict(os.environ, {"PATH": str(bindir)}):
+ return ffmpeg_exe(name)
+
+ @unittest.skipIf(os.name == "nt", "symlinked fake Homebrew prefix")
+ def test_lean_homebrew_ffmpeg_is_replaced_by_ffmpeg_full_of_the_same_prefix(self):
+ """#317: brew install ffmpeg-full is keg-only, so PATH keeps the lean formula; both
+ binaries come from opt/ffmpeg-full, and the result says why."""
+ prefix, bindir = self._brew_tree()
+ for name in ("ffmpeg", "ffprobe"):
+ path, source = self._exe(name, bindir)
+ self.assertEqual((path, source), (str(prefix / "opt" / "ffmpeg-full" / "bin" / name), "homebrew-ffmpeg-full"))
+ _, bindir = self._brew_tree(formula="ffmpeg@7")
+ self.assertEqual(self._exe("ffmpeg", bindir)[1], "homebrew-ffmpeg-full")
+
+ @unittest.skipIf(os.name == "nt", "symlinked fake Homebrew prefix")
+ def test_ffmpeg_is_left_alone_unless_it_is_the_lean_homebrew_formula(self):
+ """Not macOS, no ffmpeg-full installed, a different formula, a binary outside any Cellar and
+ an ffmpeg-full of ANOTHER prefix all keep what PATH resolves."""
+ prefix, bindir = self._brew_tree()
+ self.assertEqual(self._exe("ffmpeg", bindir, system="Linux"), (str(bindir / "ffmpeg"), "path"))
+ _, bindir = self._brew_tree(full=False)
+ self.assertEqual(self._exe("ffmpeg", bindir)[1], "path")
+ _, bindir = self._brew_tree(formula="ffmpeg-custom")
+ self.assertEqual(self._exe("ffmpeg", bindir)[1], "path")
+ _, bindir = self._brew_tree(full=False, other_prefix_full=True)
+ self.assertEqual(self._exe("ffmpeg", bindir)[1], "path")
+ plain = Path(tempfile.mkdtemp(prefix="plain-", dir=OUT))
+ self.addCleanup(shutil.rmtree, plain, True)
+ (plain / "ffmpeg").write_text("#!/bin/sh\n")
+ (plain / "ffmpeg").chmod(0o755)
+ self.assertEqual(self._exe("ffmpeg", plain), (str(plain / "ffmpeg"), "path"))
+ self.assertEqual(self._exe("ffprobe", plain), ("", ""))
+
+ @unittest.skipIf(os.name == "nt", "symlinked fake Homebrew prefix")
+ def test_doctor_names_the_binary_it_will_run(self):
+ """doctor's additive keys, and its plain output, say which build runs and why."""
+ from unittest import mock
+ prefix, bindir = self._brew_tree()
+ with mock.patch("platform.system", return_value="Darwin"), mock.patch.dict(os.environ, {"PATH": str(bindir)}):
+ rep = _contract._exe_report()
+ self.assertEqual(rep["ffmpeg_path"], str(prefix / "opt" / "ffmpeg-full" / "bin" / "ffmpeg"))
+ self.assertEqual(rep["ffprobe_source"], "homebrew-ffmpeg-full")
+ d = json.loads(sh(sys.executable, SCRIPTS / "_contract.py", "doctor", "--json").stdout)
+ for key in ("ffmpeg_path", "ffmpeg_source", "ffprobe_path", "ffprobe_source"):
+ self.assertIn(key, d)
+
+ def test_drawtext_fix_hint_tells_an_absent_filter_from_a_crash(self):
+ absent = _contract._capability_fix_hint("filter:drawtext")
+ self.assertIn("no drawtext filter", absent)
+ self.assertNotIn("crashed", absent)
+ self.assertIn("crashed", _contract._capability_fix_hint("filter:drawtext", True))
+
def test_macos_fix_hint_says_ffmpeg_full_is_keg_only(self):
"""Homebrew's ffmpeg-full is keg-only: `brew install ffmpeg-full` alone leaves the lean
formula (or no ffmpeg) on PATH, so a hint that only says to install it sends the user