Convert a YouTube Transcript to SRT
Get a transcript in standard JSON, then convert its timed segments to SRT on your own computer. The script below uses the segment starts and durations and makes zero network requests.
Documentation reviewed: 2026-11-14 · By PostToData
Get one timed caption track
Use the transcript tool to inspect an example, or read the transcript REST operation in standard format. Save the successful JSON response as transcript.json. A plain transcript copied as text lacks the cue boundaries this script needs.
Generate an SRT file
Save the script as to_srt.py and run python3 to_srt.py < transcript.json > subtitles.srt. The script orders cues by time, preserves their text and rejects a response without usable timed segments. It does not invent timing for an untimed transcript.
Check it against your video
Open the SRT with the video in an editor. Check the first cue, a transition in the middle and the last cue. If the source cues overlap or the edit differs from the source video, fix timing before importing. Verify you have permission to reuse the captions.
SRT conversion script
import json, math, sys
def clock(ms):
seconds, ms = divmod(ms, 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
return f"{hours:02}:{minutes:02}:{seconds:02},{ms:03}"
payload = json.load(sys.stdin)
items = payload.get("data", {}).get("items", [])
segments = items[0].get("segments", []) if items else []
cues = []
for cue in sorted(segments, key=lambda cue: cue["start"]):
start, duration = cue["start"], cue["duration"]
text = "\n".join(line.strip() for line in cue["text"].splitlines() if line.strip())
if not (math.isfinite(start) and math.isfinite(duration) and start >= 0 and duration > 0 and text):
continue
a = round(start * 1000)
b = max(a + 1, round((start + duration) * 1000))
cues.append(f"{len(cues)+1}\n{clock(a)} --> {clock(b)}\n{text}")
if not cues:
sys.exit("No timed captions in the input JSON.")
sys.stdout.reconfigure(encoding="utf-8")
print("\n\n".join(cues))Example sources and documentation
Current prices & implemented operations
| Operation | Per successful call | 1,000 successful calls |
|---|---|---|
| YouTube · Transcript | $0.003 | $3.00 |
The 1,000-call figure is list price multiplied by calls, not 1,000 records or a top-up package. The example only previews the first operation: no upstream fetch or charge. To retrieve data, remove dry_run=1 and supply Authorization: Bearer API_KEY. Keep max_price_usd to reject a price above the approved amount.
curl --get "https://posttodata.com/v1/youtube/transcript" \
--data-urlencode 'id=UF8uR6Z6KLc' \
--data-urlencode 'format=standard' \
--data-urlencode 'max_price_usd=0.003' \
--data-urlencode 'dry_run=1'A per-call ceiling is not a shared budget for the whole task. Bound the number of approved calls and stop on 402, 412 or 429; do not automatically raise limits or rotate accounts.
Frequently asked questions
Will this transcribe a video with no captions?
This recipe uses an available caption track. If the source cannot provide timed captions, the script exits without writing any cues.
Related guides
- Export a Batch of TikTok Captions to CSV
- Research Recent YouTube Videos by Keyword
- Export YouTube Comments to CSV or Excel
- Build a Creator Shortlist for a Product Campaign