Fix NVENC transcode: use system ffmpeg instead of bundled one
Docker Build and Push / check-secrets (push) Successful in 4s
Docker Build and Push / build-and-push (cpu, latest) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 11.8) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 12.6) (push) Has been skipped
Docker Build and Push / build-and-push (cuda, 12.8) (push) Has been skipped
Docker Build and Push / build-and-push (directml, latest) (push) Has been skipped
Build Windows CPU / build (push) Has been cancelled
Build Windows CUDA 11.8 / build (push) Has been cancelled
Build Windows CUDA 12.6 / build (push) Has been cancelled
Build Windows CUDA 12.8 / build (push) Has been cancelled
Build Windows DirectML / build (push) Has been cancelled

Bundled ffmpeg at backend/ffmpeg/linux_x64/ffmpeg has no NVENC support.
System /usr/bin/ffmpeg does. Switch _ensure_h264 to use shutil.which('ffmpeg')
which resolves to /usr/bin/ffmpeg. Also log the actual NVENC error message
so future failures are visible in the task logs.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
liuchen
2026-06-27 15:52:21 +08:00
co-authored by Claude Haiku 4.5
parent 0b2a3ec6e3
commit f21f844f0f
+9 -11
View File
@@ -406,23 +406,21 @@ def _ensure_h264(task_id: str, video_path: str) -> str:
push_log(task_id, "⚠ 视频格式(可能是 AV1/HEVC)OpenCV 无法解码,自动转换为 H.264…")
try:
from backend.tools.ffmpeg_cli import FFmpegCLI
import subprocess
import subprocess, shutil
# 优先系统 ffmpeg(有 NVENC),项目自带的没有编译 NVENC 支持
sys_ffmpeg = shutil.which('ffmpeg') or '/usr/bin/ffmpeg'
push_log(task_id, f"FFmpeg 转码中(H.264 NVENC)…")
cmd = [
FFmpegCLI.instance().ffmpeg_path,
'-y', '-i', video_path,
sys_ffmpeg, '-y', '-i', video_path,
'-c:v', 'h264_nvenc', '-cq', '18', '-preset', 'p4',
'-c:a', 'copy',
'-loglevel', 'error',
converted,
'-c:a', 'copy', '-loglevel', 'error', converted,
]
push_log(task_id, "FFmpeg 转码中(H.264 NVENC)…")
result = subprocess.run(cmd, capture_output=True, text=True, timeout=3600)
if result.returncode != 0 or not Path(converted).exists():
push_log(task_id, "NVENC 转码失败,回退 libx264…")
err = (result.stderr or '').strip()[:200]
push_log(task_id, f"NVENC 失败({err or 'unknown'}),回退 libx264…")
cmd_x264 = [
FFmpegCLI.instance().ffmpeg_path,
'-y', '-i', video_path,
sys_ffmpeg, '-y', '-i', video_path,
'-c:v', 'libx264', '-crf', '18', '-preset', 'fast',
'-c:a', 'copy', '-loglevel', 'error', converted,
]