From 844e1a102ac44421561b77c976dfda701ca4ae01 Mon Sep 17 00:00:00 2001 From: Sjshi763 Date: Sat, 3 Jan 2026 14:57:42 +0800 Subject: [PATCH] =?UTF-8?q?[BUG]=20=E5=B7=B2=E7=BB=8F=E6=8A=8Affmpeg?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=88=B0=E7=B3=BB=E7=BB=9F=E5=8F=98=E9=87=8F?= =?UTF-8?q?path=E4=BA=86=20=E8=BF=98=E6=98=AF=E6=A3=80=E6=B5=8B=E4=B8=8D?= =?UTF-8?q?=E5=87=BA=E6=9D=A5=20=3F=20Fixes=20#232?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/ffmpeg_helper.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/ffmpeg_helper.py b/backend/ffmpeg_helper.py index b116aee..5653195 100644 --- a/backend/ffmpeg_helper.py +++ b/backend/ffmpeg_helper.py @@ -14,7 +14,17 @@ def check_ffmpeg_exists() -> bool: logger.info(f"FFMPEG_BIN_PATH: {ffmpeg_bin_path}") if ffmpeg_bin_path and os.path.isdir(ffmpeg_bin_path): os.environ["PATH"] = ffmpeg_bin_path + os.pathsep + os.environ.get("PATH", "") - logger.info(f"ffmpeg 未配置路径,尝试使用系统路径PATH: {os.environ.get('PATH')}") + logger.info(f"使用FFMPEG_BIN_PATH: {ffmpeg_bin_path}") + else: + # 遍历系统PATH寻找ffmpeg.exe + system_path = os.environ.get("PATH", "") + path_dirs = system_path.split(os.pathsep) + for path_dir in path_dirs: + ffmpeg_exe_path = os.path.join(path_dir, "ffmpeg.exe") + if os.path.isfile(ffmpeg_exe_path): + os.environ["PATH"] = path_dir + os.pathsep + system_path + logger.info(f"在系统PATH中找到ffmpeg: {path_dir}") + break try: subprocess.run(["ffmpeg", "-version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True) logger.info("ffmpeg 已安装") @@ -36,4 +46,4 @@ def ensure_ffmpeg_or_raise(): "🪟 Windows 推荐:https://www.gyan.dev/ffmpeg/builds/\n" "💡 如果你已安装,请将其路径写入 `.env` 文件,例如:\n" "FFMPEG_BIN_PATH=/your/custom/ffmpeg/bin" - ) \ No newline at end of file + )