first commit

This commit is contained in:
Jefferyhcool
2025-04-13 17:44:54 +08:00
commit 0e0b8da317
112 changed files with 4397 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import os
import subprocess
from dotenv import load_dotenv
load_dotenv()
def check_ffmpeg_exists() -> bool:
"""
检查 ffmpeg 是否可用。优先使用 FFMPEG_BIN_PATH 环境变量指定的路径。
"""
ffmpeg_bin_path = os.getenv("FFMPEG_BIN_PATH")
print(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", "")
try:
subprocess.run(["ffmpeg", "-version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
return True
except (FileNotFoundError, OSError, subprocess.CalledProcessError):
return False
def ensure_ffmpeg_or_raise():
"""
校验 ffmpeg 是否可用,否则抛出异常并提示安装方式。
"""
if not check_ffmpeg_exists():
raise EnvironmentError(
"❌ 未检测到 ffmpeg,请先安装后再使用本功能。\n"
"👉 下载地址:https://ffmpeg.org/download.html\n"
"🪟 Windows 推荐:https://www.gyan.dev/ffmpeg/builds/\n"
"💡 如果你已安装,请将其路径写入 `.env` 文件,例如:\n"
"FFMPEG_BIN_PATH=/your/custom/ffmpeg/bin"
)