Convert SRT to VTT with Rust

Convert subtitle formats in Rust with the SubtoVTT API. reqwest blocking example with multipart. Free API key, 100 credits to start. v1 · stable

Convert SRT to VTT with Rust using the reqwest blocking client and its built-in multipart support. It's one small dependency that removes all the boundary and header plumbing.

Pick Rust when you need a single static binary, a minimal memory footprint, or maximum throughput in a subtitle-processing pipeline.

Add the dependency

[dependencies]
reqwest = { version = "0.12", features = ["multipart", "blocking"] }

Convert SRT to VTT

use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("SUBTOVTT_API_KEY")?;
    let client = reqwest::blocking::Client::new();

    let file = fs::read("movie.srt")?;
    let part = reqwest::blocking::multipart::Part::bytes(file)
        .file_name("movie.srt")
        .mime_str("application/x-subrip")?;

    let form = reqwest::blocking::multipart::Form::new()
        .part("file", part)
        .text("from", "srt")
        .text("to", "vtt");

    let response = client
        .post("https://api.example.com/api/v1/convert")
        .bearer_auth(&api_key)
        .multipart(form)
        .send()?;

    if !response.status().is_success() {
        eprintln!("Conversion failed: {} {}", response.status(), response.text()?);
        std::process::exit(1);
    }

    if let Some(cues) = response.headers().get("x-cue-count") {
        println!("Cues: {}", cues.to_str()?);
    }

    fs::write("movie.vtt", response.bytes()?)?;
    Ok(())
}

reqwest handles the multipart framing, and bearer_auth sets the Authorization: Bearer <key> header for you. The converted file arrives as the response body and is written to movie.vtt.

The x-cue-count response header tells you how many cues the converter wrote. Set SUBTOVTT_API_KEY in your environment first (100 free credits on key creation).

Tip: build with cargo build --release for a static binary you can drop onto any server — no runtime required.

Convert between any formats

Next

↑ Back to top