跳至主要內容
SubtitleMatrix

JSON 字幕格式

這種格式能表達什麼

文字樣式
字型、顏色、描邊、陰影
畫面定位
是
卡拉 OK 計時
是
字幕段落內換行
是
時間軸
每條字幕都有開始與結束時間
時間精確度
1 毫秒
時間以影格編號儲存
否
由右至左的文字
是

範例

一份典型的 JSON 檔,以及從中讀出了什麼

檔案

{
  "version": 1,
  "title": "Fixture: typical",
  "fps": 25,
  "styles": {
    "Default": {
      "name": "Default",
      "fontFamily": "Arial",
      "fontSize": 20,
      "primaryColor": "#FFFFFF",
      "bold": false,
      "italic": false
    }
  },
  "generator": "subtitlematrix fixtures",
  "cues": [
    {
      "id": "1",
      "start": 0,
      "end": 2000,
      "lines": [
        "Hello world.",
        "Second line."
      ],
      "style": "Default",
      "position": {
        "x": 100,
        "y": 200,
        "align": "center"
      }
    },
    {
      "id": "2",
      "start": 2500,
      "end": 4000,
      "lines": [
        "Plain line.",
        {
          "text": "Styled line.",
          "tags": [
            {
              "kind": "italic",
              "start": 0,
              "end": 6
            }
          ]
        }
      ]
    },
    {
      "id": "3",
      "start": 4500,
      "end": 6000,
      "lines": [
        "Roger: I am here."
      ],
      "speaker": "Roger"
    }
  ]
}

從中讀出了什麼

3 cues, 5 lines of text

  0 ms → 2000 ms
    Hello world.
    Second line.
    [Default; position 100,200 (center)]
  2500 ms → 4000 ms
    Plain line.
    Styled line.   [italic ×1]
  4500 ms → 6000 ms
    Roger: I am here.
    [speaker Roger]

Outside the cues:
  styles     Default
  other keys version, title, fps, generator — carried through untouched

右欄不是轉換產物,而是本站從左欄讀出的內容,也是這份檔案每一次轉換的起點。

一份結構鬆散的 JSON 檔,仍能讀出什麼

檔案

{
    "cues": [
        { "start": "0:00:01,5", "end": "0:00:03,0", "text": "Unpadded timecode." },
        { "start": 4000.5, "end": 5000, "lines": ["Fractional start.", { "text": "Second.", "tags": [] }] },
        { "start": 9000, "end": 8000, "lines": ["End before start."] },
        { "start": "nope", "end": 12000, "lines": ["No readable start."] },
        { "start": 13000, "lines": ["No end at all."] }
    ],
    "generator": "subtitlematrix boundary",
    "styles": {},
    "title": "Fixture: boundary"
}

從中讀出了什麼

3 cues, 4 lines of text

  1500 ms → 3000 ms
    Unpadded timecode.
  4001 ms → 5000 ms
    Fractional start.
    Second.
  9000 ms → 9001 ms
    End before start.

Outside the cues:
  other keys generator, title — carried through untouched

Reported while reading — repaired or skipped, never silently:
  2 × entries with no readable start and end time (they are not cues, so they were skipped)
  1 × cue times that were not whole milliseconds (they were rounded to the nearest millisecond)
  1 × cues whose end time was not after their start time (they were given a 1ms duration)

真實檔案會帶 BOM、Windows 換行、小數毫秒,或結束早於開始的 cue。這些都不會拋錯:能修的在讀入時修好,讀不出的跳過並計數。

把 SubtitleMatrix JSON 轉成其他格式

每一個都完全在你的瀏覽器裡執行。標籤標明了那個方向要付出什麼代價,打開之前就能看到。

轉換為此格式

SubtitleMatrix 的 JSON 是本站自己的字幕表示,也是格式轉換的中間基準。這一頁是它的說明:能存什麼、不能存什麼,以及每一種可以轉出的格式。

上方能力表就是全部,沒有藏起來的功能。某一列寫「否」,那就是轉進 JSON 時會失去的東西,下面每一個轉換頁都會在開啟檔案前先講清楚。所有的轉換都在瀏覽器裡跑,不上傳、也不需要帳號。

本站的 JSON 以版本號加 cues 陣列描述字幕,時間是整數毫秒;它保留樣式、定位與卡拉OK,這些正是多數播放器格式留不住的東西。它面向腳本與流水線,不是拿給播放器直接開的檔案。

常見問題

本站的 JSON 字幕檔長什麼樣子?

一個 version 欄位、可選的 styles 物件、可選的 fps 與 title,以及 cues 陣列。每條 cue 的 start 與 end 是整數毫秒,文字放在 lines 陣列裡,行內樣式放在該行的 tags 陣列。

JSON 格式會保留樣式、定位與卡拉OK嗎?

會,而且比播放器格式完整:styles 表存字型、字號、顏色、描邊與邊距,行內樣式存在 tags,螢幕座標存在每條 cue 的 position,卡拉OK用區間標記記到音節。

JSON 裡的每一條 cue 都同時有開始與結束時間嗎?

是,而且時間寫成 4126 這種整數毫秒。這是 JSON 能達到的精度,數字是精確的;一條 cue 可以很短、很長,或與下一條重疊,檔案本身不替你做任何取捨。

JSON 該轉成哪一種格式?

本站沒有任何播放器格式裝得下 JSON 的全部欄位,所以沒有免費的方向;每一頁轉換都有自己的損失清單。挑目標時看哪一份清單你能接受,而不是看哪個格式最常見。

JSON 字幕檔可以直接用文字編輯器改嗎?

可以,只要逗號與引號保持正確。時間是純數字的毫秒,改一條 cue 的起點就是改 start 的整數值;改完仍然讀得回來。