libpgs
Version:
Renderer for graphical subtitles (PGS) in the browser.
61 lines (60 loc) • 2.55 kB
TypeScript
import { DisplaySet } from "./pgs/displaySet";
import { BinaryReader } from "./utils/binaryReader";
import { SubtitleData } from "./subtitleData";
export interface PgsLoadOptions {
/**
* Async pgs streams can return partial updates. When invoked, the `displaySets` and `updateTimestamps` are updated
* to the last available subtitle. There is a minimum threshold of one-second to prevent to many updates.
*/
onProgress?: () => void;
}
/**
* The PGS subtitle data class. This can load and cache sup files from a buffer or url.
* It can also build image data for a given timestamp or timestamp index.
*/
export declare class Pgs {
/**
* The currently loaded display sets.
*/
displaySets: DisplaySet[];
/**
* The PGS timestamps when a display set with the same index is presented.
*/
updateTimestamps: number[];
/**
* Loads the subtitle file from the given url.
* @param url The url to the PGS file.
* @param options Optional loading options. Use `onProgress` as callback for partial update while loading.
*/
loadFromUrl(url: string, options?: PgsLoadOptions): Promise<void>;
/**
* Loads the subtitle file from the given buffer.
* @param buffer The PGS data.
* @param options Optional loading options. Use `onProgress` as callback for partial update while loading.
*/
loadFromBuffer(buffer: ArrayBuffer, options?: PgsLoadOptions): Promise<void>;
/**
* Loads the subtitle file from the given buffer.
* @param reader The PGS data reader.
* @param options Optional loading options. Use `onProgress` as callback for partial update while loading.
*/
loadFromReader(reader: BinaryReader, options?: PgsLoadOptions): Promise<void>;
private cachedSubtitleData?;
/**
* Pre-compiles and caches the subtitle data for the given index.
* This will speed up the next call to `buildSubtitleDataAtIndex` with the same index.
* @param index The index of the display set to cache.
*/
cacheSubtitleAtIndex(index: number): void;
/**
* Renders the subtitle at the given timestamp.
* @param time The timestamp in seconds.
*/
getSubtitleAtTimestamp(time: number): SubtitleData | undefined;
/**
* Pre-compiles the required subtitle data (windows and pixel data) for the frame at the given index.
* @param index The index of the display set to render.
*/
getSubtitleAtIndex(index: number): SubtitleData | undefined;
private getPixelDataFromComposition;
}