fix(unified-render): 无音轨视频防御 + probe_has_audio 工具
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 1m4s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m3s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 4m23s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped

- 新增 ffmpeg_utils.probe_has_audio:ffprobe 探测音频流
- _mix_audio 入口过滤无音频流的 clip,避免 FFmpeg 引用 [i:a] 失败
- 新增 _clip_has_audio 缓存方法,同 clip 只探测一次
- 6个新增单测覆盖:全无音频、部分无音频、主图层无但独立音轨有、缓存、双无音频兜底
This commit is contained in:
灵应
2026-07-12 22:16:34 +08:00
parent ca86240c06
commit 73e853127a
3 changed files with 199 additions and 0 deletions
@@ -85,6 +85,41 @@ def run_ffmpeg(
raise
def probe_has_audio(local_path: str | Path) -> bool:
"""探测文件是否包含音频流。
Args:
local_path: 本地文件路径
Returns:
True 表示有音频流(或探测失败保守返回),False 表示确认无音频流
"""
try:
result = subprocess.run( # nosec B603
[
FFPROBE_BIN,
"-v",
"error",
"-select_streams",
"a:0",
"-show_entries",
"stream=codec_type",
"-of",
"default=noprint_wrappers=1:nokey=1",
str(local_path),
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=10,
)
return result.stdout.strip() == "audio"
except Exception:
# 探测失败保守返回 True,让 FFmpeg 自己处理(避免误删音频)
return True
def probe_duration(local_path: str | Path) -> float:
"""用 ffprobe 获取视频时长(秒)。