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
8 changed files with 89 additions and 2 deletions
+33 -1
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);