diff --git a/README.md b/README.md index f487de2f..31d0fdc9 100644 --- a/README.md +++ b/README.md @@ -3225,6 +3225,8 @@ enable [smb](#smb-server) support (**not** recommended): `impacket==0.13.0` to install FFmpeg on Windows, grab [a recent build](https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z) -- you need `ffmpeg.exe` and `ffprobe.exe` from inside the `bin` folder; copy them into `C:\Windows\System32` or any other folder that's in your `%PATH%` +if your ffmpeg/ffprobe binaries have nonstandard names -- such as `ffmpeg8` (macports) -- set environment variables `PRTY_FFMPEG_BIN` and `PRTY_FFPROBE_BIN` to the corret name (or full path) + ### dependency chickenbits diff --git a/copyparty/mtag.py b/copyparty/mtag.py index 65dcd9b8..c25d4538 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -46,24 +46,33 @@ except: HAVE_MUTAGEN = False -def have_ff(scmd: str) -> bool: - if ANYWIN: - scmd += ".exe" +def have_ff(name: str) -> bool: + uname = name.upper() + if os.environ.get("PRTY_NO_" + uname): + return b"" + + ebin = os.environ.get("PRTY_%s_BIN" % (uname,)) + try: + bcmd = (ebin or name).encode("utf-8") + except: + bcmd = ebin or name + + if ANYWIN and not ebin: + bcmd += b".exe" if PY2: - print("# checking {}".format(scmd)) - acmd = (scmd + " -version").encode("ascii").split(b" ") + print("# checking {}".format(bcmd)) try: - sp.Popen(acmd, stdout=sp.PIPE, stderr=sp.PIPE).communicate() - return True + sp.Popen([bcmd, b"-version"], stdout=sp.PIPE, stderr=sp.PIPE).communicate() + return bcmd except: - return False + return b"" else: - return bool(shutil.which(scmd)) + return shutil.which(bcmd) or b"" -HAVE_FFMPEG = not os.environ.get("PRTY_NO_FFMPEG") and have_ff("ffmpeg") -HAVE_FFPROBE = not os.environ.get("PRTY_NO_FFPROBE") and have_ff("ffprobe") +HAVE_FFMPEG = have_ff("ffmpeg") +HAVE_FFPROBE = have_ff("ffprobe") CBZ_PICS = set("png jpg jpeg gif bmp tga tif tiff webp avif jxl".split()) CBZ_01 = re.compile(r"(^|[^0-9v])0+[01]\b") @@ -219,7 +228,7 @@ def ffprobe( ) -> tuple[dict[str, tuple[int, Any]], dict[str, list[Any]], list[Any], dict[str, Any]]: # ffprobe -hide_banner -show_streams -show_format -- cmd = [ - b"ffprobe", + HAVE_FFPROBE, b"-hide_banner", b"-show_streams", b"-show_format", diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 21896a04..0153bf0f 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -860,7 +860,7 @@ class ThumbSrv(object): bscale = scale.format(*list(res)).encode("utf-8") # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner" @@ -1001,7 +1001,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1080,7 +1080,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1112,7 +1112,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1148,7 +1148,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1177,7 +1177,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1212,7 +1212,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1273,7 +1273,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1314,7 +1314,7 @@ class ThumbSrv(object): # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1340,7 +1340,7 @@ class ThumbSrv(object): self.log("conv2 caf-transcode; dur=%d sz=%d q=%s" % (dur, sz, zs), 6) # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner", @@ -1361,7 +1361,7 @@ class ThumbSrv(object): self.log("conv2 caf-remux; dur=%d sz=%d" % (dur, sz), 6) # fmt: off cmd = [ - b"ffmpeg", + HAVE_FFMPEG, b"-nostdin", b"-v", b"error", b"-hide_banner",