Skip to content

NVR with realtime local object detection for IP cameras

refactor vainfo to search for first GPU (#21296)

Josh Hawkins85feb4edcba8
diff --git a/frigate/api/app.py b/frigate/api/app.py
index 440adfce4f..3a91c8ebbb 100644
--- a/frigate/api/app.py
+++ b/frigate/api/app.py
@@ -37,6 +37,7 @@ from frigate.config.camera.updater import (
CameraConfigUpdateEnum,
CameraConfigUpdateTopic,
)
+from frigate.ffmpeg_presets import FFMPEG_HWACCEL_VAAPI, _gpu_selector
from frigate.models import Event, Timeline
from frigate.stats.prometheus import get_metrics, update_metrics
from frigate.util.builtin import (
@@ -463,7 +464,15 @@ def config_set(request: Request, body: AppConfigSetBody):
@router.get("/vainfo", dependencies=[Depends(allow_any_authenticated())])
def vainfo():
- vainfo = vainfo_hwaccel()
+ # Use LibvaGpuSelector to pick an appropriate libva device (if available)
+ selected_gpu = ""
+ try:
+ selected_gpu = _gpu_selector.get_gpu_arg(FFMPEG_HWACCEL_VAAPI, 0) or ""
+ except Exception:
+ selected_gpu = ""
+
+ # If selected_gpu is empty, pass None to vainfo_hwaccel to run plain `vainfo`.
+ vainfo = vainfo_hwaccel(device_name=selected_gpu or None)
return JSONResponse(
content={
"return_code": vainfo.returncode,
diff --git a/frigate/util/services.py b/frigate/util/services.py
index 64d83833dc..9420732bed 100644
--- a/frigate/util/services.py
+++ b/frigate/util/services.py
@@ -591,12 +591,17 @@ def ffprobe_stream(ffmpeg, path: str, detailed: bool = False) -> sp.CompletedPro
def vainfo_hwaccel(device_name: Optional[str] = None) -> sp.CompletedProcess:
"""Run vainfo."""
- ffprobe_cmd = (
- ["vainfo"]
- if not device_name
- else ["vainfo", "--display", "drm", "--device", f"/dev/dri/{device_name}"]
- )
- return sp.run(ffprobe_cmd, capture_output=True)
+ if not device_name:
+ cmd = ["vainfo"]
+ else:
+ if os.path.isabs(device_name) and device_name.startswith("/dev/dri/"):
+ device_path = device_name
+ else:
+ device_path = f"/dev/dri/{device_name}"
+
+ cmd = ["vainfo", "--display", "drm", "--device", device_path]
+
+ return sp.run(cmd, capture_output=True)
def get_nvidia_driver_info() -> dict[str, Any]: