's'
This commit is contained in:
41
web2_host_caps.py
Normal file
41
web2_host_caps.py
Normal 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,
|
||||
}
|
||||
Reference in New Issue
Block a user