Convert SRT to VTT with PHP using cURL and CURLFile — the standard multipart upload path on any PHP 7.4+ install. No Composer packages required.
Pick PHP when you're working inside Laravel, WordPress, or shared hosting where the runtime is already PHP and you don't want to add another service to the stack.
Convert SRT to VTT
<?php
$apiUrl = 'https://api.example.com/api/v1/convert';
$apiKey = getenv('SUBTOVTT_API_KEY');
$curl = curl_init($apiUrl);
$file = new CURLFile('movie.srt', 'application/x-subrip', 'movie.srt');
$post = [
'file' => $file,
'from' => 'srt',
'to' => 'vtt',
];
$headers = [];
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $apiKey"],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADERFUNCTION => function ($curl, $header) use (&$headers) {
$parts = explode(':', $header, 2);
if (count($parts) === 2) {
$headers[strtolower(trim($parts[0]))] = trim($parts[1]);
}
return strlen($header);
},
]);
$body = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
if ($status !== 200) {
throw new Exception("Conversion failed: $status $body");
}
echo 'Cues: ' . $headers['x-cue-count'] . PHP_EOL;
file_put_contents('movie.vtt', $body);
The response body is the converted .vtt file, saved here with file_put_contents. The CURLOPT_HEADERFUNCTION callback captures the X-Cue-Count response header so you can log or validate the result.
Add optional parameters such as clean_sdh or max_line_length to the $post array to shape the output in the same request.
Note:
CURLFilerequires PHP 5.5+ and thefileinfoextension. SetSUBTOVTT_API_KEYin your environment first (100 free credits on key creation).
Convert between any formats
- Convert SRT to VTT →
- Convert VTT to SRT →
- Convert ASS to SRT →
- Convert SRT to ASS →
- Convert ASS to VTT →
- Convert VTT to ASS →
- Convert SRT to TXT →
Next
- Convert SRT to VTT with Node.js →
- Convert SRT to VTT with Go →
- Full API reference →
- Free subtitle tester → — no signup required