libbitsub 1.9.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -8
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/ts/diagnostics.d.ts +35 -0
- package/dist/ts/diagnostics.d.ts.map +1 -0
- package/dist/ts/diagnostics.js +102 -0
- package/dist/ts/diagnostics.js.map +1 -0
- package/dist/ts/frame-export.d.ts +6 -0
- package/dist/ts/frame-export.d.ts.map +1 -0
- package/dist/ts/frame-export.js +235 -0
- package/dist/ts/frame-export.js.map +1 -0
- package/dist/ts/parsers.d.ts +44 -4
- package/dist/ts/parsers.d.ts.map +1 -1
- package/dist/ts/parsers.js +269 -56
- package/dist/ts/parsers.js.map +1 -1
- package/dist/ts/renderers.d.ts +21 -2
- package/dist/ts/renderers.d.ts.map +1 -1
- package/dist/ts/renderers.js +150 -27
- package/dist/ts/renderers.js.map +1 -1
- package/dist/ts/types.d.ts +110 -1
- package/dist/ts/types.d.ts.map +1 -1
- package/dist/ts/utils.d.ts +1 -1
- package/dist/ts/utils.d.ts.map +1 -1
- package/dist/ts/utils.js +8 -1
- package/dist/ts/utils.js.map +1 -1
- package/dist/ts/worker.d.ts.map +1 -1
- package/dist/ts/worker.js +6 -4
- package/dist/ts/worker.js.map +1 -1
- package/dist/wrapper.d.ts +4 -2
- package/dist/wrapper.d.ts.map +1 -1
- package/dist/wrapper.js +4 -1
- package/dist/wrapper.js.map +1 -1
- package/package.json +9 -5
- package/pkg/README.md +192 -8
- package/pkg/libbitsub.d.ts +12 -220
- package/pkg/libbitsub.js +65 -118
- package/pkg/libbitsub_bg.wasm +0 -0
- package/pkg/libbitsub_bg.wasm.d.ts +7 -4
- package/pkg/package.json +2 -2
- package/src/wrapper.ts +20 -1
package/dist/ts/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/ts/worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,IAAI,YAAY,GAAkB,IAAI,CAAA;AACtC,IAAI,iBAAiB,GAA2B,IAAI,CAAA;AACpD,IAAI,SAAS,GAAG,CAAC,CAAA;AAEjB,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAM7B,CAAA;AAEH,0CAA0C;AAC1C,MAAM,UAAU,iBAAiB;IAC7B,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,IAAI,KAAK,WAAW,CAAA;AACxG,CAAC;AAED,6DAA6D;AAC7D,SAAS,kBAAkB;IACvB,OAAO
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/ts/worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,IAAI,YAAY,GAAkB,IAAI,CAAA;AACtC,IAAI,iBAAiB,GAA2B,IAAI,CAAA;AACpD,IAAI,SAAS,GAAG,CAAC,CAAA;AAEjB,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAM7B,CAAA;AAEH,0CAA0C;AAC1C,MAAM,UAAU,iBAAiB;IAC7B,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,IAAI,KAAK,WAAW,CAAA;AACxG,CAAC;AAED,6DAA6D;AAC7D,SAAS,kBAAkB;IACvB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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pgs-js implementation.
|
|
4
4
|
*/
|
|
5
|
-
export type { AutoSubtitleSource, AutoVideoSubtitleOptions, SubtitleAspectMode, SubtitleCueBounds, SubtitleCueMetadata, SubtitleData, SubtitleCompositionData, SubtitleDisplaySettings, SubtitleFormatName, SubtitleHorizontalAlign, SubtitleParserMetadata, SubtitleRendererBackend, SubtitleRendererEvent, SubtitleRendererStatsSnapshot, VideoSubtitleOptions, VideoVobSubOptions, RenderResult, SubtitleFrame, VobSubFrame } from './ts/types';
|
|
5
|
+
export type { AutoSubtitleSource, AutoVideoSubtitleOptions, OpenedSubtitles, SubtitleAspectMode, SubtitleCacheStats, SubtitleFrameCanvasOptions, SubtitleFrameCanvasTarget, SubtitleFrameCropMode, SubtitleFrameRenderOptions, SubtitleRenderedFrameData, SubtitleCueBounds, SubtitleCueMetadata, SubtitleData, SubtitleDiagnosticDetailValue, SubtitleDiagnosticErrorCode, SubtitleDiagnosticErrorLike, SubtitleDiagnosticsOptions, SubtitleDiagnosticWarning, SubtitleDiagnosticWarningCode, SubtitleCompositionData, SubtitleDisplaySettings, SubtitleFormatName, SubtitleHorizontalAlign, SubtitleLastRenderInfo, SubtitleParserMetadata, SubtitleRendererBackend, SubtitleRendererEvent, SubtitleRendererStatsSnapshot, VideoSubtitleOptions, VideoVobSubOptions, RenderResult, SubtitleFrame, VobSubFrame } from './ts/types';
|
|
6
|
+
export { SubtitleDiagnosticError, createSubtitleDiagnosticError, normalizeSubtitleError } from './ts/diagnostics';
|
|
6
7
|
export { initWasm, isWasmInitialized } from './ts/wasm';
|
|
7
8
|
export { isWebGPUSupported } from './ts/webgpu-renderer';
|
|
8
|
-
export { PgsParser, VobSubParserLowLevel, UnifiedSubtitleParser } from './ts/parsers';
|
|
9
|
+
export { PgsParser, VobSubParserLowLevel, UnifiedSubtitleParser, openSubtitles } from './ts/parsers';
|
|
10
|
+
export { renderFrameData, toBlob, toCanvas, toImageBitmap } from './ts/frame-export';
|
|
9
11
|
export { PgsRenderer, VobSubRenderer, createAutoSubtitleRenderer, type SubtitleRendererStats } from './ts/renderers';
|
|
10
12
|
export { detectSubtitleFormat } from './ts/utils';
|
|
11
13
|
import { PgsRenderer as _PgsRenderer, VobSubRenderer as _VobSubRenderer } from './ts/renderers';
|
package/dist/wrapper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,WAAW,EACZ,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,EACrB,0BAA0B,EAC1B,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,6BAA6B,EAC7B,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,WAAW,EACZ,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAGjH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAGvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAGxD,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGpG,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGpF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,0BAA0B,EAAE,KAAK,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAGpH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAMjD,OAAO,EAAE,WAAW,IAAI,YAAY,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC/F,OAAO,EAAE,qBAAqB,IAAI,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAE9E,0CAA0C;AAC1C,eAAO,MAAM,WAAW,qBAAe,CAAA;AAEvC,6CAA6C;AAC7C,eAAO,MAAM,cAAc,wBAAkB,CAAA;AAE7C,oDAAoD;AACpD,eAAO,MAAM,uBAAuB,+BAAyB,CAAA"}
|
package/dist/wrapper.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
* TypeScript wrapper for the libbitsub Rust rendering engine.
|
|
3
3
|
* Provides a compatible API with the original libpgs-js implementation.
|
|
4
4
|
*/
|
|
5
|
+
export { SubtitleDiagnosticError, createSubtitleDiagnosticError, normalizeSubtitleError } from './ts/diagnostics';
|
|
5
6
|
// Re-export WASM management
|
|
6
7
|
export { initWasm, isWasmInitialized } from './ts/wasm';
|
|
7
8
|
// Re-export WebGPU utilities
|
|
8
9
|
export { isWebGPUSupported } from './ts/webgpu-renderer';
|
|
9
10
|
// Re-export parsers
|
|
10
|
-
export { PgsParser, VobSubParserLowLevel, UnifiedSubtitleParser } from './ts/parsers';
|
|
11
|
+
export { PgsParser, VobSubParserLowLevel, UnifiedSubtitleParser, openSubtitles } from './ts/parsers';
|
|
12
|
+
// Re-export frame export helpers
|
|
13
|
+
export { renderFrameData, toBlob, toCanvas, toImageBitmap } from './ts/frame-export';
|
|
11
14
|
// Re-export renderers
|
|
12
15
|
export { PgsRenderer, VobSubRenderer, createAutoSubtitleRenderer } from './ts/renderers';
|
|
13
16
|
// Re-export format detection utilities
|
package/dist/wrapper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuCH,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAEjH,4BAA4B;AAC5B,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEvD,6BAA6B;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExD,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEpG,iCAAiC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEpF,sBAAsB;AACtB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,0BAA0B,EAA8B,MAAM,gBAAgB,CAAA;AAEpH,uCAAuC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEjD,gFAAgF;AAChF,8CAA8C;AAC9C,gFAAgF;AAEhF,OAAO,EAAE,WAAW,IAAI,YAAY,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC/F,OAAO,EAAE,qBAAqB,IAAI,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAE9E,0CAA0C;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAA;AAEvC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAA;AAE7C,oDAAoD;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libbitsub",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"author": "altqx",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "High-performance WASM renderer for graphical subtitles (PGS and VobSub)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/altqx/libbitsub"
|
|
10
|
+
},
|
|
7
11
|
"keywords": [
|
|
8
12
|
"libbitsub",
|
|
9
13
|
"pgs",
|
|
@@ -46,15 +50,15 @@
|
|
|
46
50
|
"format": "cargo fmt && prettier . --write"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
50
|
-
"prettier": "^3.8.
|
|
51
|
-
"typescript": "^6.0.
|
|
53
|
+
"@typescript/native-preview": "^7.0.0-dev.20260524.1",
|
|
54
|
+
"prettier": "^3.8.3",
|
|
55
|
+
"typescript": "^6.0.3"
|
|
52
56
|
},
|
|
53
57
|
"peerDependencies": {},
|
|
54
58
|
"engines": {
|
|
55
59
|
"node": ">=18"
|
|
56
60
|
},
|
|
57
61
|
"dependencies": {
|
|
58
|
-
"@webgpu/types": "^0.1.
|
|
62
|
+
"@webgpu/types": "^0.1.70"
|
|
59
63
|
}
|
|
60
64
|
}
|
package/pkg/README.md
CHANGED
|
@@ -13,8 +13,10 @@ Started as a fork of Arcus92's [libpgs-js](https://github.com/Arcus92/libpgs-js)
|
|
|
13
13
|
- Worker-backed parsing/rendering for large subtitle files
|
|
14
14
|
- Rich layout controls: scale, aspect mode, horizontal/vertical offsets, alignment, bottom padding, safe area, opacity
|
|
15
15
|
- Cue metadata and parser introspection APIs
|
|
16
|
+
- Rendered-frame export helpers for ImageData, ImageBitmap, Blob, and custom canvas targets
|
|
16
17
|
- Frame prefetching and cache control for high-level renderers
|
|
17
18
|
- Automatic format detection and unified loading helpers
|
|
19
|
+
- First-class diagnostics with structured error codes, warning hooks, and render/cache snapshots
|
|
18
20
|
- TypeScript support with exported event and metadata types
|
|
19
21
|
|
|
20
22
|
## Showcase
|
|
@@ -33,6 +35,22 @@ https://a.rafasu.com/v
|
|
|
33
35
|
|
|
34
36
|
## Installation
|
|
35
37
|
|
|
38
|
+
For pure Rust parser/rendering logic:
|
|
39
|
+
|
|
40
|
+
```toml
|
|
41
|
+
[dependencies]
|
|
42
|
+
libbitsub-core = "1.10.0"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For WASM bindings from Rust:
|
|
46
|
+
|
|
47
|
+
```toml
|
|
48
|
+
[dependencies]
|
|
49
|
+
libbitsub = "1.10.0"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For JavaScript package managers:
|
|
53
|
+
|
|
36
54
|
```bash
|
|
37
55
|
npm install libbitsub
|
|
38
56
|
# or
|
|
@@ -104,6 +122,7 @@ import { PgsRenderer } from 'libbitsub'
|
|
|
104
122
|
const renderer = new PgsRenderer({
|
|
105
123
|
video: videoElement,
|
|
106
124
|
subUrl: '/subtitles/movie.sup',
|
|
125
|
+
debug: true,
|
|
107
126
|
displaySettings: {
|
|
108
127
|
scale: 1.1,
|
|
109
128
|
aspectMode: 'stretch',
|
|
@@ -112,6 +131,9 @@ const renderer = new PgsRenderer({
|
|
|
112
131
|
},
|
|
113
132
|
cacheLimit: 32,
|
|
114
133
|
prefetchWindow: { before: 1, after: 2 },
|
|
134
|
+
onWarning: (warning) => {
|
|
135
|
+
console.warn(warning.code, warning.message, warning.details)
|
|
136
|
+
},
|
|
115
137
|
onEvent: (event) => {
|
|
116
138
|
if (event.type === 'worker-state') {
|
|
117
139
|
console.log('worker', event.ready ? 'ready' : 'starting', event.sessionId)
|
|
@@ -204,12 +226,15 @@ High-level renderers expose parser and cue metadata:
|
|
|
204
226
|
const metadata = renderer.getMetadata()
|
|
205
227
|
const currentCue = renderer.getCurrentCueMetadata()
|
|
206
228
|
const cue42 = renderer.getCueMetadata(42)
|
|
229
|
+
const stats = renderer.getStats()
|
|
230
|
+
const cache = renderer.getCacheStats()
|
|
231
|
+
const lastRender = renderer.getLastRenderInfo()
|
|
207
232
|
```
|
|
208
233
|
|
|
209
234
|
Low-level parsers expose the same model:
|
|
210
235
|
|
|
211
236
|
```ts
|
|
212
|
-
import { PgsParser, UnifiedSubtitleParser, VobSubParserLowLevel } from 'libbitsub'
|
|
237
|
+
import { PgsParser, UnifiedSubtitleParser, VobSubParserLowLevel, openSubtitles } from 'libbitsub'
|
|
213
238
|
|
|
214
239
|
const vob = new VobSubParserLowLevel()
|
|
215
240
|
vob.loadFromMks(new Uint8Array(mksBuffer))
|
|
@@ -217,9 +242,13 @@ vob.loadFromMks(new Uint8Array(mksBuffer))
|
|
|
217
242
|
const parser = new UnifiedSubtitleParser()
|
|
218
243
|
const detected = parser.loadAuto({ data: subtitleBytes, fileName: 'track.mks' })
|
|
219
244
|
|
|
245
|
+
const opened = await openSubtitles({ data: subtitleBytes, fileName: 'track.mks' })
|
|
246
|
+
|
|
220
247
|
console.log(detected)
|
|
221
248
|
console.log(parser.getMetadata())
|
|
222
249
|
console.log(parser.getCueMetadata(0))
|
|
250
|
+
console.log(opened.format)
|
|
251
|
+
opened.dispose()
|
|
223
252
|
```
|
|
224
253
|
|
|
225
254
|
Metadata includes:
|
|
@@ -230,6 +259,134 @@ Metadata includes:
|
|
|
230
259
|
- PGS composition count, palette ID, composition state
|
|
231
260
|
- VobSub language, track ID, IDX metadata presence, file position where available
|
|
232
261
|
|
|
262
|
+
## One-shot auto API
|
|
263
|
+
|
|
264
|
+
If you do not care whether the input is PGS or VobSub and only want one stable low-level surface, use `openSubtitles()`.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { openSubtitles } from 'libbitsub'
|
|
268
|
+
|
|
269
|
+
const subtitles = await openSubtitles({
|
|
270
|
+
data: subtitleBytes,
|
|
271
|
+
fileName: 'track.sup'
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
console.log(subtitles.format)
|
|
275
|
+
console.log(subtitles.metadata)
|
|
276
|
+
console.log(subtitles.timestamps)
|
|
277
|
+
|
|
278
|
+
const frame = subtitles.renderAtTimestamp(120.5)
|
|
279
|
+
const rendered = subtitles.renderFrameDataAtTimestamp(120.5)
|
|
280
|
+
const cue = subtitles.getCueMetadata(0)
|
|
281
|
+
|
|
282
|
+
subtitles.dispose()
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
`openSubtitles()` initializes WASM for you, auto-detects the format, loads the subtitle source, and returns a normalized handle with snapshot properties plus shared low-level helpers such as `renderAtIndex()`, `renderAtTimestamp()`, `renderFrameDataAtIndex()`, `renderFrameDataAtTimestamp()`, `getCueMetadata()`, `getLastRenderIssue()`, `clearCache()`, and `dispose()`.
|
|
286
|
+
|
|
287
|
+
Like `UnifiedSubtitleParser.loadAuto()`, this is a low-level in-memory API: pass binary subtitle content via `data` or `subData`, and optionally include `fileName`, `idxContent`, `idxUrl`, or `subUrl` as format hints or companion metadata.
|
|
288
|
+
|
|
289
|
+
## Frame export helpers
|
|
290
|
+
|
|
291
|
+
Low-level parser output can be flattened into a single exportable frame for previews, editors, snapshots, fixture generation, or visual diffing.
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import {
|
|
295
|
+
PgsParser,
|
|
296
|
+
initWasm,
|
|
297
|
+
renderFrameData,
|
|
298
|
+
toBlob,
|
|
299
|
+
toCanvas,
|
|
300
|
+
toImageBitmap
|
|
301
|
+
} from 'libbitsub'
|
|
302
|
+
|
|
303
|
+
await initWasm()
|
|
304
|
+
|
|
305
|
+
const parser = new PgsParser()
|
|
306
|
+
parser.load(new Uint8Array(arrayBuffer))
|
|
307
|
+
|
|
308
|
+
const subtitleFrame = parser.renderAtTimestamp(120.5)
|
|
309
|
+
const rendered = subtitleFrame ? renderFrameData(subtitleFrame, { crop: 'bounds' }) : null
|
|
310
|
+
|
|
311
|
+
if (rendered) {
|
|
312
|
+
const canvas = toCanvas(rendered)
|
|
313
|
+
const bitmap = await toImageBitmap(rendered)
|
|
314
|
+
const pngBlob = await toBlob(rendered)
|
|
315
|
+
|
|
316
|
+
console.log({
|
|
317
|
+
width: rendered.imageData.width,
|
|
318
|
+
height: rendered.imageData.height,
|
|
319
|
+
offsetX: rendered.offsetX,
|
|
320
|
+
offsetY: rendered.offsetY,
|
|
321
|
+
bounds: rendered.bounds,
|
|
322
|
+
canvas,
|
|
323
|
+
bitmap,
|
|
324
|
+
pngBlob
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Parser convenience methods avoid the extra `renderAtTimestamp()` step:
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
const rendered = parser.renderFrameDataAtTimestamp(120.5)
|
|
333
|
+
const fullScreenFrame = parser.renderFrameDataAtIndex(42, { crop: 'screen' })
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Cropping modes:
|
|
337
|
+
|
|
338
|
+
- `bounds` is the default. It returns a tightly cropped composed image and records where that image belongs in the original subtitle presentation area via `offsetX` and `offsetY`.
|
|
339
|
+
- `screen` preserves the full subtitle presentation dimensions, which is useful when you need stable frame sizes for test fixtures or when drawing into a presentation-sized surface.
|
|
340
|
+
|
|
341
|
+
Drawing behavior:
|
|
342
|
+
|
|
343
|
+
- `toCanvas(frame)` creates a new canvas sized to the rendered export.
|
|
344
|
+
- Passing an existing canvas target resizes it by default before drawing.
|
|
345
|
+
- Passing an existing 2D context draws in place by default, which is useful when you want subtitles composited into your own pre-sized surface.
|
|
346
|
+
|
|
347
|
+
## Diagnostics mode
|
|
348
|
+
|
|
349
|
+
Enable `debug: true` on high-level renderers when you need richer field diagnostics for malformed subtitle files. In debug mode, libbitsub records the most recent render attempt and emits structured warnings in addition to the existing lifecycle events.
|
|
350
|
+
|
|
351
|
+
```ts
|
|
352
|
+
import { PgsRenderer, SubtitleDiagnosticError } from 'libbitsub'
|
|
353
|
+
|
|
354
|
+
const renderer = new PgsRenderer({
|
|
355
|
+
video: videoElement,
|
|
356
|
+
subUrl: '/subtitles/movie.sup',
|
|
357
|
+
debug: true,
|
|
358
|
+
onWarning: (warning) => {
|
|
359
|
+
console.warn('[warning]', warning.code, warning.message, warning.details)
|
|
360
|
+
},
|
|
361
|
+
onError: (error) => {
|
|
362
|
+
if (error instanceof SubtitleDiagnosticError) {
|
|
363
|
+
console.error('[error]', error.code, error.message, error.details)
|
|
364
|
+
return
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
console.error(error)
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
console.log(renderer.getStats())
|
|
372
|
+
console.log(renderer.getCacheStats())
|
|
373
|
+
console.log(renderer.getLastRenderInfo())
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Structured diagnostic error codes currently include:
|
|
377
|
+
|
|
378
|
+
- `UNSUPPORTED_FORMAT`
|
|
379
|
+
- `BAD_IDX`
|
|
380
|
+
- `MISSING_PALETTE`
|
|
381
|
+
- `TRACK_NOT_FOUND`
|
|
382
|
+
- `MISSING_INPUT`
|
|
383
|
+
- `FETCH_FAILED`
|
|
384
|
+
- `INVALID_SUBTITLE_DATA`
|
|
385
|
+
- `WORKER_FALLBACK`
|
|
386
|
+
- `UNKNOWN`
|
|
387
|
+
|
|
388
|
+
Warnings use a smaller code set focused on non-fatal conditions such as malformed bitmap buffers, worker fallback, and missing PGS palettes during render.
|
|
389
|
+
|
|
233
390
|
## MKS security and corruption checks
|
|
234
391
|
|
|
235
392
|
The `.mks` path validates Matroska structure before handing payloads to the VobSub decoder. Embedded subtitle blocks are size-checked, compressed blocks use bounded zlib inflation, and extracted SPU packets are rejected if their declared payload lengths or control offsets are inconsistent. Malformed or oversized `.mks` payloads fail fast instead of being partially decoded.
|
|
@@ -260,6 +417,7 @@ const renderer = new PgsRenderer({
|
|
|
260
417
|
case 'loading':
|
|
261
418
|
case 'loaded':
|
|
262
419
|
case 'error':
|
|
420
|
+
case 'warning':
|
|
263
421
|
case 'renderer-change':
|
|
264
422
|
case 'worker-state':
|
|
265
423
|
case 'cache-change':
|
|
@@ -328,7 +486,8 @@ Emitted events:
|
|
|
328
486
|
| --- | --- |
|
|
329
487
|
| `loading` | subtitle format |
|
|
330
488
|
| `loaded` | subtitle format and parser metadata |
|
|
331
|
-
| `error` | subtitle format and `
|
|
489
|
+
| `error` | subtitle format and `SubtitleDiagnosticErrorLike` |
|
|
490
|
+
| `warning` | `SubtitleDiagnosticWarning` |
|
|
332
491
|
| `renderer-change` | active backend: `webgpu`, `webgl2`, or `canvas2d` |
|
|
333
492
|
| `worker-state` | whether worker mode is enabled, ready, fallback status, and the active session ID |
|
|
334
493
|
| `cache-change` | cached frame count, pending renders, and configured cache limit |
|
|
@@ -356,6 +515,8 @@ const stats = renderer.getStats()
|
|
|
356
515
|
- `totalEntries`
|
|
357
516
|
- `currentIndex`
|
|
358
517
|
|
|
518
|
+
`getCacheStats()` adds worker/session state for the current renderer cache, while `getLastRenderInfo()` exposes the most recent render outcome with a status of `rendered`, `cleared`, `pending`, `empty`, or `failed`.
|
|
519
|
+
|
|
359
520
|
## Low-level APIs
|
|
360
521
|
|
|
361
522
|
### PGS parser
|
|
@@ -368,7 +529,9 @@ parser.load(new Uint8Array(arrayBuffer))
|
|
|
368
529
|
|
|
369
530
|
const timestamps = parser.getTimestamps()
|
|
370
531
|
const frame = parser.renderAtIndex(0)
|
|
532
|
+
const rendered = parser.renderFrameDataAtTimestamp(120.5)
|
|
371
533
|
const metadata = parser.getMetadata()
|
|
534
|
+
const lastIssue = parser.getLastRenderIssue()
|
|
372
535
|
```
|
|
373
536
|
|
|
374
537
|
### VobSub parser
|
|
@@ -381,7 +544,9 @@ parser.loadFromData(idxContent, new Uint8Array(subArrayBuffer))
|
|
|
381
544
|
parser.setDebandEnabled(true)
|
|
382
545
|
|
|
383
546
|
const frame = parser.renderAtTimestamp(120.5)
|
|
547
|
+
const rendered = parser.renderFrameDataAtIndex(0, { crop: 'screen' })
|
|
384
548
|
const cue = parser.getCueMetadata(0)
|
|
549
|
+
const lastIssue = parser.getLastRenderIssue()
|
|
385
550
|
```
|
|
386
551
|
|
|
387
552
|
### Unified parser
|
|
@@ -391,7 +556,10 @@ import { UnifiedSubtitleParser, detectSubtitleFormat } from 'libbitsub'
|
|
|
391
556
|
|
|
392
557
|
const format = detectSubtitleFormat({ data: subtitleBytes, fileName: 'track.sup' })
|
|
393
558
|
|
|
394
|
-
const parser = new UnifiedSubtitleParser(
|
|
559
|
+
const parser = new UnifiedSubtitleParser({
|
|
560
|
+
debug: true,
|
|
561
|
+
onWarning: (warning) => console.warn(warning.code, warning.message)
|
|
562
|
+
})
|
|
395
563
|
parser.loadAuto({ data: subtitleBytes, fileName: 'track.sup' })
|
|
396
564
|
```
|
|
397
565
|
|
|
@@ -404,19 +572,20 @@ libbitsub prefers:
|
|
|
404
572
|
3. Canvas2D
|
|
405
573
|
|
|
406
574
|
```ts
|
|
407
|
-
import {
|
|
575
|
+
import { isWebGPUSupported } from 'libbitsub'
|
|
408
576
|
|
|
409
577
|
console.log({
|
|
410
|
-
webgpu: isWebGPUSupported()
|
|
411
|
-
webgl2: isWebGL2Supported()
|
|
578
|
+
webgpu: isWebGPUSupported()
|
|
412
579
|
})
|
|
413
580
|
```
|
|
414
581
|
|
|
582
|
+
WebGL2 and Canvas2D fallback remain automatic. Use `onWebGPUFallback`, `onWebGL2Fallback`, `onEvent`, or `onWarning` if you need to observe backend changes.
|
|
583
|
+
|
|
415
584
|
## Notes
|
|
416
585
|
|
|
417
586
|
- Worker mode is shared, but subtitle parser state is isolated per renderer session.
|
|
418
587
|
- Multiple subtitle renderers can coexist without reusing the same parser instance.
|
|
419
|
-
- If worker startup fails, the high-level API falls back to main-thread parsing.
|
|
588
|
+
- If worker startup fails, the high-level API falls back to main-thread parsing and emits a `WORKER_FALLBACK` warning/event when diagnostics are being observed.
|
|
420
589
|
- The library only handles bitmap subtitle formats. It does not parse text subtitle formats such as SRT or ASS.
|
|
421
590
|
|
|
422
591
|
## API Reference
|
|
@@ -428,6 +597,13 @@ console.log({
|
|
|
428
597
|
- `isWebGPUSupported(): boolean` checks WebGPU support.
|
|
429
598
|
- `detectSubtitleFormat(source: AutoSubtitleSource): 'pgs' | 'vobsub' | null` detects the bitmap subtitle format from file hints or binary data.
|
|
430
599
|
- `createAutoSubtitleRenderer(options: AutoVideoSubtitleOptions): PgsRenderer | VobSubRenderer` creates a high-level renderer after format detection.
|
|
600
|
+
- `openSubtitles(source, options?): Promise<OpenedSubtitles>` initializes WASM, auto-detects the low-level format, and returns a normalized parser handle.
|
|
601
|
+
- `renderFrameData(frame, options?): SubtitleRenderedFrameData | null` composes a `SubtitleData` frame into exportable pixels.
|
|
602
|
+
- `toCanvas(frame, target?, options?): HTMLCanvasElement | OffscreenCanvas` draws a rendered frame to a new or existing canvas/context.
|
|
603
|
+
- `toImageBitmap(frame, options?): Promise<ImageBitmap>` creates an `ImageBitmap` from a subtitle frame export.
|
|
604
|
+
- `toBlob(frame, type?, quality?, options?): Promise<Blob>` encodes a subtitle frame export, defaulting to PNG.
|
|
605
|
+
- `SubtitleDiagnosticError` is the structured error class libbitsub uses for coded diagnostics.
|
|
606
|
+
- `createSubtitleDiagnosticError(...)` and `normalizeSubtitleError(...)` are exported for integrations that want to preserve libbitsub-style error codes.
|
|
431
607
|
- Legacy aliases remain exported: `PGSRenderer`, `VobsubRenderer`, `UnifiedSubtitleRenderer`.
|
|
432
608
|
|
|
433
609
|
### High-level renderers
|
|
@@ -439,6 +615,8 @@ console.log({
|
|
|
439
615
|
- `setDisplaySettings(settings: Partial<SubtitleDisplaySettings>): void` updates layout settings.
|
|
440
616
|
- `resetDisplaySettings(): void` resets layout settings to defaults.
|
|
441
617
|
- `getStats(): SubtitleRendererStats` returns render statistics.
|
|
618
|
+
- `getCacheStats(): SubtitleCacheStats` returns cache occupancy, worker readiness, and session ID details.
|
|
619
|
+
- `getLastRenderInfo(): SubtitleLastRenderInfo | null` returns the last render attempt recorded in debug mode.
|
|
442
620
|
- `getMetadata(): SubtitleParserMetadata | null` returns track-level metadata.
|
|
443
621
|
- `getCurrentCueMetadata(): SubtitleCueMetadata | null` returns the currently displayed cue metadata.
|
|
444
622
|
- `getCueMetadata(index: number): SubtitleCueMetadata | null` returns metadata for a specific cue.
|
|
@@ -553,7 +731,8 @@ interface SubtitleDisplaySettings {
|
|
|
553
731
|
type SubtitleRendererEvent =
|
|
554
732
|
| { type: 'loading'; format: SubtitleFormatName }
|
|
555
733
|
| { type: 'loaded'; format: SubtitleFormatName; metadata: SubtitleParserMetadata }
|
|
556
|
-
| { type: 'error'; format: SubtitleFormatName; error:
|
|
734
|
+
| { type: 'error'; format: SubtitleFormatName; error: SubtitleDiagnosticErrorLike }
|
|
735
|
+
| { type: 'warning'; warning: SubtitleDiagnosticWarning }
|
|
557
736
|
| { type: 'renderer-change'; renderer: 'webgpu' | 'webgl2' | 'canvas2d' }
|
|
558
737
|
| { type: 'worker-state'; enabled: boolean; ready: boolean; sessionId: string | null; fallback?: boolean }
|
|
559
738
|
| { type: 'cache-change'; cachedFrames: number; pendingRenders: number; cacheLimit: number }
|
|
@@ -578,6 +757,11 @@ Both shapes expose:
|
|
|
578
757
|
- `totalEntries`
|
|
579
758
|
- `currentIndex`
|
|
580
759
|
|
|
760
|
+
Related diagnostics shapes:
|
|
761
|
+
|
|
762
|
+
- `SubtitleCacheStats` from `getCacheStats()`.
|
|
763
|
+
- `SubtitleLastRenderInfo` from `getLastRenderInfo()` when `debug` is enabled.
|
|
764
|
+
|
|
581
765
|
#### `SubtitleParserMetadata`
|
|
582
766
|
|
|
583
767
|
```ts
|