OrbiSubs ASR: skip a segment whose PTS cannot be read; prune Master.vistos
Revisión externa 1.4 y 3.2: después de 10 intentos, y con un segmento posterior en la lista, el seq sale con un .vtt vacío (sin inventar PTS) y se loguea pts_skip. test_revision.py cubre también 1.3, 1.5 y 1.6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JAUCv2ADyD2NSg4ub9YPr1
This commit is contained in:
+53
-5
@@ -485,6 +485,9 @@ class Master:
|
||||
nuevo = True
|
||||
except OSError:
|
||||
pass
|
||||
# Solo los seq que siguen en la lista: antes crecía para siempre, uno por segmento
|
||||
# (~14.400 por día con 6 s; revisión externa, 3.2).
|
||||
self.vistos &= {x[0] for x in segs}
|
||||
if not nuevo:
|
||||
return False
|
||||
cambio = False
|
||||
@@ -572,6 +575,39 @@ ADELANTO_SRT = 0.5
|
||||
CARGA_608 = 1.5
|
||||
|
||||
|
||||
class PtsFallidos:
|
||||
"""Segmentos de video cuyo PTS no se puede leer (.ts dañado). Antes se reintentaba
|
||||
para siempre y video.m3u8 se frenaba en ese segmento hasta que salía de la ventana
|
||||
de la ingesta (~1 min con 10 de 6 s): el player se quedaba sin video y el canal sin
|
||||
subtítulos (revisión externa, 1.4). Después de INTENTOS, y si ya hay uno después (el
|
||||
.ts está cerrado), se saltea: sale en video.m3u8 con un .vtt vacío. El PTS no se
|
||||
inventa: un cue con PTS supuesto podría aparecer en otro lado del video."""
|
||||
INTENTOS = 10
|
||||
|
||||
def __init__(self):
|
||||
self.n, self.salteados = {}, set()
|
||||
|
||||
def fallo(self, seq, ultimo, err=""):
|
||||
"""Un intento fallido. Devuelve True si quedó salteado."""
|
||||
n = self.n[seq] = self.n.get(seq, 0) + 1
|
||||
if n >= self.INTENTOS and seq < ultimo and seq not in self.salteados:
|
||||
self.salteados.add(seq)
|
||||
log("pts_skip", seq=seq, tries=n, err=str(err)[:200])
|
||||
return True
|
||||
return False
|
||||
|
||||
def podar(self, desde):
|
||||
self.n = {k: v for k, v in self.n.items() if k >= desde}
|
||||
self.salteados = {k for k in self.salteados if k >= desde}
|
||||
|
||||
def limpiar(self):
|
||||
self.n.clear()
|
||||
self.salteados.clear()
|
||||
|
||||
|
||||
VTT_VACIO = "WEBVTT\n\n"
|
||||
|
||||
|
||||
def pts_inicio(path):
|
||||
pr = subprocess.run(["ffprobe", "-v", "error", "-select_streams", "a:0", "-show_entries",
|
||||
"stream=start_time", "-of", "csv=p=0", path], capture_output=True, text=True)
|
||||
@@ -610,6 +646,7 @@ def bucle_trozos(a, motor, tr, met, cola, src, subs_dir):
|
||||
# La 081 medía contra la llegada del propio segmento (y0 = y): con ráfagas daba de menos.
|
||||
ys = deque() # (reloj, y)
|
||||
ys_nuevos = []
|
||||
pts_mal = PtsFallidos()
|
||||
while True:
|
||||
segs, tgt = leer_lista(src)
|
||||
trozos, _ = leer_lista(aud)
|
||||
@@ -619,7 +656,7 @@ def bucle_trozos(a, motor, tr, met, cola, src, subs_dir):
|
||||
if trozos and trozos[-1][0] < aud_hecho:
|
||||
log("sequence_reset", last=aud_hecho, now=trozos[-1][0])
|
||||
aud_hecho, publicado = -1, None
|
||||
info.clear(); llegada.clear(); ys.clear()
|
||||
info.clear(); llegada.clear(); ys.clear(); pts_mal.limpiar()
|
||||
nuevos = [x for x in trozos if x[0] > aud_hecho]
|
||||
if aud_hecho < 0 or (nuevos and nuevos[0][0] != aud_hecho + 1):
|
||||
nuevos = nuevos[-1:] # arranque o salto: desde el último trozo
|
||||
@@ -634,15 +671,15 @@ def bucle_trozos(a, motor, tr, met, cola, src, subs_dir):
|
||||
lleg_audio = ahora
|
||||
# PTS de los segmentos de video nuevos (solo ffprobe, sin decodificar).
|
||||
for seq, uri, dur, pdt in segs:
|
||||
if seq not in info and (publicado is None or seq > publicado):
|
||||
if seq not in info and seq not in pts_mal.salteados and (publicado is None or seq > publicado):
|
||||
try:
|
||||
p = al_audio(pts_inicio(os.path.join(a.dir, "src", uri)), tr)
|
||||
info[seq] = (dur, p, p + dur)
|
||||
if seq in llegada and publicado is not None:
|
||||
ys.append((time.time(), llegada[seq] - (p + dur)))
|
||||
ys_nuevos.append(ys[-1][1])
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
pts_mal.fallo(seq, segs[-1][0], e)
|
||||
if publicado is None and segs:
|
||||
publicado = segs[-1][0] - 1 # arranque: no transcribir historia
|
||||
elif publicado is not None and segs and not any(x[0] == publicado + 1 for x in segs) \
|
||||
@@ -654,6 +691,7 @@ def bucle_trozos(a, motor, tr, met, cola, src, subs_dir):
|
||||
publicado = segs[-1][0] - 1
|
||||
ys.clear() # PTS nuevos: los y viejos son de otra línea de tiempo
|
||||
info = {k: v for k, v in info.items() if k > publicado}
|
||||
pts_mal.limpiar()
|
||||
conf, dt, err = [], 0.0, None
|
||||
if nuevos:
|
||||
if hasattr(motor, "ultimo"):
|
||||
@@ -675,8 +713,17 @@ def bucle_trozos(a, motor, tr, met, cola, src, subs_dir):
|
||||
cola.flush()
|
||||
# Publicar los segmentos de video que ya tienen todo su texto (o el tope).
|
||||
pub_antes = publicado
|
||||
while publicado is not None and publicado + 1 in info:
|
||||
while publicado is not None and (publicado + 1 in info or publicado + 1 in pts_mal.salteados):
|
||||
s = publicado + 1
|
||||
if s not in info:
|
||||
# .ts sin PTS legible: sale sin subtítulo (y sin inglés: el traductor no lo
|
||||
# va a ver en la cola, y en.m3u8 lo nombra igual).
|
||||
escribir_atomico(os.path.join(subs_dir, f"{s}.vtt"), VTT_VACIO)
|
||||
if a.en:
|
||||
os.makedirs(os.path.join(a.dir, "en"), exist_ok=True)
|
||||
escribir_atomico(os.path.join(a.dir, "en", f"{s}.vtt"), VTT_VACIO)
|
||||
publicado = s
|
||||
continue
|
||||
dur, s0, s1 = info[s]
|
||||
ultimo_video = segs[-1][0] if segs else s
|
||||
if not (s1 <= listo + 0.05 or audio_fin >= s1 + cap or s < ultimo_video - 1):
|
||||
@@ -696,6 +743,7 @@ def bucle_trozos(a, motor, tr, met, cola, src, subs_dir):
|
||||
if primero is not None:
|
||||
for k in [k for k in info if k < primero - 5]:
|
||||
info.pop(k, None); llegada.pop(k, None)
|
||||
pts_mal.podar(primero - 5)
|
||||
if not nuevos and publicado == pub_antes:
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user