fix(metaclean): MP4 里的 subrip 字幕流用 mov_text 回退重封装
- `-map 0 -c copy` 遇到 subrip 字幕会报 "codec not currently supported in container" - 增加回退:视频/音频原样拷贝,字幕转 mov_text,其余流丢弃 - 实测:157 个命中文件里 5 个原本失败,回退后全部成功(复查 0 个仍带广告)
This commit is contained in:
@@ -53,21 +53,29 @@ class MetaCleanService:
|
||||
return False
|
||||
|
||||
tmp = path.with_name(f".{path.stem}.cleanmeta{path.suffix}")
|
||||
cmd = [
|
||||
"ffmpeg", "-v", "error", "-y", "-i", str(path),
|
||||
"-map", "0", "-c", "copy", "-map_metadata", "-1", "-map_chapters", "-1",
|
||||
str(tmp),
|
||||
base = ["-map_metadata", "-1", "-map_chapters", "-1", str(tmp)]
|
||||
# 先按「原样拷贝所有流」试;MP4 装不了 subrip 之类的字幕流时会失败,
|
||||
# 再退化成「视频/音频原样 + 字幕转 mov_text」
|
||||
attempts = [
|
||||
["ffmpeg", "-v", "error", "-y", "-i", str(path), "-map", "0", "-c", "copy", *base],
|
||||
["ffmpeg", "-v", "error", "-y", "-i", str(path),
|
||||
"-map", "0:v", "-map", "0:a", "-map", "0:s?", "-c", "copy", "-c:s", "mov_text", *base],
|
||||
]
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=7200)
|
||||
except subprocess.TimeoutExpired:
|
||||
result = None
|
||||
for cmd in attempts:
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=7200)
|
||||
except subprocess.TimeoutExpired:
|
||||
tmp.unlink(missing_ok=True)
|
||||
log.warning(f"⚠️ 重封装超时: {path.name}")
|
||||
return False
|
||||
if result.returncode == 0 and tmp.exists() and tmp.stat().st_size > 0:
|
||||
break
|
||||
tmp.unlink(missing_ok=True)
|
||||
log.warning(f"⚠️ 重封装超时: {path.name}")
|
||||
return False
|
||||
|
||||
if result.returncode != 0 or not tmp.exists() or tmp.stat().st_size == 0:
|
||||
if result is None or result.returncode != 0 or not tmp.exists() or tmp.stat().st_size == 0:
|
||||
tmp.unlink(missing_ok=True)
|
||||
log.warning(f"⚠️ 重封装失败: {path.name} — {result.stderr.strip()[:120]}")
|
||||
detail = (result.stderr.strip().splitlines() or ["未知错误"])[-1] if result else "未知错误"
|
||||
log.warning(f"⚠️ 重封装失败: {path.name} — {detail[:120]}")
|
||||
return False
|
||||
|
||||
# 体积变化过大说明流有问题,放弃替换
|
||||
|
||||
Reference in New Issue
Block a user