Refactor Target and Writer, add single-file HLS writing mode

This commit is contained in:
Vanilagy
2026-03-27 18:07:26 +01:00
parent b8044cfa07
commit e2e8aaab78
15 changed files with 819 additions and 540 deletions
+6 -2
View File
@@ -1102,6 +1102,7 @@ export type HlsOutputPlaylistInfo = {
export type HlsOutputSegmentInfo = {
n: number;
isSingleFile: boolean;
format: OutputFormat;
playlist: HlsOutputPlaylistInfo;
};
@@ -1109,11 +1110,13 @@ export type HlsOutputSegmentInfo = {
export type HlsOutputFormatOptions = {
segmentFormats: OutputFormat[];
targetDuration?: number;
singleFilePerPlaylist?: boolean;
getPlaylistPath?: (info: HlsOutputPlaylistInfo) => MaybePromise<string>;
getSegmentPath?: (info: HlsOutputSegmentInfo) => MaybePromise<string>;
onMaster?: (content: string) => unknown;
onPlaylist?: (content: string, info: HlsOutputPlaylistInfo) => unknown;
// Document how this is called for the single-file mode
onSegment?: (target: Target, info: HlsOutputSegmentInfo) => unknown;
};
@@ -1139,6 +1142,9 @@ export class HlsOutputFormat extends OutputFormat {
) {
throw new TypeError('options.targetDuration, when provided, must be a positive number.');
}
if (options.singleFilePerPlaylist !== undefined && typeof options.singleFilePerPlaylist !== 'boolean') {
throw new TypeError('options.singleFilePerPlaylist, when provided, must be a boolean.');
}
if (options.getPlaylistPath !== undefined && typeof options.getPlaylistPath !== 'function') {
throw new TypeError('options.getPlaylistPath, when provided, must be a function.');
}
@@ -1216,5 +1222,3 @@ export class HlsOutputFormat extends OutputFormat {
return ` Using different segment formats may grant support for this codec.`;
}
}
export const HLS_OUTPUT_FORMATS_DEFAULT = [new AdtsOutputFormat(), new MpegTsOutputFormat()];