02-ago: [proyecto] vigilancia - bucle de mensaje x3 (GOOGLE_TV_REPETICIONES) + texto final en pantalla 30s (GOOGLE_TV_TEXTO_FINAL_SG) antes de apagar

This commit is contained in:
minguezsanzjuanjose
2026-08-02 14:59:54 +02:00
parent 2b13da934e
commit 0ad6dac79e
4 changed files with 85 additions and 4 deletions

View File

@@ -141,3 +141,55 @@ def generar_video(texto, ruta_audio, oraciones, nombre="anuncio.mp4"):
proc.stdin.close()
proc.wait()
return ruta_video
def generar_video_texto_final(texto, segundos, nombre="texto_final.mp4"):
"""Video estatico con el texto completo en pantalla durante `segundos` s."""
from PIL import Image, ImageDraw, ImageFont
ruta_video = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"voz_media", nombre)
font = ImageFont.truetype(FUENTE, 52) if FUENTE else ImageFont.load_default()
gap = 18
lineas = []
linea = []
ancho = 0
for w in texto.split():
a = font.getlength(w)
if ancho + a + gap > W - 80 and linea:
lineas.append(linea)
linea = [w]
ancho = a
else:
linea.append(w)
ancho += a + gap
if linea:
lineas.append(linea)
n_frames = int(segundos * FPS)
cmd = [FFMPEG, "-y", "-f", "rawvideo", "-vcodec", "rawvideo",
"-s", f"{W}x{H}", "-pix_fmt", "rgb24", "-r", str(FPS), "-i", "-",
"-c:v", "libx264", "-preset", "veryfast", "-pix_fmt", "yuv420p",
"-an", ruta_video]
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stderr=subprocess.DEVNULL)
for i in range(n_frames):
img = Image.new("RGB", (W, H), (8, 8, 8))
d = ImageDraw.Draw(img)
y = H // 2 - (len(lineas) // 2) * 80 + 30
for linea_words in lineas:
x = 40
for w in linea_words:
d.text((x, y), w, fill=(255, 255, 255), font=font)
x += font.getlength(w) + gap
y += 80
try:
proc.stdin.write(img.tobytes())
except BrokenPipeError:
break
proc.stdin.close()
proc.wait()
return ruta_video