1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #5688 from Arcus92/native-pgs

Add support for native PGS subtitle rendering without transcoding
This commit is contained in:
Bill Thornton 2024-09-20 15:55:30 -04:00 committed by GitHub
commit 6d0f0e85a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 89 additions and 2 deletions

View file

@ -100,7 +100,7 @@ function enableNativeTrackSupport(mediaSource, track) {
if (track) {
const format = (track.Codec || '').toLowerCase();
if (format === 'ssa' || format === 'ass') {
if (format === 'ssa' || format === 'ass' || format === 'pgssub') {
return false;
}
}
@ -213,6 +213,10 @@ export class HtmlVideoPlayer {
* @type {any | null | undefined}
*/
#currentAssRenderer;
/**
* @type {any | null | undefined}
*/
#currentPgsRenderer;
/**
* @type {number | undefined}
*/
@ -590,6 +594,9 @@ export class HtmlVideoPlayer {
if (this.#currentAssRenderer) {
this.updateCurrentTrackOffset(offsetValue);
this.#currentAssRenderer.timeOffset = (this._currentPlayOptions.transcodingOffsetTicks || 0) / 10000000 + offsetValue;
} else if (this.#currentPgsRenderer) {
this.updateCurrentTrackOffset(offsetValue);
this.#currentPgsRenderer.timeOffset = (this._currentPlayOptions.transcodingOffsetTicks || 0) / 10000000 + offsetValue;
} else {
const trackElements = this.getTextTracks();
// if .vtt currently rendering
@ -1172,6 +1179,12 @@ export class HtmlVideoPlayer {
octopus.dispose();
}
this.#currentAssRenderer = null;
const pgsRenderer = this.#currentPgsRenderer;
if (pgsRenderer) {
pgsRenderer.dispose();
}
this.#currentPgsRenderer = null;
}
/**
@ -1316,6 +1329,21 @@ export class HtmlVideoPlayer {
});
}
/**
* @private
*/
renderPgs(videoElement, track, item) {
import('libpgs').then((libpgs) => {
const options = {
video: videoElement,
subUrl: getTextTrackUrl(track, item),
workerUrl: `${appRouter.baseUrl()}/libraries/libpgs.worker.js`,
timeOffset: (this._currentPlayOptions.transcodingOffsetTicks || 0) / 10000000
};
this.#currentPgsRenderer = new libpgs.PgsRenderer(options);
});
}
/**
* @private
*/
@ -1434,6 +1462,10 @@ export class HtmlVideoPlayer {
this.renderSsaAss(videoElement, track, item);
return;
}
if (format === 'pgssub') {
this.renderPgs(videoElement, track, item);
return;
}
if (this.requiresCustomSubtitlesElement()) {
this.renderSubtitlesWithCustomElement(videoElement, track, item, targetTextTrackIndex);