# Subtitle converter API

> Convert SRT, WebVTT, ASS / SSA, SBV and TTML subtitles, shift or resync timings, change frame rate, fix old Vietnamese encodings and check line length.

- Endpoint: `POST https://apibox.io.vn/v1/subtitles`
- Category: Content & HTML
- HTML docs: https://apibox.io.vn/docs/subtitles/ (Vietnamese: https://apibox.io.vn/vi/docs/subtitles/)
- Online tool: https://apibox.io.vn/tools/subtitles/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Send a subtitle file (`subtitle` text, a raw body or a file upload) and choose `to`: `srt`, `vtt`, `ass`, `sbv`, `ttml`, `json` (cues with start / end in ms) or `text` (plain transcript). The input format is detected automatically. Files in Windows-1258, TCVN3 (ABC) or VNI-Windows — common for old Vietnamese subtitles — are converted to Unicode (`encoding=auto`, or force it).

Retiming: `shift` (`+1.5s`, `-500ms`, `00:00:02,000`), `fps_from` / `fps_to` (23.976 ↔ 25), and `sync` with two points to stretch a whole file that drifts. `fix_overlaps`, `wrap` (re-break lines at `max_chars`, balancing two lines), `strip_tags` and `remove_empty` clean the cues; `merge` with a second file (`merge_mode` interleave or append) and `split_at` (two parts, rebased to zero) combine or cut files.

Every response includes `checks`: overlaps, cues shorter than `min_duration_ms` (833) or longer than `max_duration_ms` (7000), reading speed above `max_cps` (20 characters per second), lines over `max_chars` (42) and more than `max_lines` (2), the usual Netflix / YouTube style limits. `format=file` returns the converted file for download.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `subtitle` | body | string | yes |  | Subtitle text, or a file (multipart `file`, `subtitle_base64`) or a raw text body. |
| `to` | body | string | no |  | `srt`, `vtt`, `ass`, `sbv`, `ttml`, `json` or `text` (default: same as input). |
| `from` | body | string | no | `auto` | Input format, detected by default. |
| `encoding` | body | string | no | `auto` | `auto`, `utf-8`, `windows-1258`, `tcvn3`, `vni`, `windows-1252`, `utf-16le`. |
| `shift` | body | string | no |  | Move all cues: `+1.5s`, `-500ms`, `00:00:02,000`. |
| `fps_from` | body | number | no |  | Frame-rate change: source fps (with `fps_to`). |
| `fps_to` | body | number | no |  | Target fps. |
| `sync` | body | array | no |  | Two points `[{"from":"00:00:10,000","to":"00:00:11,200"}, {...}]`. |
| `fix_overlaps` | body | boolean | no | `false` | End each cue before the next starts. |
| `wrap` | body | boolean | no | `false` | Re-break long lines at `max_chars`. |
| `merge` | body | string | no |  | A second subtitle to merge (`merge_mode` interleave / append, `merge_offset`). |
| `split_at` | body | string | no |  | Split into two parts at this time. |
| `max_chars` | body | number | no | `42` | Characters per line for checks and wrapping. |
| `max_cps` | body | number | no | `20` | Maximum reading speed (characters per second). |
| `format` | body | string | no | `json` | `json` or `file` (download the converted file). |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/subtitles" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"subtitle":"1\n00:00:01,000 --> 00:00:03,500\nXin chào các bạn\n\n2\n00:00:03,400 --> 00:00:06,000\nHôm nay chúng ta học về phụ đề\n","to":"vtt","shift":"+2s"}'
```

## Example response

```json
{
  "from": "srt",
  "to": "vtt",
  "encoding": null,
  "cues": 2,
  "duration_ms": 8000,
  "operations": [
    "shift:2000ms"
  ],
  "warnings": [],
  "checks": {
    "issues": [
      {
        "cue": 1,
        "start": "00:00:03,000",
        "type": "overlap",
        "message": "Overlaps the next cue by 100 ms",
        "value": 100
      }
    ],
    "counts": {
      "overlap": 1
    },
    "total": 1
  },
  "content": "WEBVTT\n\n00:00:03.000 --> 00:00:05.500\nXin chào các bạn\n\n00:00:05.400 --> 00:00:08.000\nHôm nay chúng ta học về phụ đề\n"
}
```

## Use cases

- Convert SRT from translators to WebVTT for HTML5 players
- Fix subtitles that drift because of a 23.976 / 25 fps mismatch
- Repair old TCVN3 / VNI Vietnamese subtitles that show garbage characters
- Check reading speed and line length before publishing

## FAQ

### How do I fix a file that drifts more and more?

Use sync with two points: the time of an early cue and the time it should be, and the same for a late cue. All cues are stretched linearly between them.

### Are ASS styles kept?

When converting ASS to ASS the original [Script Info] and styles are kept and each cue keeps its style name. Override tags such as {\i1} are removed from the text.

### What is the maximum size?

Up to 20,000 cues per file, within your plan’s upload size.
