feat(pipeline): 大文件内嵌 ASS 在整理阶段自动提前抽

This commit is contained in:
ali
2026-11-20 21:09:51 +08:00
parent 080b8c4489
commit d64f02f87d
3 changed files with 46 additions and 10 deletions
+3 -2
View File
@@ -197,9 +197,10 @@ nfo_tags = plot,outline,genre,tagline,comment,studio,tag
[Compatibility]
# 电视直传码率上限(Mbps),超过就判 TRANSCODE
max_direct_mbps = 70
# 超过该体积(GB)且含内嵌 ASS 时,提前抽外挂字幕
# 超过该体积(GB)且含内嵌 ASS(ass/ssa;PGS 图形字幕客户端直接渲染,不抽)时,
# 整理阶段提前抽外挂字幕。直传片源也抽:Jellyfin 首播现场抽取 60GB 级 REMUX 实测要 4 分钟以上
pre_extract_ass_gb = 15
# 大文件自动抽 ASS(当前 export=ass 时已天然满足)
# 大文件自动抽 ASS 总开关;false 时只有 TRANSCODE 源 / 手动 extract-subs 才抽
auto_extract_ass = true
# 必须转码的片源补外挂 SRT(仅当 [Subtitles] export 不含 ass 时启用)
export_text_subs = true
+38 -7
View File
@@ -267,6 +267,26 @@ class MediaPipeline:
stripped += 1
log.info(f"🧹 广告元数据清理完成:{stripped}/{len(hits)} 个文件已重封装")
@staticmethod
def _needs_ass_pre_extract(pf) -> bool:
"""大体积且含内嵌 ASS 时,直传片源也要提前抽外挂字幕。
Jellyfin 首次播放要现场从几十 GB 的 REMUX 里抽字幕,实测 4 分钟以上;
直传不省这一步,所以按体积阈值提前抽。开关/阈值:
[Compatibility] auto_extract_ass / pre_extract_ass_gb。
"""
if not config.AUTO_EXTRACT_ASS:
return False
info = pf.info or {}
try:
size_gb = float(info.get("size_gb") or 0)
except (TypeError, ValueError):
return False
if size_gb <= config.PRE_EXTRACT_ASS_GB:
return False
return any((s.get("codec") or "").lower() in config.ASS_CODECS
for s in info.get("subs") or [])
def _generate_plan(self):
if not self.auto_execute: log.info("📝 正在生成执行计划...")
dir_video_counts = {f.parent: 0 for f, *_ in self.valid_files}
@@ -312,24 +332,34 @@ class MediaPipeline:
else:
dest_dir = f.parent
# 大文件内嵌 ASS:即使判 READY(直传)也提前抽,避免 Jellyfin 首播现场抽取几分钟。
# 不在这里判断「是否已有副本」:同一部片可能只抽了部分语言,逐轨判重交给
# scan_subtitles/_plan_ass,缺哪条补哪条。
pre_extract_ass = (self.args.mode != "clean-ads"
and not getattr(self.args, "rename_only", False)
and self._needs_ass_pre_extract(pf))
if pre_extract_ass:
log.debug(f"⏩ 大文件内嵌 ASS({pf.info.get('size_gb', 0):g}GB),检查外挂字幕: {f.name}")
# 「<目标名>-描述」视为已规范:综艺整理会在技术标签后用「-期名」补充说明,
# 整库扫描不应把它当作错名再改回去。
is_perfect = (f.name == f"{target_stem}{f.suffix.lower()}"
or f.stem.startswith(f"{target_stem}-"))
skip_heavy = config.SKIP_PERFECT_MATCH and is_perfect and self.args.mode not in ["clean-ads", "extract-subs"]
skip_heavy = (config.SKIP_PERFECT_MATCH and is_perfect
and self.args.mode not in ["clean-ads", "extract-subs"])
if skip_heavy and not self.auto_execute:
if skip_heavy and not pre_extract_ass and not self.auto_execute:
if self.args.extract_internal:
log.info(f"💡 [特权放行] {f.name} 检测到强制参数,放行底层扫描。")
else:
log.debug(f"✨ [完美豁免] {f.name} 已达最高工业标准,直接放行~")
if self.args.mode != "clean-ads" and not getattr(self.args, "rename_only", False):
# 文本字幕(ASS / SRT)外置化只对必须转码的片源做:
# 直传片源的内嵌字幕客户端能直接渲染,不需要外挂副本。
# 文本字幕(ASS / SRT)外置化:TRANSCODE 源必抽(内嵌字幕投递不稳);
# 直传片源只在「大文件 + 内嵌 ASS」时提前抽(Jellyfin 首播现场抽取太慢);
# 显式 extract-subs 或 --extract-internal 视为强制,不受此限制。
forced_subs = bool(self.args.extract_internal) or self.args.mode == "extract-subs"
want_text_subs = forced_subs or pf.verdict == TRANSCODE
want_text_subs = forced_subs or pf.verdict == TRANSCODE or pre_extract_ass
# 外挂 SRT 兜底:只在没配置 ASS 导出时启用,
# 否则同一语言会同时出现 .internal.<lang>.ass 和 .srt 两份。
@@ -348,7 +378,7 @@ class MediaPipeline:
# 🎯 内嵌字幕优先:先看内嵌,有就不再处理外挂
internal_subs = 0
if want_text_subs:
if not skip_heavy or forced_subs:
if not skip_heavy or forced_subs or pre_extract_ass:
internal_subs = SubtitleService.scan_subtitles(f, self.task_mgr, target_stem, dest_dir)
elif SubtitleService.has_internal_sub(dest_dir, target_stem):
# 完美文件名豁免时不做 ffprobe,但仍需识别"已有内嵌字幕"
@@ -359,7 +389,8 @@ class MediaPipeline:
else:
# 旧行为:外挂优先,没有外挂(或强制)时才提取内嵌
has_ext_sub = RenamerService.scan_existing_subtitles(f, target_stem, m_type, dest_dir, self.task_mgr)
if want_text_subs and (not has_ext_sub or forced_subs) and (not skip_heavy or forced_subs):
if (want_text_subs and (not has_ext_sub or forced_subs or pre_extract_ass)
and (not skip_heavy or forced_subs or pre_extract_ass)):
SubtitleService.scan_subtitles(f, self.task_mgr, target_stem, dest_dir)
# 内嵌字体附件(ASS 特效字体还原):只有抽了 ASS 才有意义