From 0d19c866fecbcdfaf7f942cca366c1cd123eb881 Mon Sep 17 00:00:00 2001 From: ali Date: Fri, 20 Nov 2026 10:24:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(metaclean):=20MP4=20=E9=87=8C=E7=9A=84=20su?= =?UTF-8?q?brip=20=E5=AD=97=E5=B9=95=E6=B5=81=E7=94=A8=20mov=5Ftext=20?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E9=87=8D=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `-map 0 -c copy` 遇到 subrip 字幕会报 "codec not currently supported in container" - 增加回退:视频/音频原样拷贝,字幕转 mov_text,其余流丢弃 - 实测:157 个命中文件里 5 个原本失败,回退后全部成功(复查 0 个仍带广告) --- media/src/services/metaclean.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/media/src/services/metaclean.py b/media/src/services/metaclean.py index c15705e..c9ae1c5 100644 --- a/media/src/services/metaclean.py +++ b/media/src/services/metaclean.py @@ -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 # 体积变化过大说明流有问题,放弃替换