Skip to content
Type

HlsOutputFormatOptions

HLS-specific output options.

ts
type HlsOutputFormatOptions = {
	segmentFormat: OutputFormat | OutputFormat[];
	targetDuration?: number;
	singleFilePerPlaylist?: boolean;
	live?: boolean;
	maxLiveSegmentCount?: number;
	getPlaylistPath?: (info: HlsOutputPlaylistInfo) => MaybePromise<FilePath>;
	getSegmentPath?: (info: HlsOutputSegmentInfo) => MaybePromise<FilePath>;
	getInitPath?: (info: HlsOutputPlaylistInfo) => MaybePromise<FilePath>;
	onMaster?: (content: string) => unknown;
	onPlaylist?: (content: string, info: HlsOutputPlaylistInfo) => unknown;
	onSegment?: (target: Target, info: HlsOutputSegmentInfo) => unknown;
	onInit?: (target: Target, info: HlsOutputPlaylistInfo) => unknown;
	onSegmentPopped?: (path: string, info: HlsOutputSegmentInfo) => unknown;
};

See OutputFormat, HlsOutputPlaylistInfo, MaybePromise, FilePath, HlsOutputSegmentInfo, and Target.

Used by

Properties

segmentFormat

ts
segmentFormat: OutputFormat | OutputFormat[];

Specifies the file format of each media segment. Not all formats are supported by all players; prefer sticking to the most commonly used ones: MpegTsOutputFormat, CmafOutputFormat, AdtsOutputFormat, and Mp3OutputFormat.

When an array of formats is specified, for each playlist, the first format that can contain all of the playlist's tracks is chosen. This allows you to, for example, package audio into .aac files and video into .ts files.

See OutputFormat.

targetDuration

ts
targetDuration?: number;

Specifies the target (max) duration in seconds for each media segment, defaulting to 2 seconds.

Mediabunny will try not to emit media segments longer than the target duration, but it is forced to if key frames are provided with a longer period than the target duration. Therefore, make sure to encode a key frame at least every targetDuration seconds to guarantee segment length, controllable via VideoEncodingConfig.keyFrameInterval.

singleFilePerPlaylist

ts
singleFilePerPlaylist?: boolean;

Whether to bundle all media segments for a playlist into a single file. Individual segments are then extracted via range requests.

live

ts
live?: boolean;

If true, the muxer will be in "live mode", continuously emitting updated playlists as new segments are created. The master playlist will be emitted as soon as all playlists have been emitted at least once, and will continue to be emitted each time a segment is finalized to further refine the accuracy of the BANDWIDTH attribute.

When false (the default), all playlists will only be emitted once, upon output finalization.

maxLiveSegmentCount

ts
maxLiveSegmentCount?: number;

When in live mode, this controls the maximum number of segments contained in each playlist. Defaults to Infinity, meaning playlists continually grow in size.

getPlaylistPath

ts
getPlaylistPath?: ((info: HlsOutputPlaylistInfo) => MaybePromise<string>);

Returns the file path for a given media playlist. If the returned path is relative, it is relative to the root path.

Defaults to 'playlist-{n}.m3u8', where n is the 1-based index of the media playlist in the master playlist.

See HlsOutputPlaylistInfo and MaybePromise.

getSegmentPath

ts
getSegmentPath?: ((info: HlsOutputSegmentInfo) => MaybePromise<string>);

Returns the file path for a given media segment. If the returned path is relative, it is relative to the path of the containing playlist.

Defaults to 'segment-{n}-{k}{ext}', where n is the 1-based index of the containing media playlist in the master playlist, k is the 1-based index of the segment in its playlist, and ext is the file extension of the segment format (including the leading dot).

If singleFilePerPlaylist is true, it defaults to 'segments-{n}{ext}' instead.

See HlsOutputSegmentInfo and MaybePromise.

getInitPath

ts
getInitPath?: ((info: HlsOutputPlaylistInfo) => MaybePromise<string>);

Returns the file path for a given media init segment. If the returned path is relative, it is relative to the path of the containing playlist.

Only necessary for segment formats that require an init file, such as CmafOutputFormat.

Defaults to 'init-{n}{ext}', where n is the 1-based index of the containing media playlist in the master playlist and ext is the file extension of the segment format (including the leading dot).

See HlsOutputPlaylistInfo and MaybePromise.

Events

onMaster

ts
onMaster?: ((content: string) => unknown);

Called whenever the master playlist is written.

onPlaylist

ts
onPlaylist?: ((content: string, info: HlsOutputPlaylistInfo) => unknown);

Called whenever a media playlist is written.

See HlsOutputPlaylistInfo.

onSegment

ts
onSegment?: ((target: Target, info: HlsOutputSegmentInfo) => unknown);

Called whenever a media segment has been fully written. In single-file mode, this function will only be called once when the playlist is finalized.

See Target and HlsOutputSegmentInfo.

onInit

ts
onInit?: ((target: Target, info: HlsOutputPlaylistInfo) => unknown);

Called when a media playlist is initialized, before any segments have been written. In single-file mode, this function is never called.

See Target and HlsOutputPlaylistInfo.

onSegmentPopped

ts
onSegmentPopped?: ((path: string, info: HlsOutputSegmentInfo) => unknown);

Called when a media segment is removed from the start of a media playlist due to maxLiveSegmentCount. Will not be called when singleFilePerPlaylist is true.

See HlsOutputSegmentInfo.

Released under the Mozilla Public License 2.0.