Integração: falantes + dublagem + vídeo final
- editor_api: importa dub e speakers juntos. - voice_chunks (falantes) vira a migração v15, depois da v14 do vídeo final (antes era criada fora das migrações). - dub.voice_for: qualquer voz que não é o streamer (other1, other2…) usa a segunda voz da dublagem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,9 @@ from pathlib import Path
|
||||
from . import dub, layout, media, reframe
|
||||
from .editor import Piece, effective_settings, emphasized, output_duration, output_words, pieces, slice_pieces, to_output
|
||||
from .scoring import Word
|
||||
from .subtitles import _escape, _ts, caption_blocks, clean_words
|
||||
from .speakers import is_other
|
||||
from .subtitles import (OTHER_LANE, STREAMER_LANE, _escape, _ts, caption_blocks, clean_words, has_other, lane,
|
||||
other_color, other_offset, other_size, other_y)
|
||||
|
||||
log = logging.getLogger("cenaforge_clipper.editor_render")
|
||||
W, H = layout.W, layout.H # quadro do vertical (padrão dos parâmetros); o formato real vem da configuração
|
||||
@@ -83,10 +85,12 @@ def banner_layout(o: dict, canvas: tuple[int, int]) -> dict:
|
||||
|
||||
|
||||
def hook_dodges(project: dict, canvas: tuple[int, int], cap_y: int, cap_size: int,
|
||||
total: float) -> list[tuple[float, float, int]]:
|
||||
total: float, below: int = 0) -> list[tuple[float, float, int]]:
|
||||
"""Onde a legenda vai enquanto cada gancho está na tela, se ele a cobriria: [(início, fim, y do centro)].
|
||||
Com a câmera em cima, o gancho fica logo abaixo dela (layout.hook_y) — o mesmo lugar da legenda automática
|
||||
(emenda câmera/jogo). Nesses segundos a legenda desce para logo abaixo do gancho; depois volta ao lugar."""
|
||||
(emenda câmera/jogo). Nesses segundos a legenda desce para logo abaixo do gancho; depois volta ao lugar.
|
||||
`below` = quanto a legenda ocupa ABAIXO do centro além do próprio tamanho (a linha de outra pessoa,
|
||||
doc/clipador/FALANTES.md): as duas linhas desviam juntas. 0 = só a linha do streamer (como antes)."""
|
||||
_, ch = canvas
|
||||
out = []
|
||||
for o in project["overlays"]:
|
||||
@@ -98,10 +102,11 @@ def hook_dodges(project: dict, canvas: tuple[int, int], cap_y: int, cap_size: in
|
||||
else:
|
||||
cy, half = int(ch * o["y"]), int(o["size"] * 0.9)
|
||||
top, bottom = cy - half, cy + half
|
||||
if cap_y + cap_size <= top or cap_y - cap_size >= bottom:
|
||||
reach = max(cap_size, below) # até onde a legenda (com a linha de baixo) desce a partir do centro
|
||||
if cap_y + reach <= top or cap_y - cap_size >= bottom:
|
||||
continue # não se encostam
|
||||
below = bottom + cap_size + 12
|
||||
y = below if below + cap_size <= ch else max(cap_size, top - cap_size - 12)
|
||||
under = bottom + cap_size + 12
|
||||
y = under if under + reach <= ch else max(cap_size, top - reach - 12)
|
||||
out.append((float(o["start"]), float(min(o["end"], total)), y))
|
||||
return out
|
||||
|
||||
@@ -224,6 +229,17 @@ def build_project_ass(project: dict, cfg: dict, credit: str, t0: float = 0.0, t1
|
||||
tsize = max(30, int(size * 0.5))
|
||||
trans_style = (f"Style: Trans,Arial,{tsize},&H00FFE79B,&H00FFE79B,&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,"
|
||||
f"{max(3, ow // 2)},2,8,60,60,0,1\n") if flags["translation"] and translation else ""
|
||||
# Fala de outra pessoa (doc/clipador/FALANTES.md): faixa própria, logo abaixo, noutra cor e tamanho. Os estilos
|
||||
# só entram quando o corte tem outra pessoa: o ASS de um corte só com o streamer fica idêntico ao de antes.
|
||||
spoken = sorted((w for w in output_words(project) if w.word.strip()), key=lambda w: (w.start, w.end))
|
||||
two = bool(cap["enabled"]) and has_other(spoken)
|
||||
osize = other_size(cap)
|
||||
other_c = layout.ass_color(other_color(cap))
|
||||
oow = max(2, int(ow) * osize // max(1, int(size))) if ow else 0
|
||||
other_styles = (f"Style: CaptionOther,{font},{osize},{other_c},{other_c},{outline},&H80000000,-1,0,0,0,100,100,0,0,1,"
|
||||
f"{oow},3,5,60,60,0,1\n"
|
||||
f"Style: KaraokeOther,{font},{osize},{high},{other_c},{outline},&H80000000,-1,0,0,0,100,100,0,0,1,"
|
||||
f"{oow},3,5,60,60,0,1\n") if two else ""
|
||||
header = f"""[Script Info]
|
||||
ScriptType: v4.00+
|
||||
PlayResX: {cw}
|
||||
@@ -235,7 +251,7 @@ ScaledBorderAndShadow: yes
|
||||
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
|
||||
Style: Caption,{font},{size},{base},{base},{outline},&H80000000,-1,0,0,0,100,100,0,0,1,{ow},3,5,60,60,0,1
|
||||
Style: Karaoke,{font},{size},{high},{base},{outline},&H80000000,-1,0,0,0,100,100,0,0,1,{ow},3,5,60,60,0,1
|
||||
Style: Credit,Arial,{cred['size']},&H00FFFFFF,&H00FFFFFF,&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,3,1,{credit_align},{credit_side},{credit_side},{credit_margin},1
|
||||
{other_styles}Style: Credit,Arial,{cred['size']},&H00FFFFFF,&H00FFFFFF,&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,3,1,{credit_align},{credit_side},{credit_side},{credit_margin},1
|
||||
Style: Text,Arial Black,64,&H00FFFFFF,&H00FFFFFF,&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,6,2,5,60,60,0,1
|
||||
Style: Box,Arial Black,64,&H00FFFFFF,&H00FFFFFF,&H004D1DE1,&H00000000,-1,0,0,0,100,100,0,0,3,18,0,5,60,60,0,1
|
||||
Style: Bar,Arial,10,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1
|
||||
@@ -259,35 +275,61 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
||||
emph = emphasized(project)
|
||||
emph_c = layout.ass_inline_color(project["captions"]["emphColor"])
|
||||
hi_c, base_c = layout.ass_inline_color(cap["highlight"]), layout.ass_inline_color(cap["color"])
|
||||
pos = f"\\pos({cw // 2},{layout.caption_y(cfg)})"
|
||||
dodges = hook_dodges(project, (cw, ch), layout.caption_y(cfg), int(cap["size"]), total)
|
||||
oth_c = layout.ass_inline_color(other_color(cap))
|
||||
cap_y = layout.caption_y(cfg)
|
||||
pos = f"\\pos({cw // 2},{cap_y})"
|
||||
trans_on = bool(flags["translation"] and translation)
|
||||
# Linha de outra pessoa logo abaixo da do streamer. Com a tradução de desenvolvimento ligada, a tradução do
|
||||
# streamer (até 2 linhas) fica ENTRE as duas e a de outra pessoa, embaixo da linha dela.
|
||||
offset = other_offset(int(size), osize, int(2.4 * tsize) + 6 if trans_on else 0)
|
||||
# O gancho desvia as duas linhas juntas (a de baixo conta na altura ocupada).
|
||||
below = offset + int(0.6 * osize) + (int(2.4 * tsize) if trans_on else 0) if two else 0
|
||||
# Sem espaço embaixo para a linha de outra pessoa (horizontal: a legenda já fica a 85 % da altura), a do
|
||||
# streamer SOBE o necessário: a ordem nunca inverte (streamer em cima, outra pessoa embaixo).
|
||||
if two:
|
||||
cap_y = min(cap_y, ch - 8 - below)
|
||||
pos = f"\\pos({cw // 2},{cap_y})"
|
||||
dodges = hook_dodges(project, (cw, ch), cap_y, int(cap["size"]), total, below=below)
|
||||
|
||||
def y_at(t: float) -> int:
|
||||
"""Altura (centro) da legenda no instante t (saída): desviada enquanto um gancho a cobriria."""
|
||||
"""Altura (centro) da legenda do streamer no instante t (saída): desviada enquanto um gancho a cobriria."""
|
||||
for s, e, y in dodges:
|
||||
if s <= t < e:
|
||||
return y
|
||||
return layout.caption_y(cfg)
|
||||
return cap_y
|
||||
|
||||
def at(t: float) -> str:
|
||||
"""Posição da legenda no instante t (saída)."""
|
||||
def oy_at(t: float) -> int:
|
||||
"""Altura (centro) da linha de outra pessoa no instante t (saída)."""
|
||||
return other_y(y_at(t), offset, osize, ch)
|
||||
|
||||
def at(t: float, other: bool = False) -> str:
|
||||
"""Posição da legenda no instante t (saída). `\\pos` fixo: o libass não empilha as duas linhas."""
|
||||
if other:
|
||||
return f"\\pos({cw // 2},{oy_at(t)})"
|
||||
y = y_at(t)
|
||||
return pos if y == layout.caption_y(cfg) else f"\\pos({cw // 2},{y})"
|
||||
return pos if y == cap_y else f"\\pos({cw // 2},{y})"
|
||||
# Ênfase: palavra de saída ↔ palavra marcada no projeto (mesmo texto, mesmo instante), casada nos tempos
|
||||
# ORIGINAIS. Depois as palavras são saneadas (ordem, sem sobreposição, duração mínima) — `clean_words` devolve
|
||||
# a mesma quantidade, na mesma ordem — e os blocos abaixo nunca ficam dois na tela ao mesmo tempo.
|
||||
raw = sorted((w for w in output_words(project) if w.word.strip()), key=lambda w: (w.start, w.end))
|
||||
# ORIGINAIS. Depois as palavras são saneadas POR FAIXA (ordem, sem sobreposição, duração mínima) —
|
||||
# `clean_words` devolve a mesma quantidade, na mesma ordem — e os blocos de uma faixa nunca ficam dois na
|
||||
# tela ao mesmo tempo (as duas faixas, sim: cada uma na sua linha).
|
||||
raw = spoken
|
||||
raw_emph = _match_emphasis(raw, project, emph)
|
||||
words = clean_words(raw)
|
||||
words: list[Word] = list(raw)
|
||||
for name in (STREAMER_LANE, OTHER_LANE):
|
||||
idxs = [i for i, w in enumerate(raw) if lane(w.speaker) == name]
|
||||
for i, w in zip(idxs, clean_words([raw[i] for i in idxs])):
|
||||
words[i] = w
|
||||
|
||||
def txt(w: Word) -> str:
|
||||
return _escape(w.word.upper() if cap["uppercase"] else w.word)
|
||||
|
||||
def key(w: Word) -> tuple[float, str]:
|
||||
return round(w.start, 3), w.word # depois de clean_words, cada início é único
|
||||
def key(w: Word) -> tuple[float, str, str]:
|
||||
return round(w.start, 3), w.word, lane(w.speaker) # depois de clean_words, cada início é único na faixa
|
||||
|
||||
emph_keys = {key(words[i]) for i in raw_emph}
|
||||
for group, g_end in caption_blocks(words, cap["maxWords"]):
|
||||
other = lane(group[0].speaker) == OTHER_LANE
|
||||
base_g = oth_c if other else base_c
|
||||
if preset == "karaoke":
|
||||
parts, cursor = [], group[0].start
|
||||
for w in group:
|
||||
@@ -296,40 +338,46 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
||||
color = f"\\1c{emph_c}" if key(w) in emph_keys else ""
|
||||
parts.append((f"{{\\k{gap}}}" if gap else "") + f"{{\\kf{dur}{color}}}{txt(w)}")
|
||||
cursor = w.end
|
||||
event(0, group[0].start, g_end, "Karaoke", f"{{{at(group[0].start)}}}" + " ".join(parts))
|
||||
event(0, group[0].start, g_end, "KaraokeOther" if other else "Karaoke",
|
||||
f"{{{at(group[0].start, other)}}}" + " ".join(parts))
|
||||
continue
|
||||
style = "CaptionOther" if other else "Caption"
|
||||
for i, word in enumerate(group):
|
||||
start = word.start
|
||||
end = group[i + 1].start if i + 1 < len(group) else g_end
|
||||
if end <= start:
|
||||
continue
|
||||
if preset == "single":
|
||||
color = emph_c if key(word) in emph_keys else (hi_c if len(group) > 1 else base_c)
|
||||
event(0, start, end, "Caption", f"{{{at(start)}{_anim('pop')}\\c{color}}}{txt(word)}")
|
||||
color = emph_c if key(word) in emph_keys else (hi_c if len(group) > 1 else base_g)
|
||||
event(0, start, end, style, f"{{{at(start, other)}{_anim('pop')}\\c{color}}}{txt(word)}")
|
||||
continue
|
||||
parts = []
|
||||
for j, w in enumerate(group):
|
||||
is_emph = key(w) in emph_keys
|
||||
if preset == "minimal":
|
||||
parts.append(f"{{\\c{emph_c}}}{txt(w)}{{\\c{base_c}}}" if is_emph else txt(w))
|
||||
parts.append(f"{{\\c{emph_c}}}{txt(w)}{{\\c{base_g}}}" if is_emph else txt(w))
|
||||
elif j == i:
|
||||
color = emph_c if is_emph else hi_c
|
||||
pop = "\\fscx118\\fscy118\\t(0,130,\\fscx100\\fscy100)" if preset == "pop" else ""
|
||||
parts.append(f"{{\\c{color}{pop}}}{txt(w)}{{\\c{base_c}\\fscx100\\fscy100}}")
|
||||
parts.append(f"{{\\c{color}{pop}}}{txt(w)}{{\\c{base_g}\\fscx100\\fscy100}}")
|
||||
else:
|
||||
parts.append(f"{{\\c{emph_c}}}{txt(w)}{{\\c{base_c}}}" if is_emph else txt(w))
|
||||
parts.append(f"{{\\c{emph_c}}}{txt(w)}{{\\c{base_g}}}" if is_emph else txt(w))
|
||||
intro = "\\fscx85\\fscy85\\t(0,90,\\fscx100\\fscy100)" if preset == "pop" and i == 0 else ""
|
||||
event(0, start, end, "Caption", f"{{{at(start)}{intro}}}" + " ".join(parts))
|
||||
event(0, start, end, style, f"{{{at(start, other)}{intro}}}" + " ".join(parts))
|
||||
|
||||
if flags["translation"] and translation:
|
||||
if trans_on:
|
||||
# Só para desenvolver (doc/clipador/IDIOMAS.md): a frase traduzida em português, menor e em azul claro,
|
||||
# logo embaixo da legenda em inglês (\\an8 = cresce para baixo; \\q0 = quebra a linha se for longa).
|
||||
for line in translation:
|
||||
# logo embaixo da legenda de QUEM FALA (`speaker` da linha; sem ele, o streamer) — \\an8 = cresce para
|
||||
# baixo; \\q0 = quebra a linha se for longa.
|
||||
for line in translation or []:
|
||||
a, _ = to_output(float(line["s"]), project["cuts"])
|
||||
b, _ = to_output(float(line["e"]), project["cuts"])
|
||||
if b - a < 0.2 or not str(line.get("pt") or "").strip():
|
||||
continue
|
||||
y = y_at(a) + int(size * 0.62)
|
||||
if two and is_other(line.get("speaker")):
|
||||
y = oy_at(a) + int(osize * 0.62)
|
||||
else:
|
||||
y = y_at(a) + int(size * 0.62)
|
||||
event(0, a, b, "Trans", f"{{\\an8\\pos({cw // 2},{y})\\q0}}{_escape(str(line['pt']))}")
|
||||
|
||||
cuts = project["cuts"]
|
||||
|
||||
Reference in New Issue
Block a user