O que video-to-srt faz?
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:
- Text burned into the frame (OCR) - exact spelling/accents, often the real lyrics.
- Speech recognition on short windows - what is actually said, and when.
- 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/nullfor short words/replies.asr_probe.py MEDIA prefix START T0 T1 --step 0.4to find where a phrase ends.asr_probe.py MEDIA vadonly as a rough first map. Force the language you expect per region (--lang esfor sung Spanish,--lang enfor 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-whisperbackend is provided but was not exercised in the sandbox where this was built.