forked from Github/frigate
Automatically detect hwaccel args (#9142)
* Automatically detect nvidia / vaapi hwaccel args * Update docs * Use auto for hwaccel args * Formatting
This commit is contained in:
committed by
Blake Blackshear
parent
a946a8f099
commit
0ee81c7526
@@ -13,7 +13,9 @@ from typing import Optional
|
||||
import cv2
|
||||
import psutil
|
||||
import py3nvml.py3nvml as nvml
|
||||
import requests
|
||||
|
||||
from frigate.const import FFMPEG_HWACCEL_NVIDIA, FFMPEG_HWACCEL_VAAPI
|
||||
from frigate.util.builtin import clean_camera_user_pass, escape_special_characters
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -371,6 +373,38 @@ def vainfo_hwaccel(device_name: Optional[str] = None) -> sp.CompletedProcess:
|
||||
return sp.run(ffprobe_cmd, capture_output=True)
|
||||
|
||||
|
||||
def auto_detect_hwaccel() -> str:
|
||||
"""Detect hwaccel args by default."""
|
||||
try:
|
||||
cuda = False
|
||||
vaapi = False
|
||||
resp = requests.get("http://192.168.50.106:1984/api/ffmpeg/hardware", timeout=3)
|
||||
|
||||
if resp.status_code == 200:
|
||||
data: dict[str, list[dict[str, str]]] = resp.json()
|
||||
for source in data.get("sources", []):
|
||||
if "cuda" in source.get("url", "") and source.get("name") == "OK":
|
||||
cuda = True
|
||||
|
||||
if "vaapi" in source.get("url", "") and source.get("name") == "OK":
|
||||
vaapi = True
|
||||
except requests.RequestException:
|
||||
pass
|
||||
|
||||
if cuda:
|
||||
logger.info("Automatically detected nvidia hwaccel for video decoding")
|
||||
return FFMPEG_HWACCEL_NVIDIA
|
||||
|
||||
if vaapi:
|
||||
logger.info("Automatically detected vaapi hwaccel for video decoding")
|
||||
return FFMPEG_HWACCEL_VAAPI
|
||||
|
||||
logger.warning(
|
||||
"Did not detect hwaccel, using a GPU for accelerated video decoding is highly recommended"
|
||||
)
|
||||
return ""
|
||||
|
||||
|
||||
async def get_video_properties(url, get_duration=False) -> dict[str, any]:
|
||||
async def calculate_duration(video: Optional[any]) -> float:
|
||||
duration = None
|
||||
|
||||
Reference in New Issue
Block a user