How I Built a Video-to-Text Tool with Supadata: Link In, SRT Out

Dkphhh Created@

A while back I got tired of scrubbing long videos to find one quote. So I built Video to Text: paste a YouTube, TikTok, Instagram, X, or Facebook link and get a transcript you can export as SRT, VTT, TXT, or CSV.

From the outside it looks like a simple form. The interesting part is what happens after you hit submit: checking whether the platform already has captions, falling back to AI when it doesn't, waiting on long jobs, and turning millisecond timestamps into subtitle files that open in a video editor.

Supadata does the transcription half. Below is the pipeline I use, compressed into one Node script you can run today.

What Supadata actually does

Supadata is one API for video transcripts. Give it a public URL — YouTube, TikTok, Instagram, X, Facebook, or a direct MP4/MP3 link — and it returns the text with timing data.

The parameter that matters most is mode: 'auto'. Supadata looks for the platform's own captions first. If they exist, you usually get them right away and pay one credit. If they don't, it generates a transcript with AI at two credits per minute. That one flag saves you from writing separate logic for every platform.

The response comes back in one of two shapes. Short videos and native captions usually return the transcript immediately. Longer videos return HTTP 202 with a jobId, and you poll until the job finishes. Handling both paths is the whole trick.

Step 1: Get an API key

Create a Supadata account and copy an API key from the dashboard. The free tier includes 100 credits, which is enough to test everything here.

Sign up with my link: https://supadata.ai/r/GFBJJ46Y

It's a referral link: you get the same free tier, and I get credits if you upgrade.

Step 2: Install the SDK

npm install @supadata/js

The script below needs Node 18 or newer. Save it as transcribe.mjs.

Step 3: Fetch the transcript and handle async jobs

Here is the complete script. It fetches a transcript, handles async jobs, and writes both a text file and an SRT file.

// transcribe.mjs
import { Supadata, SupadataError } from '@supadata/js';
import { writeFile } from 'node:fs/promises';

const supadata = new Supadata({
  apiKey: process.env.SUPADATA_API_KEY
});

const url = process.argv[2];

if (!url) {
  console.error('Usage: node transcribe.mjs <video-url>');
  process.exit(1);
}

async function fetchTranscript(url) {
  const result = await supadata.transcript({
    url,
    text: false, // keep timestamped chunks
    chunkSize: 120, // max characters per chunk
    mode: 'auto' // native captions first, AI fallback
  });

  // Small videos and native captions come back immediately.
  if (!('jobId' in result)) return result;

  // Long videos return a job ID. Poll until the job settles.
  while (true) {
    const job = await supadata.transcript.getJobStatus(result.jobId);

    if (job.status === 'failed') {
      throw new Error(job.error?.message ?? 'Transcription failed');
    }

    if (job.status === 'completed') {
      // Depending on the SDK version and platform, the transcript may be
      // wrapped in `result` or returned at the top level.
      const transcript = job.result ?? job;
      if (!transcript.content) throw new Error('Completed job has no transcript');
      return transcript;
    }

    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
}

function toSrt(chunks) {
  const timestamp = (ms) => {
    const pad = (value, width = 2) => String(value).padStart(width, '0');
    const hours = Math.floor(ms / 3_600_000);
    const minutes = Math.floor((ms % 3_600_000) / 60_000);
    const seconds = Math.floor((ms % 60_000) / 1000);
    const millis = ms % 1000;

    return `${pad(hours)}:${pad(minutes)}:${pad(seconds)},${pad(millis, 3)}`;
  };

  return chunks
    .map((chunk, index) => {
      const start = timestamp(chunk.offset);
      const end = timestamp(chunk.offset + chunk.duration);
      return `${index + 1}\n${start} --> ${end}\n${chunk.text.trim()}\n`;
    })
    .join('\n');
}

try {
  const transcript = await fetchTranscript(url);

  if (typeof transcript.content === 'string') {
    throw new Error('Expected timestamped chunks. Keep text: false.');
  }

  if (transcript.content.length === 0) {
    throw new Error('No speech detected in this video.');
  }

  await writeFile(
    'transcript.txt',
    transcript.content.map((chunk) => chunk.text.trim()).join('\n\n')
  );
  await writeFile('transcript.srt', toSrt(transcript.content));

  console.log(`Language: ${transcript.lang}`);
  console.log(`Chunks: ${transcript.content.length}`);
  console.log('Wrote transcript.txt and transcript.srt');
} catch (error) {
  if (error instanceof SupadataError) {
    console.error(`${error.error}: ${error.message}`);
    console.error(error.details);
  } else {
    console.error(error);
  }
  process.exit(1);
}

Three details are easy to miss:

  • text: false keeps timestamped chunks. With text: true you get one long string and lose the timing SRT needs.
  • chunkSize: 120 caps each chunk at about 120 characters. Smaller chunks read better as subtitles; larger chunks make a cleaner plain-text transcript.
  • Poll once per second. That's Supadata's recommendation, and polling faster won't finish the job sooner.

Job results expire one hour after completion, so store the transcript as soon as the job succeeds. In Video to Text I save it to the user's local history immediately.

Step 4: Turn chunks into SRT

Each chunk has offset and duration in milliseconds. SRT wants HH:MM:SS,mmm, so toSrt pads the hours, minutes, and seconds, then appends the milliseconds after a comma. The end time is offset + duration. Cues are separated by a blank line and numbered from 1.

The script writes transcript.txt for reading and transcript.srt for editing. The SRT opens in Premiere, DaVinci Resolve, Final Cut, and most players.

Step 5: Run it

SUPADATA_API_KEY=your_key node transcribe.mjs "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

You should see the detected language, the number of chunks, and two new files. A 30-second YouTube Short usually finishes before the first poll. A 40-minute podcast will sit in the queued state for a bit, then switch to active.

Things I learned the hard way

Long videos are always async. Anything over roughly 20 minutes returns a job ID, and platform URLs can switch to async mid-request even when they start synchronously. Build the polling path first.

Language is a preference, not a guarantee. If you ask for lang: 'en' and the video has no English captions, Supadata returns the first available language and lists the rest in availableLangs. My app shows a language picker before submitting for this reason.

Empty content is still billable. A video with no speech returns an empty array and still counts as a request. Check for it before writing an empty file.

Live streams are not supported. Only finished media can be transcribed.

mode: 'native' is the cheap path. If you only want existing captions, native skips AI generation and returns a transcript-unavailable error when none exist. For a subtitle tool, that error is useful information.

Wrapping up

That's the core of Video to Text: one API call, one polling loop, and a small formatter. The rest of the product is UI, billing, local history, and export options.

If you're building a summarizer, a newsletter bot, a search index, or a subtitle tool, start with the transcript. Supadata handles the platform-specific parts so you can work on the product around it.

Try the app: https://video2text.net Get a Supadata key: https://supadata.ai/r/GFBJJ46Y

Disclosure: the Supadata links above are referral links.