Communitygithub.com

video-to-srt

Create accurate .srt subtitle files from a video or audio file in any language, including hard cases - songs, rap/lyrics, music under speech, two people talking, mixed languages, and videos that already have text burned into the frame. Use whenever the user wants subtitles, an .srt, a transcript with timestamps, lyrics synced to a video, or says an auto-generated SRT is inaccurate, out of sync, or missing lines (Indonesian too - "buat srt", "subtitle", "teks lagu", "hasil srt tidak akurat / banyak yang hilang"). Also use to fix or complete an existing .srt against its video.

What is video-to-srt?

video-to-srt is a Claude Code agent skill that create accurate .srt subtitle files from a video or audio file in any language, including hard cases - songs, rap/lyrics, music under speech, two people talking, mixed languages, and videos that already have text burned into the frame. Use whenever the user wants subtitles, an .srt, a transcript with timestamps, lyrics synced to a video, or says an auto-generated SRT is inaccurate, out of sync, or missing lines (Indonesian too - "buat srt", "subtitle", "teks lagu", "hasil srt tidak akurat / banyak yang hilang"). Also use to fix or complete an existing .srt against its video.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/pawang-dev/video-to-srt/tree/HEAD/skills/video-to-srt

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

What does video-to-srt do?

Plain Whisper on a whole video gives wrong timings and silently drops sung or music-backed parts. This skill gets accurate subtitles by combining three sources of truth and then measuring timings instead of trusting one automatic pass:

  1. Text burned into the frame (OCR) - exact spelling/accents, often the real lyrics.
  2. Speech recognition on short windows - what is actually said, and when.
  3. A coverage check - where the audio is active but no subtitle exists yet.

Scripts are in scripts/ (run from that folder: they import each other). Read references/lessons.md before step 4 (references/example_cues.json shows the cue format); read references/sandbox.md if a download or install fails.

Workflow

0. Setup - python scripts/setup_env.py --whisper small --ocr-langs <tesseract codes> (add --check to only report). Models come from GitHub, so it works where Hugging Face is blocked. If disk is tight use --whisper base. If the user has a normal machine with internet, they can instead use faster-whisper/stable-ts (--backend faster-whisper); say which you used.

1. Look first - python scripts/probe_video.py VIDEO, then view the contact sheet image. Decide: is text burned in (where, which language)? one voice or several? song, speech, or both? Is the audio loud everywhere (music)? This determines the plan; do not skip it - on the example video the contact sheet revealed a two-party conversation plus captions that the first pass had missed.

2. Harvest on-screen text (if any) - one run per screen region: python scripts/ocr_frames.py VIDEO --crop W:H:X:Y --lang spa --out sub.json Use --ignore-mean-above N to skip scenes where that region shows something else, and --merge-similar 0.85 for typewriter-style text. Dark UI with light text needs no flags (auto-polarity + autocontrast). Spot-check a few frames by eye.

3. Measure speech - never rely on one transcript of the full file. Use the probes:

  • asr_probe.py MEDIA slide T0 T1 --win 0.9 --step 0.3 --lang en 2>/dev/null for short words/replies.
  • asr_probe.py MEDIA prefix START T0 T1 --step 0.4 to find where a phrase ends.
  • asr_probe.py MEDIA vad only as a rough first map. Force the language you expect per region (--lang es for sung Spanish, --lang en for English speech); auto-detect flips languages mid-clip and garbles code-switching media.

4. Assemble cues in a JSON list (start, end, text). Rules that matter:

  • Prefer audio timing for what is said or sung; use OCR timing only for text that is not spoken.
  • One cue per spoken/sung line (about 1-4 s, max 2 lines of text). Split dialogue per speaker (separate cues, or "- " prefixes inside one cue).
  • Sung blocks: the on-screen caption usually shows a couplet once while the audio repeats it. Measure each repetition and give it its own cues (see lessons.md).
  • Text for a cue comes from OCR when available, else from the transcript; clean obvious ASR mishearings using context, and tell the user which lines are inferred.

5. Build and validate - python scripts/build_srt.py build cues.json -o out.srt --video VIDEO (reports overlaps, too-long/short cues, reading speed, and whether ffmpeg can parse it). To start from an existing SRT: build_srt.py parse in.srt -o cues.json, edit, rebuild.

6. Find what is missing - python scripts/coverage.py VIDEO out.srt. Every reported gap is either music-only (fine) or lines you have not transcribed (repeats, quick replies, adlibs). Re-measure those spans with step 3, add cues, repeat until the remaining gaps are only music.

7. Report honestly - deliver the .srt and list: which parts are measured vs. inferred, timing accuracy (about +-0.1 s for speech, +-0.3 s for music-backed singing), and any lines worth a human listen. Offer re-timing or a different line split rather than claiming the file is perfect.

Input from the user

If the user already has an SRT, compare it with the video before editing: it is often a copy of the on-screen text and lacks everything that is only spoken. List what is missing (with time ranges) before merging. Keep the user's cue texts and spelling when they are right; change only what the measurements prove wrong, and say what changed.

Limits

  • No vocal separation is bundled (Demucs needs a large download); heavy music lowers accuracy.
  • Whisper small is the largest model that fits small sandboxes; names, slang and sung words are misheard often. OCR text beats ASR text whenever both exist.
  • faster-whisper backend is provided but was not exercised in the sandbox where this was built.

Related Skills