This commit is contained in:
eric
2026-03-25 09:40:29 -05:00
parent 23a8996114
commit 5996df8702
72 changed files with 1347 additions and 18322 deletions

41
web2_host_caps.py Normal file
View File

@@ -0,0 +1,41 @@
"""本机能力探测GPU 等(供控制台 UI"""
from __future__ import annotations
import platform
import subprocess
from typing import Any
def detect_nvidia_gpu() -> bool:
if platform.system().lower() not in ("windows", "linux"):
return False
try:
_kw: dict = {"capture_output": True, "timeout": 4}
if platform.system().lower() == "windows":
_kw["creationflags"] = subprocess.CREATE_NO_WINDOW
r = subprocess.run(["nvidia-smi"], **_kw)
return r.returncode == 0
except Exception:
return False
def detect_nvenc_available() -> bool:
if not detect_nvidia_gpu():
return False
try:
_kw = {"capture_output": True, "text": True, "timeout": 8}
if platform.system().lower() == "windows":
_kw["creationflags"] = subprocess.CREATE_NO_WINDOW
r = subprocess.run(["ffmpeg", "-hide_banner", "-encoders"], **_kw)
return r.returncode == 0 and "h264_nvenc" in (r.stdout or "")
except Exception:
return False
def gpu_status_payload() -> dict[str, Any]:
nv = detect_nvidia_gpu()
enc = detect_nvenc_available()
return {
"nvidia_detected": nv,
"nvenc_available": enc,
}