Generate a subtitled video from a Google NotebookLM audio

Generate a subtitled video from a Google NotebookLM audio

Postby Antonio Linares » Wed Nov 06, 2024 5:01 pm

1. pip install openai-whisper

2. download ffmpeg.exe from here:
https://ffmpeg.org/download.html

3. go.py
Code: Select all  Expand view
import whisper

# Cargar el modelo de Whisper
model = whisper.load_model("base")

# Transcribir el archivo WAV
result = model.transcribe("entrada.wav")

# Función para formatear los tiempos en el estilo SRT
def format_timestamp(seconds):
    hours = int(seconds // 3600)
    minutes = int((seconds % 3600) // 60)
    seconds = int(seconds % 60)
    milliseconds = int((seconds % 1) * 1000)
    return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"

# Guardar la transcripción en formato SRT
with open("transcripcion.srt", "w", encoding="utf-8") as srt_file:
    for i, segment in enumerate(result["segments"]):
        # Escribe el número del segmento
        srt_file.write(f"{i + 1}\n")
        # Escribe el tiempo de inicio y fin
        start_time = format_timestamp(segment["start"])
        end_time = format_timestamp(segment["end"])
        srt_file.write(f"{start_time} --> {end_time}\n")
        # Escribe el texto
        srt_file.write(f"{segment['text'].strip()}\n\n")
 

4. Generate the base video:
ffmpeg -loop 1 -i imagen.jpg -i entrada.wav -c:v libx264 -c:a aac -b:a 192k -shortest -y video_base.mp4

5. Add the subtitles to the video:
ffmpeg -i video_base.mp4 -vf "subtitles=transcripcion.srt" -c:a copy video_con_subtitulos.mp4

6. example:
https://huggingface.co/datasets/fivetech/notebooklm/blob/main/video_con_subtitulos.mp4
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Generate a subtitled video from a Google NotebookLM audio

Postby Antonio Linares » Thu Nov 07, 2024 7:37 pm

Usando x imágenes que cambian cada cierto tiempo:

go.bat
Code: Select all  Expand view
for /f "tokens=* USEBACKQ" %%F in (`ffprobe -i entrada.wav -show_entries format^=duration -v quiet -of csv^=p^=0`) do set duration=%%F
ffmpeg -framerate 0.1 -stream_loop -1 -i img%%d.webp -i entrada.wav -c:v libx264 -c:a aac -b:a 192k -t %duration% -y video_base.mp4
ffmpeg -i video_base.mp4 -vf "fps=30,subtitles=transcripcion.srt" -c:a copy -y video_con_subtitulos.mp4
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to Utilities / Utilidades

Who is online

Users browsing this forum: No registered users and 24 guests