Skip to content

Commit bc57eb0

Browse files
committed
Enhance encoder selection logic for better OS and hardware compatibility
1 parent e7385d0 commit bc57eb0

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Windows | `hevc_nvenc` -> `hevc_amf` -> `hevc_qsv` -> `libx265` (CPU) | Explicit
6060
Linux | `hevc_nvenc` -> `hevc_vaapi` -> `libx265` (CPU) | `vaapi` covers both AMD and Intel integrated/dedicated.
6161
MacOS | `hevc_videotoolbox` -> `libx265` (CPU only) | VideoToolbox automatically handles AMD, Intel, & Apple Silicon. Older Nvidia GPUs aren't used by Nvidia Video Codec SDK on MacOS and handled by VideoToolbox if supported.
6262

63-
Considering the wide variety of hardware configurations, the script uses the following priority logic to select the best available encoder on majority of users' systems:
63+
Considering the wide variety of hardware configurations, the script uses the following priority logic to select the best available encoder on majority of users' systems (fallback logic):
6464
> `hevc_nvenc` > `hevc_vaapi` > `hevc_videotoolbox` > `hevc_amf` > `hevc_qsv` > `libx265` (CPU)
6565
6666
> [!NOTE]

videocompress.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,28 @@ def check_encoder_available(encoder_name: str) -> bool:
103103
return False
104104

105105
def select_best_encoder() -> str:
106-
"""Select the best available encoder.
107-
108-
Preference order: NVENC > VAAPI > VideoToolbox > AMF > QSV > CPU.
106+
"""Detect the best available encoder based on OS and Hardware.
109107
110108
Returns:
111-
Encoder name to use (e.g., "hevc_nvenc" or "libx265").
109+
Encoder name (e.g., 'hevc_nvenc') or 'libx265' if none found.
112110
"""
113-
priority_chain = [
114-
"hevc_nvenc",
115-
"hevc_vaapi",
116-
"hevc_videotoolbox",
117-
"hevc_amf",
118-
"hevc_qsv"
119-
]
120-
121-
print("Checking available encoders...")
111+
# 1. Determine priority chain based on OS to avoid useless checks
112+
if sys.platform.startswith("linux"):
113+
# Linux: Nvidia or VAAPI (Intel/AMD)
114+
priority_chain = ["hevc_nvenc", "hevc_vaapi"]
115+
elif sys.platform == "darwin":
116+
# MacOS: VideoToolbox (Standard)
117+
priority_chain = ["hevc_videotoolbox"]
118+
elif sys.platform == "win32":
119+
# Windows: Nvidia -> AMD (AMF) -> Intel (QSV)
120+
priority_chain = ["hevc_nvenc", "hevc_amf", "hevc_qsv"]
121+
else:
122+
# Fallback: Check everything
123+
priority_chain = ["hevc_nvenc", "hevc_vaapi", "hevc_videotoolbox", "hevc_amf", "hevc_qsv"]
124+
125+
print(f"OS: {sys.platform}. Checking encoders: {', '.join(priority_chain)}...")
126+
127+
# 2. Check each candidate
122128
for enc in priority_chain:
123129
is_available = check_encoder_available(enc)
124130
print(f" {enc}: {'Available' if is_available else 'Unavailable'}")

0 commit comments

Comments
 (0)