Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,18 +80,33 @@ VIDEO_CONFIG = {
|
|
| 80 |
def detect_hw_encoder():
|
| 81 |
try:
|
| 82 |
result = subprocess.run(["ffmpeg", "-encoders"], capture_output=True, text=True)
|
|
|
|
|
|
|
| 83 |
if 'h264_videotoolbox' in result.stdout:
|
| 84 |
-
|
| 85 |
-
return 'h264_videotoolbox', '65'
|
| 86 |
if 'h264_nvenc' in result.stdout:
|
| 87 |
-
|
| 88 |
-
return 'h264_nvenc', '23'
|
| 89 |
if 'h264_qsv' in result.stdout:
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
except:
|
| 93 |
pass
|
| 94 |
-
logger.
|
| 95 |
return None, None
|
| 96 |
|
| 97 |
_hw_encoder, _hw_quality = detect_hw_encoder()
|
|
|
|
| 80 |
def detect_hw_encoder():
|
| 81 |
try:
|
| 82 |
result = subprocess.run(["ffmpeg", "-encoders"], capture_output=True, text=True)
|
| 83 |
+
|
| 84 |
+
candidates = []
|
| 85 |
if 'h264_videotoolbox' in result.stdout:
|
| 86 |
+
candidates.append(('h264_videotoolbox', '65'))
|
|
|
|
| 87 |
if 'h264_nvenc' in result.stdout:
|
| 88 |
+
candidates.append(('h264_nvenc', '23'))
|
|
|
|
| 89 |
if 'h264_qsv' in result.stdout:
|
| 90 |
+
candidates.append(('h264_qsv', '23'))
|
| 91 |
+
|
| 92 |
+
# Test each encoder with a tiny encode
|
| 93 |
+
for encoder, quality in candidates:
|
| 94 |
+
try:
|
| 95 |
+
test = subprocess.run([
|
| 96 |
+
"ffmpeg", "-f", "lavfi", "-i", "color=c=black:s=16x16:d=0.1",
|
| 97 |
+
"-c:v", encoder, "-q:v", quality,
|
| 98 |
+
"-f", "null", "-"
|
| 99 |
+
], capture_output=True, text=True, timeout=5)
|
| 100 |
+
if test.returncode == 0:
|
| 101 |
+
logger.info(f"✅ GPU encoder verified: {encoder}")
|
| 102 |
+
return encoder, quality
|
| 103 |
+
else:
|
| 104 |
+
logger.warning(f"⚠️ {encoder} listed but failed test encode")
|
| 105 |
+
except:
|
| 106 |
+
logger.warning(f"⚠️ {encoder} test timed out")
|
| 107 |
except:
|
| 108 |
pass
|
| 109 |
+
logger.info("ℹ️ No working GPU encoder — using libx264")
|
| 110 |
return None, None
|
| 111 |
|
| 112 |
_hw_encoder, _hw_quality = detect_hw_encoder()
|