Videos
Add Video Captions/Chapters/Subtitles
Add subtitles, captions, or chapter tracks to an existing video.
API URL
Headers
| Name | Type | Description |
|---|---|---|
| Authorization | String | Bearer YOUR_API_KEY |
File format
Captions should be in WebVTT or SRT format.
Post the file using HTML Form
- The file can be added to a form input named "file".
- The Content-Type should be multipart/form-data.
To upload a captions/subtitle file
POST https://upload.dyntube.com/v1/videos/captions/{video-id}
Request Body
| Name | Type | Description |
|---|---|---|
| language | String | two-letter language code. i.e. en,fr. The default is 'en'. |
| file* | File | Form File |
| label | String | Caption label, such as English or French. The default is English. For video chapters, use Chapters. |
| default | Boolean | Default captions in the video player. The default is false. |
| rtl | Boolean | RTL support. The default is false. |
| kind | String | The value should be subtitles or chapters depending on the use case. |
200: OK
json
{
"ok": true,
"error": null,
"captions": {}
}Code Samples
C\#
csharp
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
class Program
{
static void Main(string[] args)
{
string videoId = "your_video_id";
string bearerToken = "your_bearer_token";
string filePath = "path/to/captions.vtt";
string language = "en";
string label = "English";
bool isDefault = true;
bool isRtl = false;
string url = $"https://upload.dyntube.com/v1/videos/captions/{videoId}";
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
using (var form = new MultipartFormDataContent())
{
form.Add(new StreamContent(File.OpenRead(filePath)), "file", "captions.vtt");
form.Add(new StringContent(language), "language");
form.Add(new StringContent(label), "label");
form.Add(new StringContent(isDefault.ToString()), "default");
form.Add(new StringContent(isRtl.ToString()), "rtl");
var response = httpClient.PostAsync(url, form).Result;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
Console.WriteLine("Captions updated successfully.");
}
else
{
Console.WriteLine($"Error updating captions. Status code: {response.StatusCode}");
}
}
}
}
}Node.js
javascript
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');
const videoId = 'your_video_id';
const bearerToken = 'your_bearer_token';
const filePath = 'path/to/captions.vtt';
const language = 'en';
const label = 'English';
const isDefault = true;
const isRtl = false;
const url = `https://upload.dyntube.com/v1/videos/captions/${videoId}`;
const formData = new FormData();
formData.append('file', fs.createReadStream(filePath), 'captions.vtt');
formData.append('language', language);
formData.append('label', label);
formData.append('default', isDefault ? 1 : 0);
formData.append('rtl', isRtl ? 1 : 0);
axios.post(url, formData, {
headers: {
Authorization: `Bearer ${bearerToken}`,
...formData.getHeaders()
}
})
.then(response => {
if (response.status === 200) {
console.log('Captions updated successfully.');
} else {
console.log(`Error updating captions. Status code: ${response.status}`);
}
})
.catch(error => {
console.log(`Error updating captions. ${error}`);
});Python
python
import requests
video_id = 'your_video_id'
bearer_token = 'your_bearer_token'
file_path = 'path/to/captions.vtt'
language = 'en'
label = 'English'
is_default = True
is_rtl = False
url = f'https://upload.dyntube.com/v1/videos/captions/{video_id}'
headers = {
'Authorization': f'Bearer {bearer_token}',
}
files = {
'file': ('captions.vtt', open(file_path, 'rb')),
}
data = {
'language': language,
'label': label,
'default': int(is_default),
'rtl': int(is_rtl),
}
response = requests.post(url, headers=headers, files=files, data=data)
if response.status_code == 200:
print('Captions updated successfully.')
else:
print(f'Error updating captions. Status code: {response.status_code}')PHP
php
$videoId = 'your_video_id';
$bearerToken = 'your_bearer_token';
$filePath = 'path/to/captions.vtt';
$language = 'en';
$label = 'English';
$isDefault = true;
$isRtl = false;
$url = "https://upload.dyntube.com/v1/videos/captions/{$videoId}";
$ch = curl_init($url);
$data = array(
'file' => new CURLFile($filePath),
'language' => $language,
'label' => $label,
'default' => $isDefault ? 1 : 0,
'rtl' => $isRtl ? 1 : 0
);
curl_setopt_array($ch, array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array("Authorization: Bearer {$bearerToken}"),
CURLOPT_RETURNTRANSFER => true
));
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 200 && $status < 300) {
echo "Captions updated successfully.";
} else {
echo "Error updating captions. Status code: {$status}";
}Related Pages
- Get video to verify existing captions and subtitles.
- Delete captions, subtitles, or chapters to remove a text track.
- Update video to adjust player settings such as default captions behavior.
- AI Language Codes if captions are generated by AI transcription or translation.
Something missing or wrong here? Tell us and we will correct it. New to DynTube? Start with uploading and embedding.