@banou/media-player 0.10.38 → 0.10.39
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 +15 -18
- package/dist/engine/index.js +1 -1
- package/dist/engine/playback.d.ts +5 -1
- package/dist/engine/subtitles.d.ts +13 -3
- package/dist/{engine-eF2uRLyY.js → engine-DFqSQyNb.js} +212 -212
- package/dist/index.js +244 -240
- package/dist/react/video-player.d.ts +6 -2
- package/package.json +2 -2
- package/src/lib/engine/playback.ts +9 -2
- package/src/lib/engine/subtitles.ts +33 -18
- package/src/lib/react/hooks/use-playback.ts +7 -4
- package/src/lib/react/video-player.tsx +6 -2
|
@@ -167,11 +167,15 @@ export type MediaPlayerLocalOptions = CommonOptions & MediaPlayerSource & {
|
|
|
167
167
|
jassubWorkerUrl: string;
|
|
168
168
|
/** jassub's SIMD build, `jassub-worker-modern.wasm`. */
|
|
169
169
|
jassubWasmUrl: string;
|
|
170
|
+
/** `jassub-worker-modern.js`, the script that runs `jassubWasmUrl`, from the same jassub version. */
|
|
171
|
+
jassubWasmWorkerUrl: string;
|
|
170
172
|
/**
|
|
171
|
-
* jassub's non-SIMD build, `jassub-worker.wasm`, for
|
|
172
|
-
*
|
|
173
|
+
* jassub's non-SIMD build, `jassub-worker.wasm`, for browsers without relaxed SIMD and for devices
|
|
174
|
+
* reporting 2 GB of memory or less.
|
|
173
175
|
*/
|
|
174
176
|
jassubLegacyWasmUrl?: string;
|
|
177
|
+
/** `jassub-worker.js`, the script that runs `jassubLegacyWasmUrl`. Pass both or neither. */
|
|
178
|
+
jassubLegacyWasmWorkerUrl?: string;
|
|
175
179
|
/** Fallback face for `liberation sans`, used when a subtitle track names a font the file does not carry. */
|
|
176
180
|
defaultFontUrl?: string;
|
|
177
181
|
/** `@banou/media-player/noto-sans-jp.otf`, the face for CJK text, fetched once the selected track shows some. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banou/media-player",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.39",
|
|
4
4
|
"description": "A video player for containers and codecs the browser cannot play natively, remuxed on the fly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@videojs/core": "10.0.0-beta.26",
|
|
54
54
|
"@videojs/react": "10.0.0-beta.26",
|
|
55
55
|
"ass-compiler": "^0.1.16",
|
|
56
|
-
"jassub": "^2.5.
|
|
56
|
+
"jassub": "^2.5.37",
|
|
57
57
|
"libav-wasm": "^0.8.14",
|
|
58
58
|
"lucide-react": "^0.536.0",
|
|
59
59
|
"osra": "^0.6.12",
|
|
@@ -53,8 +53,12 @@ export type PlaybackOptions = {
|
|
|
53
53
|
libavWorkerUrl: string
|
|
54
54
|
jassubWorkerUrl: string
|
|
55
55
|
jassubWasmUrl: string
|
|
56
|
-
/** jassub
|
|
56
|
+
/** `jassub/dist/wasm/jassub-worker-modern.js`, the script that runs `jassubWasmUrl` */
|
|
57
|
+
jassubWasmWorkerUrl: string
|
|
58
|
+
/** jassub's non-SIMD build, for browsers without relaxed SIMD and devices with 2 GB of memory or less */
|
|
57
59
|
jassubLegacyWasmUrl?: string
|
|
60
|
+
/** `jassub/dist/wasm/jassub-worker.js`, the script that runs `jassubLegacyWasmUrl` */
|
|
61
|
+
jassubLegacyWasmWorkerUrl?: string
|
|
58
62
|
defaultFontUrl?: string
|
|
59
63
|
cjkFontUrl?: string
|
|
60
64
|
bufferSize?: number
|
|
@@ -165,7 +169,8 @@ export const terminateRemuxer = (remuxer: { worker: Worker, destroy: () => Promi
|
|
|
165
169
|
export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackController> => {
|
|
166
170
|
const {
|
|
167
171
|
videoElement, subtitleContainer, read, length, publicPath, libavWorkerUrl,
|
|
168
|
-
jassubWorkerUrl, jassubWasmUrl,
|
|
172
|
+
jassubWorkerUrl, jassubWasmUrl, jassubWasmWorkerUrl, jassubLegacyWasmUrl, jassubLegacyWasmWorkerUrl,
|
|
173
|
+
defaultFontUrl, cjkFontUrl, bufferSize = DEFAULT_BUFFER_SIZE,
|
|
169
174
|
audioStreamIndex, chooseAudioStream, onReady, onError, onRecovered, onSeek, onSubtitleStreams,
|
|
170
175
|
onAudioStreams, onOutput,
|
|
171
176
|
} = options
|
|
@@ -212,7 +217,9 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
212
217
|
container: subtitleContainer,
|
|
213
218
|
workerUrl: jassubWorkerUrl,
|
|
214
219
|
wasmUrl: jassubWasmUrl,
|
|
220
|
+
wasmWorkerUrl: jassubWasmWorkerUrl,
|
|
215
221
|
legacyWasmUrl: jassubLegacyWasmUrl,
|
|
222
|
+
legacyWasmWorkerUrl: jassubLegacyWasmWorkerUrl,
|
|
216
223
|
defaultFontUrl,
|
|
217
224
|
cjkFontUrl,
|
|
218
225
|
onStreams: onSubtitleStreams,
|
|
@@ -6,7 +6,7 @@ import { parse } from 'ass-compiler'
|
|
|
6
6
|
|
|
7
7
|
export type SubtitleStream = { streamIndex: number, title: string, language: string }
|
|
8
8
|
|
|
9
|
-
/** -1 turns subtitles off. It
|
|
9
|
+
/** -1 turns subtitles off. It empties the track and matches no header, so nothing is set. */
|
|
10
10
|
export const SUBTITLES_OFF = -1
|
|
11
11
|
|
|
12
12
|
type SubtitleHeaderPart = { type: 'header', streamIndex: number, content: string, eventsContent: string, styles: Map<string, number> }
|
|
@@ -27,16 +27,26 @@ export type SubtitleRendererOptions = {
|
|
|
27
27
|
*/
|
|
28
28
|
container: HTMLElement
|
|
29
29
|
workerUrl: string
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The SIMD build, `jassub-worker-modern.wasm`. Used wherever relaxed SIMD is available and the device
|
|
32
|
+
* reports more than 2 GB of memory.
|
|
33
|
+
*/
|
|
31
34
|
wasmUrl: string
|
|
32
35
|
/**
|
|
33
|
-
* The
|
|
36
|
+
* The script that runs `wasmUrl`, `jassub-worker-modern.js` from the same jassub version, since each wasm
|
|
37
|
+
* build has its own. The worker imports it and starts its threads from it, so it is a same-origin url.
|
|
38
|
+
*/
|
|
39
|
+
wasmWorkerUrl: string
|
|
40
|
+
/**
|
|
41
|
+
* The non-SIMD build, `jassub-worker.wasm`, for anything without relaxed SIMD or with 2 GB of memory or less.
|
|
34
42
|
*
|
|
35
43
|
* Optional in practice as well as in the type, unlike under jassub 1: v2 defaults both wasm urls to
|
|
36
44
|
* its own files resolved against `import.meta.url`, so leaving this unset degrades to whatever the
|
|
37
45
|
* bundler emitted rather than failing outright.
|
|
38
46
|
*/
|
|
39
47
|
legacyWasmUrl?: string
|
|
48
|
+
/** The script that runs `legacyWasmUrl`, `jassub-worker.js`. Pass both or neither. */
|
|
49
|
+
legacyWasmWorkerUrl?: string
|
|
40
50
|
/**
|
|
41
51
|
* Fallback face for `liberation sans`. Without it jassub falls back to whatever the wasm build embeds.
|
|
42
52
|
*
|
|
@@ -169,7 +179,9 @@ export type SubtitleRenderer = ReturnType<typeof createSubtitleRenderer>
|
|
|
169
179
|
export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
170
180
|
const { video, container, workerUrl } = options
|
|
171
181
|
const wasmUrl = workerFetched(options.wasmUrl)!
|
|
182
|
+
const wasmWorkerUrl = workerFetched(options.wasmWorkerUrl)!
|
|
172
183
|
const legacyWasmUrl = workerFetched(options.legacyWasmUrl)
|
|
184
|
+
const legacyWasmWorkerUrl = workerFetched(options.legacyWasmWorkerUrl)
|
|
173
185
|
const defaultFontUrl = workerFetched(options.defaultFontUrl)
|
|
174
186
|
const cjkFontUrl = workerFetched(options.cjkFontUrl)
|
|
175
187
|
let cjkFontRequested = false
|
|
@@ -195,6 +207,8 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
195
207
|
const rendererFailed = (error: unknown) => {
|
|
196
208
|
console.warn('the subtitle renderer failed; the file plays without subtitles', error)
|
|
197
209
|
}
|
|
210
|
+
// a renderer that never started is reported once, by `bootJassub`, not again by everything that waited on it
|
|
211
|
+
const startFailed = () => undefined
|
|
198
212
|
|
|
199
213
|
/**
|
|
200
214
|
* Run something against the worker, once there is a worker to run it against.
|
|
@@ -218,7 +232,7 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
218
232
|
const instance = jassub
|
|
219
233
|
if (!instance) return
|
|
220
234
|
void instance.ready
|
|
221
|
-
.then(() => (jassub === instance ? run(instance.renderer) : undefined))
|
|
235
|
+
.then(() => (jassub === instance ? run(instance.renderer) : undefined), startFailed)
|
|
222
236
|
.catch(rendererFailed)
|
|
223
237
|
}
|
|
224
238
|
|
|
@@ -257,9 +271,11 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
257
271
|
expectedDisplayTime: performance.now(),
|
|
258
272
|
width: video.videoWidth,
|
|
259
273
|
height: video.videoHeight,
|
|
260
|
-
|
|
274
|
+
// Never exactly 0: from 2.5.30 jassub redraws for a colour space it learns late only `if (this._lastDrawTime)`,
|
|
275
|
+
// so a picture paused at the start kept its unconverted colours. libass rounds to the millisecond.
|
|
276
|
+
mediaTime: video.currentTime || Number.MIN_VALUE,
|
|
261
277
|
}, true)
|
|
262
|
-
})
|
|
278
|
+
}, startFailed)
|
|
263
279
|
.catch(rendererFailed)
|
|
264
280
|
})
|
|
265
281
|
}
|
|
@@ -277,8 +293,8 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
277
293
|
* `subtitle-paused-repaint.browser.test.tsx`'s turn-off case four runs out of four, while adding
|
|
278
294
|
* back EITHER of the other two passes. Neither of those events fires in that test, so what the
|
|
279
295
|
* extra listener buys is timing rather than a trigger, and the honest conclusion is that the clear
|
|
280
|
-
*
|
|
281
|
-
* case several times.
|
|
296
|
+
* when subtitles are turned off is more delicate than it looks. Do not shorten this list without
|
|
297
|
+
* running that case several times.
|
|
282
298
|
*/
|
|
283
299
|
const REPAINT_ON = ['loadedmetadata', 'seeked', 'pause'] as const
|
|
284
300
|
const onRepaintEvent = () => repaint()
|
|
@@ -288,12 +304,13 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
288
304
|
container.append(canvas)
|
|
289
305
|
try {
|
|
290
306
|
jassub = new JASSUB({
|
|
291
|
-
video,
|
|
292
307
|
canvas,
|
|
293
308
|
subContent: header.content,
|
|
294
309
|
workerUrl,
|
|
295
310
|
modernWasmUrl: wasmUrl,
|
|
311
|
+
modernWasmWorkerUrl: wasmWorkerUrl,
|
|
296
312
|
...legacyWasmUrl ? { wasmUrl: legacyWasmUrl } : {},
|
|
313
|
+
...legacyWasmWorkerUrl ? { wasmWorkerUrl: legacyWasmWorkerUrl } : {},
|
|
297
314
|
fonts: attachments.map(([, data]) => data),
|
|
298
315
|
availableFonts: {
|
|
299
316
|
...Object.fromEntries(attachments),
|
|
@@ -309,9 +326,9 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
309
326
|
rendererFailed(error)
|
|
310
327
|
return
|
|
311
328
|
}
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
|
|
329
|
+
// Not handed to the constructor, which attaches it with a `setVideo` nothing catches: that rejects with `ready`, so a
|
|
330
|
+
// renderer that cannot start would leave an unhandled rejection in the host page.
|
|
331
|
+
void jassub.setVideo(video).catch(startFailed)
|
|
315
332
|
void jassub.ready.catch(rendererFailed)
|
|
316
333
|
for (const type of REPAINT_ON) video.addEventListener(type, onRepaintEvent)
|
|
317
334
|
/*
|
|
@@ -390,12 +407,10 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
390
407
|
const header = headers.get(next)
|
|
391
408
|
const events = [...dialogues.get(next)?.values() ?? []].map((part) => part.assEvent)
|
|
392
409
|
onRenderer((renderer) => {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
return Promise.all(calls)
|
|
410
|
+
// Off empties the track rather than freeing it. jassub redoes a draw asked for while one is in flight without
|
|
411
|
+
// its repaint flag, and from 2.5.30 an unforced draw of a freed track reports no change, so the line stayed up.
|
|
412
|
+
if (!header) return renderer.removeAllEvents()
|
|
413
|
+
return Promise.all([renderer.freeTrack(), renderer.setTrack(header.content), ...events.map((event) => renderer.createEvent(event))])
|
|
399
414
|
})
|
|
400
415
|
loadCjkFontFor(events)
|
|
401
416
|
// outside the callback so that turning subtitles OFF while paused clears the picture too
|
|
@@ -79,11 +79,11 @@ export const usePlayback = (
|
|
|
79
79
|
onOutput?: (output: PlaybackOutput) => void,
|
|
80
80
|
) => {
|
|
81
81
|
const player = usePlayer()
|
|
82
|
-
// The
|
|
82
|
+
// The five asset urls are required on the local arm, so a default only ever applies when options is
|
|
83
83
|
// null, and the effect below returns before touching them in that case.
|
|
84
84
|
const {
|
|
85
|
-
read, size, publicPath = '', libavWorkerUrl = '', jassubWorkerUrl = '', jassubWasmUrl = '',
|
|
86
|
-
jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize, autoplay = false, chapters,
|
|
85
|
+
read, size, publicPath = '', libavWorkerUrl = '', jassubWorkerUrl = '', jassubWasmUrl = '', jassubWasmWorkerUrl = '',
|
|
86
|
+
jassubLegacyWasmUrl, jassubLegacyWasmWorkerUrl, defaultFontUrl, cjkFontUrl, bufferSize, autoplay = false, chapters,
|
|
87
87
|
seekPrepareBudgetMs = SEEK_PREPARE_BUDGET_MS,
|
|
88
88
|
} = options ?? ({} as Partial<MediaPlayerLocalOptions>)
|
|
89
89
|
|
|
@@ -378,7 +378,9 @@ export const usePlayback = (
|
|
|
378
378
|
libavWorkerUrl,
|
|
379
379
|
jassubWorkerUrl,
|
|
380
380
|
jassubWasmUrl,
|
|
381
|
+
jassubWasmWorkerUrl,
|
|
381
382
|
jassubLegacyWasmUrl,
|
|
383
|
+
jassubLegacyWasmWorkerUrl,
|
|
382
384
|
defaultFontUrl,
|
|
383
385
|
cjkFontUrl,
|
|
384
386
|
bufferSize,
|
|
@@ -447,6 +449,7 @@ export const usePlayback = (
|
|
|
447
449
|
// times a second, and the restart loop reads as "Loading metadata" forever at a flat 0 B/s.
|
|
448
450
|
}, [
|
|
449
451
|
player, playingAudio, video, subtitles, size, publicPath, libavWorkerUrl, jassubWorkerUrl, jassubWasmUrl,
|
|
450
|
-
jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize,
|
|
452
|
+
jassubWasmWorkerUrl, jassubLegacyWasmUrl, jassubLegacyWasmWorkerUrl, defaultFontUrl, cjkFontUrl, bufferSize,
|
|
453
|
+
audioStreamIndex, autoplay, restartToken,
|
|
451
454
|
])
|
|
452
455
|
}
|
|
@@ -193,11 +193,15 @@ export type MediaPlayerLocalOptions =
|
|
|
193
193
|
jassubWorkerUrl: string
|
|
194
194
|
/** jassub's SIMD build, `jassub-worker-modern.wasm`. */
|
|
195
195
|
jassubWasmUrl: string
|
|
196
|
+
/** `jassub-worker-modern.js`, the script that runs `jassubWasmUrl`, from the same jassub version. */
|
|
197
|
+
jassubWasmWorkerUrl: string
|
|
196
198
|
/**
|
|
197
|
-
* jassub's non-SIMD build, `jassub-worker.wasm`, for
|
|
198
|
-
*
|
|
199
|
+
* jassub's non-SIMD build, `jassub-worker.wasm`, for browsers without relaxed SIMD and for devices
|
|
200
|
+
* reporting 2 GB of memory or less.
|
|
199
201
|
*/
|
|
200
202
|
jassubLegacyWasmUrl?: string
|
|
203
|
+
/** `jassub-worker.js`, the script that runs `jassubLegacyWasmUrl`. Pass both or neither. */
|
|
204
|
+
jassubLegacyWasmWorkerUrl?: string
|
|
201
205
|
/** Fallback face for `liberation sans`, used when a subtitle track names a font the file does not carry. */
|
|
202
206
|
defaultFontUrl?: string
|
|
203
207
|
/** `@banou/media-player/noto-sans-jp.otf`, the face for CJK text, fetched once the selected track shows some. */
|