104b195d38
Mismos segmentos y .vtt que el HLS, retraso fijo configurable (24 s), envío al ritmo del PCR interpolado (las ráfagas tiraban paquetes en UDP). Tarea 078.
58 lines
2.4 KiB
Python
58 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Lee un .ts con SEI GA94 y muestra el texto 608 del campo pedido (1=CC1, 2=CC3)
|
|
y los bytes de texto del 708 por servicio. Solo para verificar la salida."""
|
|
import sys
|
|
from orbisubs_srt import partir, pts_de
|
|
EXT = {0x12: "ÁÉÓÚÜü‘¡*’—©℠•“”ÀÂÇÈÊËëÎÏïÔÙùÛ«»", 0x13: "ÃãÍÌìÒòÕõ{}\\^_|~ÄäÖöߥ¤│Å娸┌┐└┘"}
|
|
ESP = "®°½¿™¢£♪à èâêîôû"
|
|
BAS = {0x2A: "á", 0x5C: "é", 0x5E: "í", 0x5F: "ó", 0x60: "ú", 0x7B: "ç", 0x7C: "÷", 0x7D: "Ñ", 0x7E: "ñ"}
|
|
ts, campo = open(sys.argv[1], "rb").read(), int(sys.argv[2])
|
|
vpid, aus, cur = 256, [], None
|
|
for i in range(0, len(ts) - 187, 188):
|
|
pid, pusi, af, pay = partir(ts[i:i + 188])
|
|
if pid != vpid: continue
|
|
if pusi:
|
|
cur = bytearray(pay); aus.append(cur)
|
|
elif cur is not None:
|
|
cur += pay
|
|
frames = []
|
|
for pes in aus:
|
|
pts = pts_de(bytes(pes)); j = pes.find(b"GA94")
|
|
if j < 0: continue
|
|
n = pes[j + 5] & 0x1F
|
|
tri = [pes[j + 7 + 3 * k: j + 10 + 3 * k] for k in range(n)]
|
|
frames.append((pts, tri))
|
|
frames.sort()
|
|
buf, txt, prev = "", [], None
|
|
d708 = {1: bytearray(), 2: bytearray()}
|
|
pkt = bytearray()
|
|
for pts, tri in frames:
|
|
for t in tri:
|
|
typ = t[0] & 3
|
|
if typ == campo - 1 and t[0] & 4:
|
|
a, b = t[1] & 0x7F, t[2] & 0x7F
|
|
if (a, b) == prev and a < 0x20: continue
|
|
prev = (a, b)
|
|
if a in (0x14, 0x15) and b == 0x2F:
|
|
txt.append(f"{pts/90000:9.2f} {buf.strip()}"); buf = ""
|
|
elif a in (0x14, 0x15): pass
|
|
elif a == 0x11 and 0x30 <= b <= 0x3F: buf += ESP[b - 0x30]
|
|
elif a in (0x12, 0x13) and 0x20 <= b <= 0x3F: buf = buf[:-1] + EXT[a][b - 0x20]
|
|
elif 0x10 <= a <= 0x17: buf += " "
|
|
else:
|
|
for c in (a, b):
|
|
if c >= 0x20: buf += BAS.get(c, chr(c))
|
|
elif typ in (2, 3) and t[0] & 4:
|
|
if typ == 3 and pkt:
|
|
k = 1
|
|
while k < len(pkt):
|
|
svc, sz = pkt[k] >> 5, pkt[k] & 31
|
|
if svc == 0: break
|
|
d708.setdefault(svc, bytearray()).extend(pkt[k + 1:k + 1 + sz]); k += 1 + sz
|
|
pkt = bytearray()
|
|
pkt += t[1:3]
|
|
for l in txt[:12]: print(l)
|
|
for s in (1, 2):
|
|
b = d708[s]
|
|
print(f"708 svc{s}:", "".join(chr(c) if 0x20 <= c < 0x7F or 0xA0 <= c else "|" for c in b)[:400])
|