0:05 myText1 is textClass
0:06 myText1 text "Bienvenidos a la proyección."
0:07 myText1 position sph 0 -30 10
0:08 myText1 color 100 100 100 # Blanco
0:09 myText1 intensity 100
0:10 scene add myText1 near # Añadir texto a la escena
0:11 myText1 intensity 0 dur 1 # Desvanecer el texto seg. 10
0:12 myText1 delete
Digistar no tiene soporte nativo para archivos VTT. Pero puedes usar Python para transformar el archivo .vtt en comandos Digistar (subtitles.ds).
Ejemplo de un archivo VTT
WEBVTT
00:00:05.000 --> 00:00:10.000
Bienvenidos a la proyección.
00:00:15.000 --> 00:00:20.000
Aquí vemos una nebulosa.
00:00:25.000 --> 00:00:30.000
Las estrellas nacen en estos lugares.
Digistar necesita un mínimo de tiempo para renderizar el texto y aplicar las transiciones. El archivo .vtt debe tener marcas de tiempo de al menos 3 segundos para asegurar que el subtítulo sea visible y tenga una transición adecuada.
Cómo usarlo en tu script de video
En video.ds, simplemente agrega:
script play $Content/Scripts/subtitles.ds
vtt_to_ds.py
import os
import re
def vtt_to_ds(vtt_file, output_file, min_duration=3, buffer_time=0.5):
with open(vtt_file, "r", encoding="utf-8") as f:
lines = f.readlines()
subtitle_blocks = []
current_block = []
for line in lines:
line = line.strip()
if "-->" in line:
start_time, end_time = line.split(" --> ")
start_seconds = convert_to_seconds(start_time)
end_seconds = convert_to_seconds(end_time)
duration = end_seconds - start_seconds
if duration < min_duration:
end_seconds = start_seconds + min_duration # Ajustar duración mínima
current_block = [start_seconds, end_seconds + buffer_time, ""] # Añadir margen
elif line and not line.startswith("WEBVTT"):
current_block[2] = line
subtitle_blocks.append(current_block)
with open(output_file, "w", encoding="utf-8") as f:
for i, (start, end, text) in enumerate(subtitle_blocks):
f.write(f"{start} myText{i+1} is textClass\n")
f.write(f"{start+1} myText{i+1} text \"{text}\"\n")
f.write(f"{start+2} myText{i+1} position sph 0 -30 10\n")
f.write(f"{start+3} myText{i+1} color 100 100 100\n")
f.write(f"{start+4} myText{i+1} intensity 100\n")
f.write(f"{start+5} scene add myText{i+1} near\n")
f.write(f"{end} myText{i+1} intensity 0 dur 1\n")
f.write(f"{end+1} myText{i+1} delete\n\n")
def convert_to_seconds(time_str):
h, m, s = map(float, re.split("[:.]", time_str.replace(",", ".")))
return int(h * 3600 + m * 60 + s)
def process_all_vtt_files(root_dir="."):
for dirpath, _, filenames in os.walk(root_dir):
for filename in filenames:
if filename.endswith(".vtt"):
vtt_path = os.path.join(dirpath, filename)
ds_filename = f"subtitles_{os.path.splitext(filename)[0]}.ds"
ds_path = os.path.join(dirpath, ds_filename)
print(f"Procesando: {vtt_path} → {ds_path}")
vtt_to_ds(vtt_path, ds_path)
# Ejecutar búsqueda en el directorio actual y subdirectorios
process_all_vtt_files()