RTX 3050 - Order Now
Home / Blog / Tutorials / Subtitle Generator Pipeline with Whisper and SRT
Tutorials

Subtitle Generator Pipeline with Whisper and SRT

Build an automated subtitle generation pipeline that transcribes video audio with Whisper and exports perfectly timed SRT files on a dedicated GPU server.

You will build a pipeline that takes video files, extracts audio, transcribes with Whisper including precise timestamps, and outputs industry-standard SRT subtitle files ready for upload to YouTube, Vimeo, or any video platform. The end result: drop a 60-minute video and receive an SRT file with accurate subtitles in under 5 minutes. Process multiple languages without cloud API costs. Here is the pipeline on dedicated GPU infrastructure.

Pipeline Architecture

StageToolInputOutput
1. Audio extractionFFmpegVideo file (MP4/MKV)WAV audio
2. TranscriptionWhisper Large v3AudioTimestamped segments
3. SRT formattingPythonSegments.srt file
4. Translation (optional)LLaMA 3.1 8BSRT textTranslated SRT

Audio Extraction

import subprocess

def extract_audio(video_path: str, output_path: str) -> str:
    subprocess.run([
        "ffmpeg", "-i", video_path,
        "-vn", "-acodec", "pcm_s16le",
        "-ar", "16000", "-ac", "1",
        output_path, "-y"
    ], check=True)
    return output_path

Whisper Transcription with Timestamps

from faster_whisper import WhisperModel

whisper = WhisperModel("large-v3", device="cuda", compute_type="float16")

def transcribe_for_subtitles(audio_path: str, language: str = None) -> list:
    segments, info = whisper.transcribe(
        audio_path,
        beam_size=5,
        word_timestamps=True,
        language=language
    )
    subtitle_segments = []
    for seg in segments:
        subtitle_segments.append({
            "start": seg.start,
            "end": seg.end,
            "text": seg.text.strip()
        })
    return subtitle_segments

Whisper Large v3 provides word-level timestamps, enabling precise subtitle timing. The faster-whisper implementation runs 4x faster than standard Whisper with CTranslate2 optimisation.

SRT File Generation

def format_timestamp(seconds: float) -> str:
    hours = int(seconds // 3600)
    minutes = int((seconds % 3600) // 60)
    secs = int(seconds % 60)
    millis = int((seconds % 1) * 1000)
    return f"{hours:02d}:{minutes:02d}:{secs:02d},{millis:03d}"

def generate_srt(segments: list, max_chars: int = 42, max_duration: float = 5.0) -> str:
    srt_entries = []
    index = 1
    for seg in segments:
        text = seg["text"]
        # Split long segments for readability
        if len(text) > max_chars * 2:
            words = text.split()
            mid = len(words) // 2
            line1 = " ".join(words[:mid])
            line2 = " ".join(words[mid:])
            text = f"{line1}\n{line2}"

        entry = (f"{index}\n"
                 f"{format_timestamp(seg['start'])} --> {format_timestamp(seg['end'])}\n"
                 f"{text}\n")
        srt_entries.append(entry)
        index += 1
    return "\n".join(srt_entries)

def save_srt(segments: list, output_path: str):
    srt_content = generate_srt(segments)
    with open(output_path, "w", encoding="utf-8") as f:
        f.write(srt_content)

Batch Processing API

from fastapi import FastAPI, UploadFile
from fastapi.responses import FileResponse
app = FastAPI()

@app.post("/generate-subtitles")
async def generate_subtitles(video: UploadFile, language: str = None):
    video_path = save_upload(video)
    audio_path = video_path.replace(video_path.split(".")[-1], "wav")

    extract_audio(video_path, audio_path)
    segments = transcribe_for_subtitles(audio_path, language)
    srt_path = video_path.rsplit(".", 1)[0] + ".srt"
    save_srt(segments, srt_path)

    return FileResponse(srt_path, filename=f"{video.filename.rsplit('.', 1)[0]}.srt")

Multilingual Subtitle Translation

For translated subtitles, pipe the SRT text through the LLM translation stage. Translate each subtitle entry individually to preserve timing. Use the vLLM server for batch translation across multiple target languages simultaneously. This produces multilingual subtitle sets from a single transcription run.

Quality and Production

For production: post-process subtitles to fix common issues (orphaned words, subtitles shorter than 1 second); implement a review interface where editors can correct individual entries; support VTT format alongside SRT for web video; and batch-process video libraries overnight. Deploy on private infrastructure for confidential video content. See model options for translation models, TTS hosting for audio dubbing, more tutorials, and media use cases. Check infrastructure guides for storage recommendations.

Video AI GPU Servers

Dedicated GPU servers for subtitle generation and video processing. Fast transcription on isolated UK infrastructure.

Browse GPU Servers

Need a Dedicated GPU Server?

Deploy from RTX 3050 to RTX 5090. Full root access, NVMe storage, 1Gbps — UK datacenter.

Browse GPU Servers

gigagpu

We benchmark, deploy, and optimise GPU infrastructure for AI workloads. All data in our guides comes from real-world testing on our UK-based dedicated GPU servers.

Ready to deploy your AI workload?

Dedicated GPU servers from our UK datacenter. NVMe storage, 1Gbps networking, full root access.

Browse GPU Servers Contact Sales

Have a question? Need help?